I’m working on creating a 3D landscape. So far I’ve got a mesh created with vertices and faces, and it all looks decent. I’ve applied a single texture to it, but want to have multiple textures perhaps based on the height. I’m thinking I need a shader to do this.
I’m new to shaders but so far I’ve followed this tutorial and have two textures blended together. However, I want to fade one texture out completely at certain heights (or position) and have the other completley show.
I’m really not sure how to approach this using a shader. Could someone give some advice on how to start?
For argument’s sake, suppose your source geometry runs from y=0 to y=1 and you want the second texture to be completely transparent at y=0 and completely opaque at y=1. Then you could add an addition varying, named
secondTextureAlphaor something like that. Load it with your pre-transformation y values in the shader, then combine the incoming values from the source textures either so that the second is multiplies bysecondTextureAlpha, if you want to stick with additive blending, or via themixfunction for multiplicative.So e.g. the fragement shader might end up looking like:
To achieve a more complicated mapping, just adjust how you load
secondTextureAlphain your vertex shader, or take it as an input attribute maybe.