Archived

This topic is now archived and is closed to further replies.

texture blending depending on vertex height

This topic is 4988 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, I''m coding a terrain renderer. I''d like to blend textures for different height levels depending on vertex height. Is this possible at all without using a pixel shader? From what I read in the DirectX9 documentation primary color of a vertex can be used as an argument of a texture blending operation. Is there a way to automatically compute primary color from vertex position? I thought so because it works for texture coordinates. I also tried the following: I created a volume texture for each terrain level texture with equal width and height and a depth of 1. By using automatic texture coordinate generation for the w texture coordinate and using the border color of black I could fade each texture to black depending on vertex height and just add the results of each texture stage. Unfortunately this doesn''t work with mipmapping as every mipmap level is faded differently. Do you see any way to improve this approach to work with mipmapping or is it just crap? Are there better ways to texture huge terrains without using up too much video memory?

Share this post


Link to post
Share on other sites
Hey!

I''m doing quite the same things as you.
Indeed, you can blend textures of different height levels (problem of switching from global to detail texture, eh?). Even without pixel shaders. All you have to do is to use the texture-combine- extension (see specs for texture_env_combine IIRC).

What you basically do is the following:
You use the alpha of the primary color as blending factor (glColor4f(x,x,x,blend), where blend=0 means texture 0 only and blend=1 means texture 1 only).
Then you tell texture unit 0 to interpolate between texture 0 (color) and texture 1 (color) using the primary color alpha as blending factor.
You tell texture unit 1 to mix modulate the primary color (the blended, lighted color) with the resulting color of texture unit 0.

Sorry, I can''t give you the source code of this, but it''s actually only about 6 lines of code (some glTexEnv calls). See the extension specs. They''re quite useful here.

> From what I read in the DirectX9 documentation primary color of
> a vertex can be used as an argument of a texture blending
> operation. Is there a way to automatically compute primary
> color from vertex position? I thought so because it works for
> texture coordinates.

As far as I know, you either have to do it on the CPU, or you have to use vertex shaders here.

> Do you see any way to improve this approach to work with
> mipmapping or is it just crap?
I also wanted to use 3D textures (I guess that''s the same as volume textures) for height texturing. But then I realized the GeForce II MX 400 doesn''t support this:-( (But the RadeOn 9800 is already ordered!)

My idea was the following: You sort your detail textures by height (e.g. water, beach, gras, mud, hill, rocks) and put them all on top of each other in a 3D texture. Then, you use the vertex height as w-coordinate. This should readily select the right texture and do the blending. This might also solve your mipmapping problem and should work nicely with CLOD and vertex animation stuff.

> Are there better ways to texture huge terrains without using up
> too much video memory?
Definitely compress your textures. It''s just a change of one word (at least in OpenGL) and boosted my performance by 30% and uses much less memory (I think 1/4). See texture compression extension.

Lutz

Share this post


Link to post
Share on other sites
Hello,

thanks for your ideas. I tried blending with the alpha of the diffuse color and it works as you said. Unfortunately there are cases where one triangle is influences by 3 textures but I think I can solve this by using the alpha of the specular color as additional blending factor.

Your idea with the volume texture was my first try. Basically it''s working - as long as you don''t use mipmapping. A 3D texture is mipmapped in all 3 dimensions so with ech mipmap level you lose half your detail textures.

Texture compression is really worth a try too but I will implement it when everything is finished.

Share this post


Link to post
Share on other sites
Hey!

> Your idea with the volume texture was my first try. Basically
> it''s working - as long as you don''t use mipmapping. A 3D texture
> is mipmapped in all 3 dimensions so with ech mipmap level you
> lose half your detail textures.

Urgh! Didn''t think about that.
It will probably strongly depend on the way the hardware selects the mipmap level. I guess it is based on the ratio of texel size and pixel size. However, there are 3 texel sizes, one for each texture coordinate. The first 2 will usually be small whereas the third (the blend direction) will be rather large (>> pixel size). Hmmm, which mipmap level is selected here??

Is there a way to steer the mipmap selection?

How do you - btw - generate a 3d mipmap? Is there a gluGenerate3DMipmaps or something like that?

> Texture compression is really worth a try too but I will
> implement it when everything is finished.

It''s really done easily. You can just check it for curiosity. It''s really just changing one variable (GL_TEXTURE to GL_COMPRESSED_TEXTURE IIRC).

BTW: RadeOn 9800 doesn''t work with my mobo - GRRRR! I''ll order an NVidia today!

Share this post


Link to post
Share on other sites