体积光
先设置参数, 这里的所有属性不需要暴露在材质球上所以没必要写。
Properties
{
_MainTex ("", 2D) = "black" {} //在RenderFeature里面获取相机渲染图来传入
_MaxStep ("",float) = 200 //设置最大步数
_MaxDistance ("",float) = 1000 //最大步进距离
_LightIntensity ("",float) = 0.01 //每次步进叠加的光照强度
_StepSize ("" , float) = 0.1 //每次步进距离
}
float4 GetTheWorldPos(float2 ScreenUV , float Depth)
{ //获取像素的屏幕空间位置 float3 ScreenPos = float3(ScreenUV , Depth); float4 normalScreenPos = float4(ScreenPos * 2.0 - 1.0 , 1.0); //得到ndc空间下像素位置 float4 ndcPos = mul( unity_CameraInvProjection , normalScreenPos ); ndcPos = float4(ndcPos.xyz / ndcPos.w , 1.0); //获取世界空间下像素位置 float4 sencePos = mul( unity_CameraToWorld , ndcPos * float4(1,1,-1,1)); sencePos = float4(sencePos.xyz , 1.0); return sencePos; } ```