Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我尝试添加距离衰减时,我的 HLSL 代码无法正常工作。
我试过这个:
Output.Color = baseColor*(diffuseLightingFactor + xAmbient * (1 / xDistance));
和这个:
diffuseLightingFactor *= 1 / xDistance;
xDistance 是相机和模型之间的距离。
有人可以帮忙吗,因为我是着色器的新手,根本不知道。
尝试这个:
Output.Color = float4(saturate( baseColor * ( (diffuseLightingFactor + xAmbient) * (1 / xDistance)) ).rgb, 1);
这确保了 alpha(透明度)始终为 1,并且其他颜色在 0 和 1 之间。我还在光照因子的总和周围添加了括号,以便将雾因子应用于两者。