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);
}