Skip to main content
GameDev.net gamedev.net
🔒 Locked

Single or multiple program objects

Started by varun_shrivastava Nov 18, 2011 at 10:22 AM 1 replies 850+ views
Original Post
varun_shrivastava
varun_shrivastava
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?
Ashaman73
Ashaman73

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
...
varun_shrivastava
varun_shrivastava

[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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.