问题
Is there a way to blend 2 textures in a gradient manner? ex. first textures starts at top and goes to the bottom, and second one starts bottom and goes top. I want to make them loose opacity like in a gradient to create a smooth connection. Is it possible?
Maybe there is some other way to create such textures? The problem is that the difference in heights in my terrain does not look really well - in one square area, one triangle has a different texture than the other.
回答1:
For every terrain texture store an additional blend amount in your terrain vertex. This blend amount is simply a float
value in the range of 0
to 1
, where 0
means zero opacity and 1
means that the texture is fully opaque.
In the pixel shader you can use this amount to interpolate between the sampled pixels from the base texture and the blended one.
In this picture you can see a 3*3 terrain with a ground texture and a grass texture on top of it. The numbers represent the blend amount for each of the vertices:
回答2:
Use a shader. You can either use two sampler2D textures, or one single sampler2DArray texture. GLSL has linear (mix
) and hermite (smoothstep
) interpolation functions builtin.
来源:https://stackoverflow.com/questions/14630838/terrain-texturing