PDA

View Full Version : Blend and texture env modes



halo
04-13-2005, 12:19 PM
I am writing a materials system which can have up to four passes. Each pass can have a texture, detail map, and cube map. I want the renderer to perform the same regardless of how many texture units are available.

Let's say there are 3 texture units available:
1. set up texture
2. set up detail map
3. set up cube map
4. render

Now let's say there are 2 texture units available:
1. set up texture
2. set up detail map
3. render
4. set up cube map
5. render

I need a blend mode that doesn't brighten or darken, but just kinds of averages the two textures, and I need it to work for both textures and passes.

So far, I am doing this:

First texture in the material:
glTexEnvi GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE
glTexEnvi GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE
glTexEnvf GL_TEXTURE_ENV,GL_RGB_SCALE,2

For the detail and cubemap, I normally use the same code as above. If I have to force an extra render (because there are not enough texture units) I use GL_REPLACE for the texture mode and GL_DST_COLOR,GL_SRC_COLOR for the blend.

This appears to give identical results with multitexturing turned on or off.

Any advice? Am I doing this right?

dorbie
04-13-2005, 03:43 PM
Yes, but you have limited requirements. The main limitation of the technique is that your first pass collapses the result to a single value in the framebuffer. Then subsequent texture operations are limited to using that single value with the available blending operations. It works for your scenario and it's called multipass rendering, but there are more sophisticated ways of building texture shading trees that aren't as easily combined with a framebuffer blend. This was a popular topic when Carmack was writing Quake III and he mantioned some of the issues in his .plan files of that era.

halo
04-13-2005, 08:11 PM
I am trying to get a uniform system that will work for both high and low-end cards. It seems like rendering techniques right now are waaaaaaaaay too open-ended and just not designed as a whole. I hear a lot of discussion of theoretical techniques and what is possible, but I need something that works on all my users' machines. Know what I mean?

dorbie
04-14-2005, 12:37 AM
Yes and it's not 100% possible. Some work has been done on this. Shader trees might be a useful search for you, but this gets complicated and some hardware is severely limited compared to others.

It really depends on how complex you want to get.

Often what is done is more sophisticated cards get more sophisticated graphics with a different rendering path. Simple cards have a more basic fallback rendering path.

halo
04-14-2005, 07:24 AM
Yeah, Half-Life 2 doesn't display anything on a GEForce4; no cube maps, hardly any effects. The card is actually much better than that, but Valve just didn't want to deal with it.

Problem is, only like 20% of your users will have a shader card. Computers ship with outdated cards, and people don't want to spend $500 on a new one, when they can go get an X-Box or something for less money.