advanced terrain texturing

leaving out the story why
i need to combine 4 or more textures, and i have the density-value of every texture per vertex. the sum of all alpha-values on a vertex is 1.

how to render this ?
and more important : how to render this less passes than 1 per texture ?

Well in the multipass scenario, don’t use alpha, use vertex color to modulate the texture. Set vertex color to 0.25 and draw four passes with a blend equation of GL_ONE, GL_ONE. Except the first pass which should have no blending.

Alternatively you could compute the alpha at each vertex remembering that the first pass should always be 1.0 even if it is subsequently obscured and each pass is modulated by 1-alpha in subsequent passes, remembering to set the blendfunction to SRC_ALPHA, ONE_MINUS_SRC_ALPHA.

The arithmetic of the passes is simple, you just have to remember that subsequent pass contributions modulate earlier passes by 1-alpha and factor that into the arithmetic per vertex.

Multitexture could also be used and isn’t that difficult either. Similar rules may apply although it depends on the number of texture units. Just think about the arithmetic contribution of terms to the final value and know that you must start with final fragment alpha = 1 on the first pass and you can’t go wrong.

You could probably do something clever with saturate alpha and just specify alpha directly on each pass, but that’s up to you to work out. It would be simplest I think, but I wouldn’t trust that blend equation to work and be quick everywhere, although I haven’t tested this.

[This message has been edited by dorbie (edited 02-26-2004).]