2
我挣扎了一段时间,在我的xna游戏中添加了一个fog效果。 我在文件(.Fx)中使用自定义着色器效果。 “PixelShaderFunction”的工作原理没有错误。但问题是我所有的土地都以同样的方式着色。 我认为问题来自相机与型号之间距离的计算。如何计算xna上雾效应模型的距离?
float distance = length(input.TextureCoordinate - cameraPos);
这是我与“PixelShaderFunction”
// Both techniques share this same pixel shader.
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float distance = length(input.TextureCoordinate - cameraPos);
float l = saturate((distance-fogNear)/(fogFar-fogNear));
return tex2D(Sampler, input.TextureCoordinate) * lerp(input.Color, fogColor, l);
}
非常感谢!你的例子非常适合我的问题。 – 2013-04-02 06:54:22