PDA

View Full Version : detail texture fading out into distance



soconne
11-19-2003, 09:33 AM
Anybody know of a good method for making a detail texture fade out when it gets to far away from the viewer?

I've tried specifying my own mipmaps, but when I do they don't blend together right as they go off into the distance. Plus the blend from the first to the last one within about 10 units of the camera, meaning 10 opengl units.

Basically I have a terrain with a detail texture, but it creates a visible 'pattern' across the entire landscape. This is what I want to get rid of.

jwatte
11-19-2003, 12:09 PM
If it fades out quickly, perhaps you're drawing it too tightly tiled. Try dividing your texture coordinates by some single-digit integer, like 4.

To get the MIP maps to fade "correctly" you must use LINEAR_MIPMAP_LINEAR filtering, or possibly ANISOTROPIC.

Also, using MIP mapping to determine distance won't work right, as a close-but-slanted surface will use a higher MIP map level.

I would use a second texture, or just color value, that lerps from 1 in the near range to 0 in the far range, and modulate the alpha of the detail texture with this value. You'll need texture_env_crossbar+texture_env_combine to pull this off, or better (NV_register_combiners, or ARB_fragment_program).

soconne
11-19-2003, 04:21 PM
I actually tried using the combine arb extension, but then it doesn't actually look like it was 'modulated', but the actual color appears instead of being blended. For example the texture is a gray rock pattern, and the main landscape texture is grass. If I use the combine extension, then I see gray showing through where the alpha map had a 0 and so forth. So it's not actually modulating, unless the modulate function lets you specify your own transparency value. Anyway have any ideas?

jwatte
11-19-2003, 06:06 PM
Unfortunately, your description does not explain exactly what you tried to do, nor what your expected result is. For example, it's even un-clear whether you're trying to do this in a single pass multi-texture application, or multi-pass framebuffer blending operation.

I suggest studying the fragment processing pipeline, as explained in the OpenGL specification PDF, which you can download for free from the front page of this web site. Trust me: the functionality works exactly as specified, and is clearly capable of providing what it sounds like you want, both for single-pass and multi-pass solutions.

soconne
11-19-2003, 09:11 PM
I meant to say I was using multitexturing which should be implied by 'combine arb extension'. Does anybody know of a good method for fading out the detail texture, perhaps by using alpha values? As mentioned above, using the combine arb extension the detail map actual shows through the first texture without actually being blended or modulated.

zeckensack
11-20-2003, 08:14 AM
Depends on how your detail textures are created (art problem, perhaps?).

You can get a pretty good effect using GL_ADD_SIGNED_ARB. This way, your detail texture can lighten or darken the base texture. This is done with a bias, so your detail texture data must be 'centered' at 50% grey.

If you're modulating with a light map you will want to do that after adding base and detail texture.

As for distance fading, this will work automatically with mipmap selection (trilinear filtering on the detail map is recommended). If it fades 'too near' you should either
1)increase detail map resolution
1a)try GL_MIRRORED_REPEAT (if available on the target) for easy resolution doubling
2)scale down the texture coordinates for the detail map (in effect zooming in)

Another texture controlling the fade works, too, of course, but the cost of occupying another texture sampler and increasing vertex size looks a bit wasteful to me.

tweakoz
11-20-2003, 08:44 AM
Originally posted by oconnellseanm:
[B]Anybody know of a good method for making a detail texture fade out when it gets to far away from the viewer?


I use either multitexturing or multipass combined with a vertex program similar to below.




DP4 DeviceCoord.x, matMVP[0], VtxPos;
DP4 DeviceCoord.y, matMVP[1], VtxPos;
DP4 DeviceCoord.z, matMVP[2], VtxPos;
DP4 DeviceCoord.w, matMVP[3], VtxPos;
MOV result.position, DeviceCoord;

#########################################
# Depth/Alpha Fog
#
# Generate a fog texture blend value
# based on camera depth
#
# Value will be 1.0 at z = fog_start
# Value will be 0.0 at z = (fog_start+fog_range)
#
# fog parameters:
# FogParams.z = fog start
# FogParams.w = fog range
# KConst = { 0.0, 0.5, 1.0, 4.0 };
#
# should be able to use this for detail
# texturing also, I would probably give
# a separate set of start/range values
# for the detail texture. and the blend
# value calc will be inverted.
#
#########################################

ADD Temp0.z, DeviceCoord.z, -FogParams.z;
RCP Temp0.w, FogParams.w;
MAD FogV.w, -Temp0.z, Temp0.w, KConst.zzzz;
MIN FogV.w, FogV.w, KConst.z;



mtm