VolumetricLighting/Assets/VolumetricFog/Shaders/VolumetricFog.cginc

35 lines
770 B
HLSL
Raw Normal View History

2016-11-01 13:25:56 +01:00
sampler3D _VolumeScatter;
float4 _VolumeScatter_TexelSize;
float4 _Screen_TexelSize;
float _CameraFarOverMaxFar;
float _NearOverFarClip;
int ihash(int n)
{
n = (n<<13)^n;
return (n*(n*n*15731+789221)+1376312589) & 2147483647;
}
float frand(int n)
{
return ihash(n) / 2147483647.0;
}
float2 cellNoise(int2 p)
{
int i = p.y*256 + p.x;
return float2(frand(i), frand(i + 57)) - 0.5;//*2.0-1.0;
}
half4 Fog(half linear01Depth, half2 screenuv)
{
half z = linear01Depth * _CameraFarOverMaxFar;
z = (z - _NearOverFarClip) / (1 - _NearOverFarClip);
if (z < 0.0)
return half4(0, 0, 0, 1);
half3 uvw = half3(screenuv.x, screenuv.y, z);
2022-04-03 17:47:44 +02:00
//uvw.xy += cellNoise(uvw.xy * _Screen_TexelSize.zw) * _VolumeScatter_TexelSize.xy * 0.8;
2016-11-01 13:25:56 +01:00
return tex3D(_VolumeScatter, uvw);
}