PDA

View Full Version : DIfferent Objects with different shaders in one scene



Dylan
09-04-2006, 01:24 PM
In my renderScene subroutine I call for a stream of particles drawn with a shader attached (for updating color and position of the particles). Now I just want to draw another object in the scene, i.e. a teapot, but this object get affected by the shader for the particles...is there a way to disable the shader when drawing the teapot, or to assign the particle shader only to the particles?

k_szczech
09-04-2006, 03:11 PM
glUseProgramObject(shaderHandle);
...draw particles...
glUseProgramObject(0);
...draw teapot...

Dylan
09-05-2006, 12:09 AM
Thanks it works!

Can you extend your awnser by telling me how I can use a secondary shader for the teapot?

and next, enabling and disabling the shaderprogram decreases the framerate to 50%, is there another option?

Komat
09-05-2006, 12:30 AM
Originally posted by Dylan:
Can you extend your awnser by telling me how I can use a secondary shader for the teapot?
glUseProgramObject(shaderHandle);
...draw particles...
glUseProgramObject(shaderHandle2);
...draw teapot...

k_szczech
09-05-2006, 12:42 AM
enabling and disabling the shaderprogram decreases the framerate to 50%, is there another option?
Switching shaders is always a bit slow. If you had 1000 FPS and now you have 500 FPS, then I think it's ok, but if you had 100 FPS and now you have 50 FPS, then you must be doing something wrong since you use only one shader and you enable/disable it only once per frame.
Note thet you do not need to call functions such as glUniformLocation every frame.

Jedimaster
09-07-2006, 03:28 AM
before all you must be sure that your shaders have been compiled correctly ready to use.

then in your draw function,

glUseProgram(handle1)
//draw something stuff

glUseProgram(handle2)
//draw something stuff

Or you write a super shader which include the multipass effect in it by using sm3