浏览代码

Add volumetrics to the HDRI sky

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
4e43b0ab
共有 6 个文件被更改,包括 63 次插入35 次删除
  1. 46
      ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl
  2. 7
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Deferred.compute
  4. 7
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  5. 21
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
  6. 10
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/0xxx.meta

46
ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl


HenyeyGreensteinPhasePartVarying(asymmetry, LdotD);
}
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf
float3 TransmittanceColorAtDistanceToAbsorption(float3 transmittanceColor, float atDistance)
{
return -log(transmittanceColor + 0.00001) / max(atDistance, 0.000001);
}
#ifndef USE_LEGACY_UNITY_SHADER_VARIABLES
#define VOLUMETRIC_LIGHTING_ENABLED
#endif
// TODO: share this...
#define PRESET_ULTRA 0

float4 GetInScatteredRadianceAndTransmittance(float2 positionSS, float depthVS,
TEXTURE3D(VBufferLighting), SAMPLER3D(linearClampSampler),
float4 VBufferDepthEncodingParams, float2 VBufferScale)
float2 VBufferScale, float4 VBufferDepthEncodingParams)
float slice0 = clamp(floor(d * n - 0.5), 0, n - 1); // TODO: somehow avoid the clamp...
float slice1 = clamp( ceil(d * n - 0.5), 0, n - 1); // TODO: somehow avoid the clamp...
// Therefore, we perform 2 bilinear taps.
float d0 = slice0 * rcp(n) + (0.5 * rcp(n));
float d1 = slice1 * rcp(n) + (0.5 * rcp(n));
float s0 = clamp(floor(d * n - 0.5), 0, n - 1); // TODO: somehow avoid the clamp...
float s1 = clamp( ceil(d * n - 0.5), 0, n - 1); // TODO: somehow avoid the clamp...
float d0 = s0 * rcp(n) + (0.5 * rcp(n));
float d1 = s1 * rcp(n) + (0.5 * rcp(n));
float z0 = DecodeLogarithmicDepth(d0, VBufferDepthEncodingParams);
float z1 = DecodeLogarithmicDepth(d1, VBufferDepthEncodingParams);

// Perform 2 bilinear taps. The sampler should clamp the values at the boundaries of the 3D texture.
float4 v0 = SAMPLE_TEXTURE3D_LOD(VBufferLighting, linearClampSampler, float3(uv, d0), 0);
float4 v1 = SAMPLE_TEXTURE3D_LOD(VBufferLighting, linearClampSampler, float3(uv, d1), 0);
float4 vt = lerp(v0, v1, saturate((z - z0) / (z1 - z0)));
// The sampler should clamp to edge.
float4 L0 = SAMPLE_TEXTURE3D_LOD(VBufferLighting, linearClampSampler, float3(uv, d0), 0);
float4 L1 = SAMPLE_TEXTURE3D_LOD(VBufferLighting, linearClampSampler, float3(uv, d1), 0);
float4 L = lerp(L0, L1, saturate((z - z0) / (z1 - z0)));
return float4(vt.rgb, Transmittance(vt.a));
return float4(L.rgb, Transmittance(L.a));
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf
float3 TransmittanceColorAtDistanceToAbsorption(float3 transmittanceColor, float atDistance)
// A version without depth - returns the value for the far plane.
float4 GetInScatteredRadianceAndTransmittance(float2 positionSS,
TEXTURE3D(VBufferLighting), SAMPLER3D(linearClampSampler),
float2 VBufferScale)
return -log(transmittanceColor + 0.00001) / max(atDistance, 0.000001);
// Account for the visible area of the VBuffer.
float2 uv = positionSS * VBufferScale;
// The sampler should clamp to edge.
float4 L = SAMPLE_TEXTURE3D_LOD(VBufferLighting, linearClampSampler, float3(uv, 1), 0);
return float4(L.rgb, Transmittance(L.a));
}
#endif // UNITY_VOLUME_RENDERING_INCLUDED

7
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader


posInput.depthVS,
_VBufferLighting,
s_linear_clamp_sampler,
_VBufferDepthEncodingParams,
_VBufferResolutionAndScale.zw);
diffuseLighting *= volumetricLighting.a;
_VBufferResolutionAndScale.zw,
_VBufferDepthEncodingParams);
// TODO: apply volumetrics after SSS.
// diffuseLighting *= volumetricLighting.a;
specularLighting *= volumetricLighting.a;
specularLighting += volumetricLighting.rgb;
#endif

7
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Deferred.compute


posInput.depthVS,
_VBufferLighting,
s_linear_clamp_sampler,
_VBufferDepthEncodingParams,
_VBufferResolutionAndScale.zw);
diffuseLighting *= volumetricLighting.a;
_VBufferResolutionAndScale.zw,
_VBufferDepthEncodingParams);
// TODO: apply volumetrics after SSS.
// diffuseLighting *= volumetricLighting.a;
specularLighting *= volumetricLighting.a;
specularLighting += volumetricLighting.rgb;
#endif

7
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#ifndef USE_LEGACY_UNITY_SHADER_VARIABLES
#define VOLUMETRIC_LIGHTING_ENABLED
#endif
//-----------------------------------------------------------------------------
// SurfaceData and BSDFData
//-----------------------------------------------------------------------------

#include "SubsurfaceScatteringSettings.cs.hlsl"
#include "../../../Core/ShaderLibrary/VolumeRendering.hlsl"
#include "../../../Core/ShaderLibrary/VolumeRendering.hlsl"
#endif
// Define refraction keyword helpers

21
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader


#include "../../../../Core/ShaderLibrary/Color.hlsl"
#include "../../../../Core/ShaderLibrary/Common.hlsl"
#include "../../../../Core/ShaderLibrary/CommonLighting.hlsl"
#include "../../../../Core/ShaderLibrary/VolumeRendering.hlsl"
#include "../../../ShaderVariables.hlsl"
#ifdef VOLUMETRIC_LIGHTING_ENABLED
TEXTURE3D(_VBufferLighting);
SamplerState s_linear_clamp_sampler;
#endif
float4 _SkyParam; // x exposure, y multiplier, z rotation
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4

dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
#ifdef VOLUMETRIC_LIGHTING_ENABLED
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
float4 volumetricLighting = GetInScatteredRadianceAndTransmittance(posInput.positionSS,
_VBufferLighting,
s_linear_clamp_sampler,
_VBufferResolutionAndScale.zw);
// TODO: apply volumetrics after SSS.
// diffuseLighting *= volumetricLighting.a;
skyColor *= volumetricLighting.a;
skyColor += volumetricLighting.rgb;
#endif
return float4(skyColor, 1.0);
}

10
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/0xxx.meta


fileFormatVersion: 2
guid: 405d053465ae98342849302f26ddfee0
folderAsset: yes
timeCreated: 1508423740
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存