参考教程
Tutorial 13: Procedural Terrain Texturing
学习记录
这篇文章中我们介绍 Procedural terrain texturing ,本篇代码基于上一篇,仅有少量改动。
原教程中对于这篇描述如下:
Procedural parameters are usually calculated in our shaders based on input textures or the terrain data itself. One of the most popular parameters is to use the height of the pixel being rendered and apply a texture using different height bands. In this way you can specify the ground texture to be below a certain height, then a rock texture for anything above that height, and finally a snow texture for anything in the final height range. Although this works the results are not entirely realistic.
A more useful procedural parameter to use for determining which texture to apply is the use the slope of the current pixel. The slope can be easily calculated (one minus the Y normal) and has the properties of reflecting real world growth and deposition patterns. For example in this tutorial we use the slope to determine where the rock gets exposed, and everything less than that slope is covered with snow. This represents a real world pattern where anything with too much slope the snow will never accumulate on. Likewise this can be extended to growth patterns, erosion patterns, and so forth.
其实就是选择性的对纹理进行贴图,我们这篇中的场景为雪山,在这里我们使用当前斜率来计算是否使用混合或者直接使用雪的纹理(当山体坡度大的时候没有积雪所以使用雪的纹理与地面纹理混合)。
主要修改 terrain.ps
,使其支持三个纹理并且使用其法线判断混合或者覆盖:
1 | //////////////////////////////////////////////////////////////////////////////// |
其他的修改则只是为了支持新的 terrain.ps
,我们修改 TerrainShaderClass
使其支持三张纹理的渲染,同时修改 ShaderManagerClass
的对应函数。最后在 AoolicationClass
里读入新的纹理,读入的代码如下:
1 | // Load texture 0 |
最后,调用新的渲染方法:
1 | // Render the cell buffers using the terrain shader. |
最终效果: