Jump to content
  • Advertisement
Sign in to follow this  
pammatt

texture blending layers

This topic is 5057 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

Hi guys, I know what I want to do, but I'm not sure how to do it. :-) I rendering the textures on my terrain and I want to do it like the following. Each texture layer (with the exception of the base layer), has an alpha map associated with it. I want to use that alpha map to blend the current layer onto the layer below it. I also want to support a infinite number of texture layers (obviously restricted by performance). So my questions are, how do I do this? Do I need to use register combiners and if so how? I do not want to use any vertex or fragment shaders, at least not now. I'd appreciate any help, I've been looking up things and trying to figure it out for a while now. [Edited by - pammatt on November 17, 2004 10:30:28 AM]

Share this post


Link to post
Share on other sites
Advertisement
That's pretty easy to do with blending and/or texture combiners.

The easiest way : full multipass.
render the terrain with the base texture
enable blending (glEnable(GL_BLEND) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA))
set depth function to equal (glDepthFunc(GL_EQUAL))
for i = 2 to n, render the terrain with the ith texture
disable blending (glDisable(GL_BLEND))
restore depth function (eg glDepthFunc(GL_LESS))

More clever way : use as many texture units as possible.
Use the same method as above, except that you group texture passes with multitexturing available for the first pass. For instance, if your graphics card supports 4 texture units and if you have 7 layers, then render 4 layers in a first pass and render the 3 other layers in 3 passes.

The former method uses n passes to render n layers. The latter method uses min(0,n-m)+1 to render n layers with m texture units.

Share this post


Link to post
Share on other sites
with any card u can do.
draw the first terrain layer.
and then for subsequent texture layers enable blending with GL_SRC_ALPHA ONE_MINUS_SRC_ALPHA, + draw the relelavent terrain polygons.

with higher capable cards u can collaspse these multiple passes down into fewer passes (which may or may not run quicker)
eg with glsl on gffx u can access 16 textures in one pass

Share this post


Link to post
Share on other sites
good point reminds me with the blending passes u can disable deopthwrites, which will provide a speedboost (maybe)
also dont use GL_EQUAL (the ati performance faq saiz this aint optimal) use GL_LEQUAL instead

Share this post


Link to post
Share on other sites
Right, makes sense, but what stumps me, is how do I do this using a seperate alpha map and not the alpha channel of the terrain texture layers. The reason I ask, is that I want to use the same set of texture coordinates for each layer and rely on the texture matrix. So if I want one of the texture layers to repeat several times, I want its alpha mask to remain unaffected.

Share this post


Link to post
Share on other sites
Quote:
Right, makes sense, but what stumps me, is how do I do this using a seperate alpha map and not the alpha channel of the terrain texture layers

You can use pair of textures with the GL_ARB_texture_env_crossbar extension (or GL_NV_texture_env_combine4 for NVIDIA cards). This requires graphics cards that handle multitexturing with at least 2 texture units (TBH almost all cards do it today!), and this requires twice the number of texture units when using the "second" method I mentioned above.

Share this post


Link to post
Share on other sites
you dont need to use the crossbar extension.

you have to use 2 texture units for the mask and the terrain quad (using interpolate, not modulate), then the result of that u blend with multipass (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).

just do that for all ur layers.

you can avoid the multipass completely and just do multitexturing, but you'll run out of texture units very fast! 3 layers + 3 masks = 6 texture units, or in ur case 3 layers + 2 masks = 5 units.

older cards have 4 units, moderately new cards have 6, and most new cards have 8.

Share this post


Link to post
Share on other sites
Quote:
Original post by DaN1maL
you dont need to use the crossbar extension.

...

you can avoid the multipass completely and just do multitexturing, but you'll run out of texture units very fast!

If you're skipping multipass thanks to multitexturing, you _need_ the crossbar capability.

Quote:
Original post by DaN1maL
older cards have 4 units, moderately new cards have 6, and most new cards have 8.

Roughly :
GeForce1, GeForce2GTS/MX/Go) and GeForce4MX/Go have 2 texture units, GeForce 3Ti and GeForce4Ti have 4 texture units and GeForceFX have 16 texture units (well, in fact you have to play a bit with it to get as much as that, since only 4 are available without fragemnt programs).
Radeon 7xxx have 3 texture units, Radeon 8xxx lower 9xxx (that is, R200 class) have 6 texture units, and higher Radeon 9xxx (R300 class) have 8 texture units.
And most other graphics cards do support 2 texture units, except very very old cards that so not support multitexturing.

Share this post


Link to post
Share on other sites
By older I meant gf3 ;)

You don't need crossbar ext...

texunit 0 - layer 1 (doesn't need mask)
texunit 1 - layer 2's mask
texunit 2 - layer 2 (use interpolate to blend using prev alpha map)
texunit 3 - layer 3's mask
texunit 4 - layer 3 (use interpolate to blend using prev alpha map)

You never need to access anything before the previous texture unit.

Unless crossbar does more than allow you to use GL_TEXTUREn .. I'm not sure. I've never had to use crossbar, and I've done exactly the above.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!