浏览代码

Port the scattering code

/main
Evgenii Golubev 8 年前
当前提交
a7733afe
共有 3 个文件被更改,包括 42 次插入5 次删除
  1. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/AtmosphericScattering.hlsl
  2. 39
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader
  3. 1
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs

7
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/AtmosphericScattering.hlsl


#endif
}
inline float4 LinearEyeDepth4(float4 z) { return float4(1.0, 1.0, 1.0, 1.0) / (_ZBufferParams.zzzz * z + _ZBufferParams.wwww); }
float VolundSampleScatterOcclusion(float2 pos) {
#if defined(ATMOSPHERICS_OCCLUSION)
float2 uv = UVFromPos(pos);

baseUV.xy = uv + _DepthTextureScaledTexelSize.xw; xDepth.z = SAMPLE_TEXTURE2D_LOD(_CameraDepthTexture, SRL_BilinearSampler, baseUV);
baseUV.xy = uv + _DepthTextureScaledTexelSize.zw; xDepth.w = SAMPLE_TEXTURE2D_LOD(_CameraDepthTexture, SRL_BilinearSampler, baseUV);
xDepth = LinearEyeDepth4(xDepth);
xDepth.x = LinearEyeDepth4(xDepth.x);
xDepth.y = LinearEyeDepth4(xDepth.y);
xDepth.z = LinearEyeDepth4(xDepth.z);
xDepth.w = LinearEyeDepth4(xDepth.w);
float4 diffDepth = xDepth - cDepth.rrrr;
float4 maskDepth = abs(diffDepth) < _OcclusionDepthThreshold;

39
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader


TEXTURECUBE(_Cubemap);
SAMPLERCUBE(sampler_Cubemap);
float4 _SkyParam; // x exposure, y multiplier, z rotation
float4x4 _InvViewProjMatrix;
float4 _SkyParam; // x exposure, y multiplier, z rotation
struct Attributes
{

float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
return ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0) * exp2(_SkyParam.x) * _SkyParam.y);
float3 skyDome = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
Coordinate coord = GetCoordinate(input.positionCS.xy, _ScreenSize.zw);
// TODO: what sort of depth and world position values do we compute here?
float rawDepth = LOAD_TEXTURE2D(_CameraDepthTexture, coord.unPositionSS).r;
float3 positionWS = UnprojectToWorld(rawDepth, coord.positionSS, _InvViewProjMatrix);
float4 c1, c2, c3;
VolundTransferScatter(positionWS, c1, c2, c3);
float4 coord1 = float4(c1.rgb + c3.rgb, max(0.f, 1.f - c1.a - c3.a));
float3 coord2 = c2.rgb;
float sunCos = dot(normalize(dir), _SunDirection);
float miePh = MiePhase(sunCos, _MiePhaseAnisotropy);
float2 occlusion = float2(1.0, 1.0); // TODO.
float extinction = coord1.a;
float3 scatter = coord1.rgb * occlusion.x + coord2 * miePh * occlusion.y;
#ifdef ATMOSPHERICS_DEBUG
switch (_AtmosphericsDebugMode)
{
case ATMOSPHERICS_DBG_RAYLEIGH: return c1;
case ATMOSPHERICS_DBG_MIE: return c2 * miePh;
case ATMOSPHERICS_DBG_HEIGHT: return c3;
case ATMOSPHERICS_DBG_SCATTERING: return float4(scatter, 1.0);
case ATMOSPHERICS_DBG_OCCLUSION: return float4(occlusion.xy, 0.0, 1.0);
case ATMOSPHERICS_DBG_OCCLUDEDSCATTERING: return float4(scatter, 1.0);
}
#endif
return float4(skyDome * extinction + scatter, 1.0);
}
ENDHLSL

1
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs


m_RenderSkyPropertyBlock.SetTexture("_Cubemap", skyParameters.skyHDRI);
m_RenderSkyPropertyBlock.SetVector("_SkyParam", new Vector4(skyParameters.exposure, skyParameters.multiplier, skyParameters.rotation, 0.0f));
m_RenderSkyPropertyBlock.SetMatrix("_InvViewProjMatrix", Utilities.GetViewProjectionMatrix(camera).inverse);
var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial, 0, 0, m_RenderSkyPropertyBlock);

正在加载...
取消
保存