三维场景渲染中,通常需要模拟一些流动的效果,如河流,管道流向等,通过改变纹理坐标变换矩阵,可以方便的产生流动的效果。
//设置纹理
drawArgs.Device.SetTexture(0,gravelOrbit_Single.MeshTexture);
//纹理变换矩阵 tMatrix = Matrix.Identity 渲染函数外定义
//tu方向流动
// tMatrix.M31 += 8f;
// tv方向流动
tMatrix.M32 += 0.1f;
//设置纹理变换标志,具体参数是什么,还不清楚,如果有知道的朋友可以留言告诉我!
drawArgs.Device.SetTextureStageState(0, TextureStage.TextureTransformFlags, TextureTransform.Count2);
//设置纹理坐标变换矩阵
drawArgs.Device.SetTransform(TransformState.Texture0, tMatrix);
以上是应用SlimDX的设置函数。实现语言不同,但是d3d的思路是一致的。
一下是其他变换的设置:
tMatrix.M11 表示tu方向上的缩放
tMatrix.M22 表示tv方向上的缩放