libgdx debugging shaders

I just stated working with shaders myself

I did a basic shader and then copied one from the internet to kinda play around with it and check it out.
But I just get nothing and I’m not sure how to debug shaders :smiley:

Vertex shader


void main()
{	
  gl_Position = ftransform();		
  gl_TexCoord[0] = gl_MultiTexCoord0;
}

Fragment shader

#version 120
uniform sampler2D u_texture; 

// Currently not used
uniform float time = 1.0; 

// Swirl effect parameters
uniform float radius = 80.0;
uniform float angle = 2.8;
uniform vec2 center = vec2(50.0, 50.0);

vec4 PostFX(sampler2D tex, vec2 uv, float time)
{
  vec2 texSize = vec2(512, 512);
  vec2 tc = uv * texSize;
  tc -= center;
  float dist = length(tc);
  if (dist < radius) 
  {
    float percent = (radius - dist) / radius;
    float theta = percent * percent * angle * 8.0;
    float s = sin(theta);
    float c = cos(theta);
    tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
  }
  tc += center;
  vec3 color = texture2D(tex, tc / texSize).rgb;
  return vec4(color, 1.0);
}

void main (void)
{
  vec2 uv = gl_TexCoord[0].st;
  gl_FragColor = PostFX(u_texture, uv, time);
}

its supposed to be like a swirl effect but I’m getting nothing.
It might also be that the vertex shader is wrong, since its very different from the default vertex shader

I think using glGetShaderInfoLog(int shader) after compiling a shader and glGetProgramInfoLog(int program) after linking and validating a shader program might help you find out if there is an issue with your shaders.

I don’t use libgdx, but taking a quick look at the api, I think these are what you need.

To use them you pass an int, of which you get when you use glCreateShader(int type) and glCreateProgram() respectively.

What you get from calling the log methods is a string, of which you can do what ever with.

I think…
As I said, I don’t use libgdx, but rather lwjgl, but it seems the main opengl methods are relatively all the same.

(Just in case, here’s a link to the api: http://libgdx.badlogicgames.com/nightlies/docs/api/)

well yeah there is ShaderProgram.getLog(), but its empty.
I am using ShaderProgram.pedantic = false; however for it to work at all, but they do that in the mattdesl tutorials too

I ended up with this:

#version 120

#ifdef GL_ES 
#define LOWP lowp 
precision mediump float; 
#else 
#define LOWP  
#endif 
varying LOWP vec4 v_color; 
varying vec2 v_texCoords; 

uniform sampler2D u_texture; //image
uniform float amount; //amount of twirl

void main()
{
   vec2 uv = v_texCoords-0.5;
   float angle = atan(uv.y,uv.x);
   float radius = length(uv);
   angle+= radius*amount;
   vec2 shifted = radius*vec2(cos(angle), sin(angle));
   gl_FragColor = v_color * texture2D(u_texture, (shifted+0.5));
}

and it works like you would expect:

However. I have a tile map, and if you want this effect on the whole screen, like this:

you would either need a vertex shader rather than a fragment shader, OR somehow apply it to the whole screen.
But I’m not sure if you can specify in libgdx to render to texture, apply the effect and then render that texture to screen. Internally of course that happens because of double buffering…

gonna try out using a fbo