0
\$\begingroup\$

I got a full functioning heightmap loader, however I can only use one texture. Now I want to implement more textures (like diffrent textures depending on heights ect, Possibly a structure that makes it easy to implement diffrent coditions of where to use certain textures)

But I'm a bit unsure how to go about doing this. Could anyone point me in the direction of a good guide on how you would implement something like this.

\$\endgroup\$
1
\$\begingroup\$

The term you are looking for is multitexturing. For this, you have to send every texture you want to use to the pixel shader, and there decide from some per-vertex weight factor how much each texture will add its value to the final color. For example, if you want to use 4 textures, you add a float4 value to your vertices (I'd call this weight). Then in pixel shader sample your 4 textures into float4 col1,col2,col3,col4 values. The final color then would be:

 float4 finalColor = col1*weight.x + col2*weight.y + col3*weight.z + col4*weight.w;

You should set the weighting while generating your heightmap, and the weights should normally add up to 1. The logic, which you generate those should be trivial for you, but if you are having problems, then I recommend Riemers' tutorials which is XNA, but it can be easily implemented. You can even look at his multitexturing algorythm based on terrain heights.

\$\endgroup\$
  • 1
    \$\begingroup\$ thx, this was very helpful :)! \$\endgroup\$ – Fredrik Boston Westman Feb 22 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.