I have an image of concrete rocks of different shades of colors, and I'm applying this shader, but without referencing s_lightMap's uniform in my program:

        precision mediump float;                            
        varying vec2 v_texCoord;                            
        uniform sampler2D s_baseMap;                        
        uniform sampler2D s_lightMap;                       
        void main()                                         
          vec4 baseColor;                                   
          vec4 lightColor;                                  

          baseColor = texture2D( s_baseMap, v_texCoord );   
          lightColor = texture2D( s_lightMap, v_texCoord ); 
          gl_FragColor = baseColor * (lightColor + 0.25);   

it displays a picture with variable light color added to the final pixel color, but s_lightMap isn't even linked into the program, what is happening in this case, at first I thought it would just do the baseColor as the FragColor, but the addition of the 0.25 makes a non-negative result to (lightColor + 0.25). I'm confused, one minute I think lightColor would be set to a texture of 1's the next an array of 0's.

Or is it just random data? It doesn't appear at all random in the picture, it looks like it's obeying a rule of shading.

I'd like to mimic this effect in code that's not broken.

Here's the unshadded image:

Unrendered Image

Example "gimped" image of how it has variable shades (though this is an invert):

enter image description here

  • \$\begingroup\$ s_lightMap is not linked in shader = you are not assigning it a texture unit in the code? \$\endgroup\$
    – Cristina
    May 2, 2013 at 15:08
  • \$\begingroup\$ @Cristina correct, but why would it be doing anything at all, like adding what appears to be color in sharper shades? It's a snippet of code I hacked together, I liked the effect, but it's poor code, so I'd like to get the effect without poor code. \$\endgroup\$ May 2, 2013 at 19:52
  • \$\begingroup\$ If you are compiling under Win32 you can use gDebugger gremedy.com/download.php to see what exactly is the texture that is being redered at that time. Also there is vis.uni-stuttgart.de/glsldevil \$\endgroup\$
    – Cristina
    May 2, 2013 at 20:25

1 Answer 1


After close inspection I found that the line:

gl_FragColor = baseColor * ( lightColor + 0.25 );

is probably exactly equal to:

gl_FragColor = baseColor * ( baseColor + 0.25 );

when uniform sampler2D s_lightMap isn't being loaded into the program.

EDIT: This may or may not be because of the State Functionality of openGL es 2.0, but I wouldn't bet on using it.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .