Search code examples
javaglsllibgdx

GLSL - setting uniform issue


I went into a little problem here, My render loop doesn't render my world because of GLSL issues.

The program updates the uniform in the render loop :

map[mapPos].light = Lighting.checkSunLight(mapPosY, mapPosX, this); // It works good.. returns float
Shaders.blockS.begin();
Shaders.blockS.setUniformf("lightBlock", map[mapPos].light); // Problem is here!!!
Shaders.blockS.end();
batch.draw(map[mapPos].getBlockTexture(), (mapPosX * Block.WIDTH), (mapPosY * Block.HEIGHT),     Block.WIDTH, Block.HEIGHT); // Doesn't draw the block.

Just if you curious about the fragment shader -

varying vec4 vColor;
varying vec2 vTexCoord;

uniform vec2 screenSize;

uniform sampler2D u_texture;
uniform vec4 gameTime;
uniform float lightBlock;

const float RADIUS = 0.75;

const float SOFTNESS = 0.6;

void main() {

    vec4 texColor = texture2D(u_texture, vTexCoord);

    vec4 timedColor = (vColor + gameTime);

    vec2 position = (gl_FragCoord.xy / screenSize.xy) - vec2(0.5);
    float len = length(position);

    float vignette = smoothstep(RADIUS, RADIUS-SOFTNESS, len);

    texColor.rgb = mix(texColor.rgb, texColor.rgb * vignette, 0.5);

    gl_FragColor = vec4(texColor.rgb * timedColor.rgb * lightBlock, texColor.a);
}

Pedantic is

ShaderProgram.pedantic= false;

Solution

  • I've fixed it, I just moved the .end() function of the shader program to the last line.