Jump to content
  • Advertisement
Sign in to follow this  
varun_shrivastava

OpenGL Single or multiple program objects

This topic is 2580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After reading Orange book (OpenGL 2.0), some doubts are there in my mind.
In order to render a scene, a single program object (with one vertex/fragment shader) or multiple program objects can be used.

i.e. all the objects with one program object or every object can define its own program object.

i went through other threads on this forum and got to know about different techniques. But some doubts came to my mind regarding how global states of the scene like lightning, fog will work if every object use its own shader. This will imply setting up of all the global states to each new program object that's being created by objects in the scene.

What would be a better approach for this or its the only way?

Share this post


Link to post
Share on other sites
Advertisement

After reading Orange book (OpenGL 2.0), some doubts are there in my mind.
In order to render a scene, a single program object (with one vertex/fragment shader) or multiple program objects can be used.

i.e. all the objects with one program object or every object can define its own program object.

i went through other threads on this forum and got to know about different techniques. But some doubts came to my mind regarding how global states of the scene like lightning, fog will work if every object use its own shader. This will imply setting up of all the global states to each new program object that's being created by objects in the scene.

What would be a better approach for this or its the only way?

You normaly group your objects to be rendered by shaders to avoid shader/state switches. I.e. when rendering a scene with terrain, trees, water and some characters, you could proceed like this:

turn on shader 'terrain'
=>render all terrain patches
turn on shader 'tree'
=>render all trees
turn on shader 'character_material'
=>render main char
=>render npcs
=>render animals
turn on shader 'bloom'
=> render single rectangle to do some post processing
...

Share this post


Link to post
Share on other sites

[quote name='varuns' timestamp='1321611760' post='4885276']
After reading Orange book (OpenGL 2.0), some doubts are there in my mind.
In order to render a scene, a single program object (with one vertex/fragment shader) or multiple program objects can be used.

i.e. all the objects with one program object or every object can define its own program object.

i went through other threads on this forum and got to know about different techniques. But some doubts came to my mind regarding how global states of the scene like lightning, fog will work if every object use its own shader. This will imply setting up of all the global states to each new program object that's being created by objects in the scene.

What would be a better approach for this or its the only way?

You normaly group your objects to be rendered by shaders to avoid shader/state switches. I.e. when rendering a scene with terrain, trees, water and some characters, you could proceed like this:

turn on shader 'terrain'
=>render all terrain patches
turn on shader 'tree'
=>render all trees
turn on shader 'character_material'
=>render main char
=>render npcs
=>render animals
turn on shader 'bloom'
=> render single rectangle to do some post processing
...

[/quote]

yeah that's a good implementation. But as i mentioned previously, how a global light source will affect the scene.
As different shaders are being used, we need to set lightning parameters again on every shader switch or there is another way of achieving it.

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!