浏览代码

various fix + backport change of WRITE_NORMAL_BUFFER on all shader + add shader preprocessor

/main
Sebastien Lagarde 7 年前
当前提交
23c3f077
共有 8 个文件被更改,包括 62 次插入11 次删除
  1. 20
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitShaderPreprocessor.cs
  2. 12
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader
  3. 12
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  4. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl
  5. 6
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader
  6. 12
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader
  7. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  8. 6
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs

20
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitShaderPreprocessor.cs


using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline

protected ShaderKeyword m_WriteNormalBuffer;
LitShaderPreprocessor()
{
m_WriteNormalBuffer = new ShaderKeyword("WRITE_NORMAL_BUFFER");
}
bool LitShaderStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData)
{
if (CommonShaderStripper(hdrpAsset, shader, snippet, inputData))

bool isForwardPass = snippet.passName == "Forward";
bool isDepthOnlyPass = snippet.passName == "DepthOnly";
bool isTransparentForwardPass = snippet.passName == "TransparentDepthPostpass" || snippet.passName == "TransparentBackface" || snippet.passName == "TransparentDepthPrepass";
// When using forward only, we never need GBuffer pass (only Forward)

// When we are in deferred (i.e !hdrpAsset.renderPipelineSettings.supportOnlyForward), we only support tile lighting
if (!hdrpAsset.renderPipelineSettings.supportOnlyForward && inputData.shaderKeywordSet.IsEnabled(m_ClusterLighting))
return true;
if (isDepthOnlyPass)
{
// When we are full forward, we don't have depth prepass without writeNormalBuffer
if (hdrpAsset.renderPipelineSettings.supportOnlyForward && !inputData.shaderKeywordSet.IsEnabled(m_WriteNormalBuffer))
return true;
// When we are in deferred we don't have depth prepass with writeNormalBuffer
if (!hdrpAsset.renderPipelineSettings.supportOnlyForward && inputData.shaderKeywordSet.IsEnabled(m_WriteNormalBuffer))
return true;
}
if (!hdrpAsset.renderPipelineSettings.supportOnlyForward)
{

12
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader


ZWrite On
ColorMask 0
HLSLPROGRAM
HLSLPROGRAM
// In deferred, depth only pass don't output anything.
// In forward it output the normal buffer
#pragma multi_compile _ WRITE_NORMAL_BUFFER
#ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator
#include "../Lit/ShaderPass/LitSharePass.hlsl"
#else
#endif
#include "LayeredLitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

12
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader


ZWrite On
ColorMask 0
// In deferred, depth only pass don't output anything.
// In forward it output the normal buffer
#pragma multi_compile _ WRITE_NORMAL_BUFFER
#ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator
#include "../Lit/ShaderPass/LitSharePass.hlsl"
#else
#endif
#include "LayeredLitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

2
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl


#define CLEAR_COAT_IOR 1.5
#define CLEAR_COAT_IETA (1.0 / CLEAR_COAT_IOR) // IETA is the inverse eta which is the ratio of IOR of two interface
#define CLEAR_COAT_F0 0.04 // IORToFresnel0(CLEAR_COAT_IOR)
#define CLEAR_COAT_ROUGHNESS 0.01
#define CLEAR_COAT_ROUGHNESS 0.001
#define CLEAR_COAT_PERCEPTUAL_ROUGHNESS RoughnessToPerceptualRoughness(CLEAR_COAT_ROUGHNESS)
//-----------------------------------------------------------------------------

6
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader


#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator
#include "ShaderPass/LitSharePass.hlsl"
#else
#endif
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

12
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader


ZWrite On
ColorMask 0
// In deferred, depth only pass don't output anything.
// In forward it output the normal buffer
#pragma multi_compile _ WRITE_NORMAL_BUFFER
#ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator
#include "ShaderPass/LitSharePass.hlsl"
#else
#endif
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

3
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader


#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "ShaderPass/StackLitDepthPass.hlsl"
// As we enabled WRITE_NORMAL_BUFFER we need all regular interpolator
#include "ShaderPass/StackLitSharePass.hlsl"
#include "StackLitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

6
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs


{
using (new ProfilingSample(cmd, "Depth Prepass (forward)", CustomSamplerId.DepthPrepass.GetSampler()))
{
cmd.EnableShaderKeyword("OUTPUT_NORMAL_BUFFER");
cmd.EnableShaderKeyword("WRITE_NORMAL_BUFFER");
HDUtils.SetRenderTarget(cmd, hdCamera, m_NormalBufferManager.GetBuffersRTI(), m_CameraDepthStencilBuffer);

{
using (new ProfilingSample(cmd, "Depth Prepass (deferred)", CustomSamplerId.DepthPrepass.GetSampler()))
{
cmd.DisableShaderKeyword("OUTPUT_NORMAL_BUFFER"); // Note: This only disable the output of normal buffer for Lit shader, not the other shader that don't use multicompile
cmd.DisableShaderKeyword("WRITE_NORMAL_BUFFER"); // Note: This only disable the output of normal buffer for Lit shader, not the other shader that don't use multicompile
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraDepthStencilBuffer);

{
using (new ProfilingSample(cmd, "Depth Prepass (deferred incomplete)", CustomSamplerId.DepthPrepass.GetSampler()))
{
cmd.DisableShaderKeyword("OUTPUT_NORMAL_BUFFER");
cmd.DisableShaderKeyword("WRITE_NORMAL_BUFFER");
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraDepthStencilBuffer);

正在加载...
取消
保存