Sign in to follow this  
zaneski13

OpenGL Multipass help

Recommended Posts

This seems like it should be simple enough and yet I haven't been able to figure it out. The way I'm rendering stuff is I have a diffuse pass where I just render the scene with all of its diffuse textures. The second pass is the lighting pass where I render the scene without textures but with lights. The way I want to blend these two scenes together is where the lighting scene is white the diffuse scene will be at full brightness and where the lighting scene is black I want the diffuse scene to be pitch black. (I set restrictions in my shader code so that I'll never have a black pixel. ) So basicly I'm just multiplying the light scene by the diffuse scene but I can't figure out what blend functions to use. Would I be better off rendering the scenes to a texture and then blending the textures appropriately? Also, how can I query opengl to find out how many texture units I have available? because if I do end up taking the shader approach, I might have to pass more textures than allowed, which in that case, I'd need a recursive function that passes the scenes textures over to the shader as many times as needed, then blend the textures that the shader generated, recursively.

Share this post


Link to post
Share on other sites
Render to texture.

Blending modes function on individual polygons. A multiplicative blending mode wouldn't work, because then objects in your scene would be multiplied by each other as they were drawn.

After you render to texture, my best bet would be using a shader to blend them, as you mentioned.

If you're just using two textures, you're almost certainly not going to run out of room. You probably have 16 or 32 units at your disposal. Maybe even 64. At that point, fillrate is going to be more important than how many textures you're using.

Share this post


Link to post
Share on other sites
Quote:
Original post by zaneski13So basicly I'm just multiplying the light scene by the diffuse scene but I can't figure out what blend functions to use.

Use either :
glBlendFunc(GL_DST_COLOR, GL_ZERO);
or :
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
which gives exactly the same results.

Quote:
Original post by zaneski13Would I be better off rendering the scenes to a texture and then blending the textures appropriately?

If you are fill-rate limited, try the render-to-texture approach. If your fillrate is not an issue, I suggest to stick with blending at least in the beginning. Render-to-texture allows you to perform more complex blending at a later stage, and somehow will provide some kind of deferred shading.

Quote:
Original post by zaneski13Also, how can I query opengl to find out how many texture units I have available?

Call glGetIntegerv with GL_MAX_TEXTURE_UNITS. However, please note that the "old" texture unit approach is more or less deprecated, and many graphics cards can render much more textures that what GL_MAX_TEXTURE_UNITS returns. You would need to use fragment shaders though.

More information here :
http://www.opengl.org/wiki/Textures_-_more#Max_Texture_Units

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this