浏览代码

Merge pull request #689 from Unity-Technologies/Add-support-of-transparent-depth-prepass

Add support of transparent depth prepass
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
821950ca
共有 5 个文件被更改,包括 65 次插入4 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 26
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataIndividualLayer.hlsl
  4. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  5. 32
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader

2
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


void RenderTransparentDepthPostPass(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd, ForwardPass pass)
{
if (m_FrameSettings.renderSettings.enableTransparentPostPass)
if (!m_FrameSettings.renderSettings.enableTransparentPostPass)
return;
using (new ProfilingSample(cmd, "Render Transparent Depth Post ", GetSampler(CustomSamplerId.TransparentDepthPostPass)))

26
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5
[ToggleOff] _TransparentDepthPrepassEnable("_TransparentDepthPrepassEnable", Float) = 0.0
[ToggleOff] _TransparentBackfaceEnable("_TransparentBackfaceEnable", Float) = 0.0
[ToggleOff] _TransparentDepthPostpassEnable("_TransparentDepthPostpassEnable", Float) = 0.0

#include "ShaderPass/LitDistortionPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL
}
// Caution: Order of pass mater. It should be:
// TransparentDepthPrepass, TransparentBackface, Forward/ForwardOnly, TransparentDepthPostpass
Pass
{
Name "TransparentDepthPrepass"
Tags{ "LightMode" = "TransparentDepthPrepass" }
Cull[_CullMode]
ZWrite On
ColorMask 0
HLSLPROGRAM
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_PREPASS
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "ShaderPass/LitDepthPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}

8
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataIndividualLayer.hlsl


// Perform alha test very early to save performance (a killed pixel will not sample textures)
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER)
float alphaCutoff = _AlphaCutoff;
#ifdef CUTOFF_TRANSPARENT_DEPTH_POSTPASS
#ifdef CUTOFF_TRANSPARENT_DEPTH_PREPASS
alphaCutoff = _AlphaCutoffPrepass;
#elif defined(CUTOFF_TRANSPARENT_DEPTH_POSTPASS)
alphaCutoff = _AlphaCutoffPostpass;
#endif
DoAlphaTest(alpha, alphaCutoff);

surfaceData.baseColor = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).rgb * ADD_IDX(_BaseColor).rgb;
#ifdef _DETAIL_MAP_IDX
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
float3 baseColorOverlay = (detailAlbedo < 0.5) ?
float3 baseColorOverlay = (detailAlbedo < 0.5) ?
surfaceData.baseColor * PositivePow(2.0 * detailAlbedo, ADD_IDX(_DetailAlbedoScale)) :
1.0 - (1.0 - surfaceData.baseColor) * PositivePow(2.0 * (1.0 - detailAlbedo), ADD_IDX(_DetailAlbedoScale));
// Lerp with details mask

surfaceData.atDistance = _ATDistance;
// Thickness already defined with SSS (from both thickness and thicknessMap)
surfaceData.thickness *= _ThicknessMultiplier;
// Rough refraction don't use opacity. Instead we use opacity as a transmittance mask.
// Rough refraction don't use opacity. Instead we use opacity as a transmittance mask.
surfaceData.transmittanceMask = 1.0 - alpha;
alpha = 1.0;
#else

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl


// shared constant between lit and layered lit
float _AlphaCutoff;
float _AlphaCutoffPrepass;
float _AlphaCutoffPostpass;
float4 _DoubleSidedConstants;
float _DistortionScale;

32
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5
[ToggleOff] _TransparentDepthPrepassEnable("_TransparentDepthPrepassEnable", Float) = 0.0
[ToggleOff] _TransparentBackfaceEnable("_TransparentBackfaceEnable", Float) = 0.0
[ToggleOff] _TransparentDepthPostpassEnable("_TransparentDepthPostpassEnable", Float) = 0.0

ENDHLSL
}
// Caution: Order of pass mater. It should be:
// TransparentDepthPrepass, TransparentBackface, Forward/ForwardOnly, TransparentDepthPostpass
Pass
{
Name "TransparentDepthPrepass"
Tags{ "LightMode" = "TransparentDepthPrepass" }
Cull[_CullMode]
ZWrite On
ColorMask 0
HLSLPROGRAM
#pragma hull Hull
#pragma domain Domain
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_PREPASS
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "ShaderPass/LitDepthPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}
Pass
{
Name "TransparentBackface"

ColorMask 0
HLSLPROGRAM
#pragma hull Hull
#pragma domain Domain
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_POSTPASS

正在加载...
取消
保存