http://blog.csdn.net/a3070173/archive/2008/11/20/3342062.aspx
- Dislace Mapping其实就是在顶点着色器中
- 对顶点进行置换偏移,经常用于水仿真流体绘制.
- 顶点着色器:
- uniform float g_fScale;
- uniform sampler2D g_DisplaceTexture;
- void main()
- {
- float fDisplace = texture2DLod(g_DisplaceTexture, gl_MultiTexCoord0.st, 0.0).r;
- vec4 vec4NewVertex = vec4(gl_Vertex.x, gl_Vertex.y + g_fScale*fDisplace, gl_Vertex.zw);
-
- gl_TexCoord[0] = gl_MultiTexCoord0;
- gl_Position = gl_ModelViewProjectionMatrix*vec4NewVertex;
- }
- 片元着色器:
- uniform sampler2D g_DecalTexture;
- void main()
- {
- gl_FragColor = texture2D(g_DecalTexture, gl_TexCoord[0].st);
- }
- Demo效果截图:
- exe文件:http://www.fileupyours.com/view/219112/GLSL/Simple%20Displace%20Mapping.rar
- VC9运行库:http://www.fileupyours.com/view/219112/GLSL/VC9%26%2336816%3B%26%2334892%3B%26%2326102%3B%26%2324211%3B.rar