Jedimaster
07-02-2006, 10:30 PM
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:
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_CUBEMAP,cubetex);
glUniform1i(getUniLoc(ShaderProg,"NeedCubeMap"),1);
/*
Draw something too
*/
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,2dtex);
glUniform1i(getUniLoc(ShaderProg,"NeedCubeMap"),0);
/*
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;
}else{
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:
I have 2 texture Units,one is for CubeMap,other is for 2D texture.
Now, In draw function,structure like this:
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_CUBEMAP,cubetex);
glUniform1i(getUniLoc(ShaderProg,"NeedCubeMap"),1);
/*
Draw something too
*/
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,2dtex);
glUniform1i(getUniLoc(ShaderProg,"NeedCubeMap"),0);
/*
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;
}else{
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: