Flow Control : Using Single Shader HELP

I just want to using single shader in my program.
I have 2 texture Units,one is for CubeMap,other is for 2D texture.

Now, In draw function,structure like this:

Draw something too

Draw something too…

In Fragment Shader,Just like this:

uniform samplerCube cubemap; //0
uniform sampler2D tex2d; //1

uniform bool NeedCubeMap;

varying float LightCoeff;
varying vec3 vUV3D;
varying vec2 vUV2D;

void main(void)

if( NeedCubeMap ){
	vec4 cubecolor = textureCube(cubemap,vUV3D);
	gl_FragColor = cubecolor*LightCoeff;
	vec4 tex2dcolor = texture2D(tex2d,vUV2D);
	gl_FragColor = tex2dcolor*LightCoeff;


but when the program is running,it’s black,nothing…I thinks maybe the frame buffer was not written,but when I cut off anything about the “NeedCubeMap”,it just good. Where is the wrong ? :confused: :confused: :confused:

Did use set the samplers to 0 and 1?
This needs to be in your code somewhere:

Yes,I had combine Sampler2D with Uniform tex2d1 and the same to Cubemap

Post some more code then.

Any compile or link errors of the shaders?
Any glGetError hit?
Is the shader program in use when you call glUniform? It has no program parameter, so it can only affect the currently bound program.
If you set the glClearColor to non-black, do see something rendered at all?
What’s your vertex shader?

Try this:

void main(void)
  vec4 color;
  if( NeedCubeMap ){
    color = textureCube(cubemap,vUV3D);
    color = texture2D(tex2d,vUV2D);
  gl_FragColor = color * vec4(LightCoeff);

:stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue:
I just find where I was wrong !

I am wrong to use Sampler3D instead of SamplerCube

and the same to function texture3D and textureCube

Now Everying is correct!

Thanks Everyone!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.