【发布时间】:2013-03-14 18:49:39
【问题描述】:
我为在我的 xna 游戏中添加 雾 效果而苦苦挣扎了一段时间。 我在文件 (.Fx) 中使用自定义着色器效果。 “PixelShaderFunction”可以正常工作。但问题是我所有的土地都以相同的方式着色。 我认为问题出在相机和模型之间的距离的计算上。
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);
}
【问题讨论】:
标签: xna shader game-engine effects fog