   [Solved] Multiplied colors get invisible
  Hello,I'm using the following pixel shader source. I'm setting the FragColor to the result of a multiplication between the color of a "diffuse" texture by the color of a 1D light table texture (attempting toon-shading, that is).uniform sampler1D TextureUnit0; //1D Light-table.uniform sampler2D TextureUnit1; //Diffuse texture.varying vec3 vNormal;void main(){vec3 L = normalize(vec3(gl_LightSource[0].position));float intensity = clamp(dot(L,vNormal),0.0,1.0);vec4 value = texture1D(TextureUnit0, intensity);vec4 texel = texture2D(TextureUnit1, gl_TexCoord[0].st);gl_FragColor = value * texel;}  Here's the thing: the mesh becomes completely invisible.If I comment out the "texel" variable in the line "gl_FragColor = value * texel;", the mesh becomes visible but only showing the plain lighting by the 1D texture. If I comment out the "value" variable in this same line, the mesh becomes visible with only the diffuse texture. No issue there as well.The problem lies when I multiply them.I want the 1D texture to modulate the underlying diffuse texture(s). Can someone help me with this?[Edited by - Kryzon on May 5, 2010 4:04:51 PM]
  What's the alpha on both textures? If any of them has alpha = 0.0, the product will produce alpha = 0.0, and thus a completely transparent pixel. Check that :)   ;  Ok, checked. I've tested the code with two BMPs with the appropriate size (256² for the diffuse, and 64x1 for the 1D texture). Just to be sure I also tried hard coding the alphas: "texel.a = 1.0;" and "value.a = 1.0;".The problem persists.   ;  What happens if you set gl_FragColor.a = 1.0 as the last shader instruction?   ;  check the alpha values as all the post have suggested. I guarantee that its getting set to zero.  Even if the .rgb value was 0 you would see a black object. The fact that you are not seeing the object means the alpha is being set to 0.;  Here's the current Main I'm using, with the modifications as suggested:void main(){vec3 L = normalize(vec3(gl_LightSource[0].position));float intensity = clamp(dot(L,vNormal),0.0,1.0);vec4 value = texture1D(TextureUnit0, intensity);value.a = 1.0;vec4 texel = texture2D(TextureUnit1, gl_TexCoord[0].st);texel.a = 1.0;gl_FragColor = value * texel;gl_FragColor.a = 1.0;}Oh, the mesh appears if I set the FragColor to either "value*value" or "texel*texel" (it's not what I'm after, but shows that it is possible to multiply texel colors). The problem is precisely in multiplying "value*texel". As soon as I hit Compile, the mesh disappears completely. No errors reported at all.EDIT: I just tried "gl_FragColor = max(texel*value,vec4(1.0,1.0,1.0,1.0));" - still invisible, nothing appears. Makes me wonder if "texel*value" is an acceptable value.Any chance this is a bug with Shader Designer?   ;  "gl_FragColor = max(texel*value,vec4(1.0,1.0,1.0,1.0));"The pipeline does this step anyway... :-)OK;1) Have you tried basic opengl debugging stuff, like setting your clear colour to be bright purple, so you can see even dark objects? Does the object render in sight when the shader is disabled?2) Try setting the texel to something hardcoded; like solid blue say and see if that changes things.3) Try setting the intensity hardcoded to 1.0 and see what happens.;  Better post the entire CPU side code. You might be setting some state that produces that.   ;  I'm not using OpenGL code, I'm coding and previewing the shader with Shader Designer.I just noticed now, blending was disabled from the start so it definitely can't be any blend related issues.Also noted, if I set the FragColor to any operation between the two lookups, the object becomes invisible: "texel+value", "texel-value", "texel/value" (and the same for "value+texel", etc.).Whenever I hardcode the color value, it works. The mesh only gets invisible if the output color comes from some operation between both lookups. Not only that, but it disregards anything that I might hardcode in the output as well:gl_FragColor = texel + value + vec4(1.0,1.0,1.0,1.0);The above still makes it invisible. If I comment either of the lookup variables, the mesh appears.   ;  I tried to compile your code in Rendermonkey. There were no error messages but the object was invisible. When I change your 1D texture to 2D texture, the object appears and the shader looks fine. I post here for clarity the slightly modified code that I've used.uniform vec3 lightDir;uniform sampler2D TextureUnit0;uniform sampler2D TextureUnit1;varying vec3 vNormal;void main(void){   vec3 L = normalize(lightDir);   float intensity = clamp(dot(L,vNormal),0.0,1.0);   vec4 value = texture2D(TextureUnit0, vec2(intensity,0.0));   vec4 texel = texture2D(TextureUnit1, gl_TexCoord[0].st);   gl_FragColor = value * texel;}It seems that Rendermonkey (or even my GPU) has problems in 1D texture support. It may be the same with your Shader Designer.Check your alpha blending mode and/or set your clear colour to be bright purple as Katie suggests.   