How to implement multi-pass texture in a single shader?
I would like build a scene which contains 2D texture and envirment-mapping texture IN GLSL. I have try to do like this:
Draw()
{
glUseProgram(shader);
glUniform1i(loc,"get2Dtexture",1);
glActiveTexture(GL_TEXUTRE0);
glBindTexture(2D);
//Draw Some Thing
glBindTexture(2D);
//Draw Some Thing too
glUniform1i(loc,"get2Dtexture",0);
glActiveTexture(GL_TEXTURE1);
glBindTexutre(3D);
//Draw A Sphere
}
In fragment shader
uniform sampler2D tex0;
uniform sampler3D tex1;
uniform int get2Dtexture;
main()
{
///
if (get2Dtexture == 1)
{
gl_FragColor = texture2D();
}
else
{
gl_FragColor = texture3D();
}
///
}
In glut console,it seems that during rendering every frame it will report "get2Dtexture invaild"....
Thanks. I just want to know how to implement multi-pass texture in a single shader,because i think switch between different shaders will cost much.
glUniform1i(loc,"get2Dtexture",0);
This shouldn't even compile. glUniform1i() takes two integers only, no string. You first need to use glGetUniformLocation() to get the "loc" parameter for a specific program.
Further, you need to obtain the textures uniform locations, too, and set those as glUniform1i() to the texture index (0, 1, ...) that you have the texture image in.
Honestly, I would not worry about the small cost of switching shaders just yet. I would worry about making a simple program that uses GLSL and actually works, first.
The other point, which is not clear from your post, is why you are trying to implement multipass instead of using the shader to perform your rendering operation in a single pass?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement