浏览代码

Merge pull request #1857 from Unity-Technologies/HDRP/decals/v2_1/normal_buffer

Hdrp/decals/v2 1/normal buffer
/hdrp-staging
GitHub 6 年前
当前提交
92fa3473
共有 17 个文件被更改,包括 335 次插入19 次删除
  1. 1
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  2. 7
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  3. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs
  4. 150
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  5. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProjectorComponent.cs
  6. 6
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl
  7. 7
      com.unity.render-pipelines.high-definition/HDRP/Material/GBufferManager.cs
  8. 9
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs
  9. 5
      com.unity.render-pipelines.high-definition/HDRP/Material/RenderPipelineMaterial.cs
  10. 10
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  11. 5
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl
  12. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDCustomSamplerId.cs
  13. 40
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  14. 2
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  15. 6
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  16. 87
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader
  17. 9
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader.meta

1
com.unity.render-pipelines.high-definition/CHANGELOG.md


- Fix display correct target platform when showing message to inform user that a platform is not supported
- Remove workaround for metal and vulkan in normal buffer encoding/decoding
- Fixed an issue with color picker not working in forward
- Decals corectly update normal buffer in forward
- Fixed an issue where reseting HDLight do not reset all of its parameters
### Changed

7
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs


protected MaterialProperty drawOrder = new MaterialProperty();
protected const string kDrawOrder = "_DrawOrder";
protected const string kDecalStencilWriteMask = "_DecalStencilWriteMask";
protected const string kDecalStencilRef = "_DecalStencilRef";
protected MaterialEditor m_MaterialEditor;
// This is call by the inspector

CoreUtils.SetKeyword(material, "_ALBEDOCONTRIBUTION", material.GetFloat(kAlbedoMode) == 1.0f);
CoreUtils.SetKeyword(material, "_COLORMAP", material.GetTexture(kBaseColorMap));
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap));
CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
material.SetInt(kDecalStencilWriteMask, (int)HDRenderPipeline.StencilBitMask.Decals);
material.SetInt(kDecalStencilRef, (int)HDRenderPipeline.StencilBitMask.Decals);
material.SetShaderPassEnabled(HDShaderPassNames.s_MeshDecalsMStr, false);
material.SetShaderPassEnabled(HDShaderPassNames.s_MeshDecalsAOStr, false);
material.SetShaderPassEnabled(HDShaderPassNames.s_MeshDecalsMAOStr, false);

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs


protected const string kStencilWriteMask = "_StencilWriteMask";
protected const string kStencilRefMV = "_StencilRefMV";
protected const string kStencilWriteMaskMV = "_StencilWriteMaskMV";
protected const string kStencilDepthPrepassRef = "_StencilDepthPrepassRef";
protected const string kStencilDepthPrepassWriteMask = "_StencilDepthPrepassWriteMask";
protected const string k_GeometricNormalFilteringEnabled = "_GeometricNormalFilteringEnabled";
protected const string k_TextureNormalFilteringEnabled = "_TextureNormalFilteringEnabled";

material.SetInt(kStencilWriteMask, (int)HDRenderPipeline.StencilBitMask.LightingMask);
material.SetInt(kStencilRefMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
material.SetInt(kStencilWriteMaskMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
// for depth only pass to be used in decal to normal buffer compositing
material.SetInt(kStencilDepthPrepassRef, (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer);
material.SetInt(kStencilDepthPrepassWriteMask, (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer);
}
}
} // namespace UnityEditor

150
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader


[ToggleUI] _MaskmapSmoothness("_MaskmapSmoothness", Range(0.0, 1.0)) = 1.0
[HideInInspector] _DecalMeshDepthBias("_DecalMeshDepthBias", Float) = 0.0
[HideInInspector] _DrawOrder("_DrawOrder", Int) = 0
// Stencil state
[HideInInspector] _DecalStencilRef("_DecalStencilRef", Int) = 8
[HideInInspector] _DecalStencilWriteMask("_DecalStencilWriteMask", Int) = 8
}
HLSLINCLUDE

Pass
{
Name "DBufferMesh_3RT" // Name is not used
Tags{"LightMode" = "DBufferMesh_3RT"} // Smoothness
Tags{"LightMode" = "DBufferMesh_3RT"} // Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

Pass
{
Name "DBufferProjector_M" // Name is not used
Tags{"LightMode" = "DBufferProjector_M"} // Metalness
Tags{"LightMode" = "DBufferProjector_M"} // Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

Name "DBufferProjector_AO" // Name is not used
Tags{"LightMode" = "DBufferProjector_AO"} // AO only
// back faces with zfail, for cases when camera is inside the decal volume
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
Cull Front
ZWrite Off
ZTest Greater

Name "DBufferProjector_MAO" // Name is not used
Tags{"LightMode" = "DBufferProjector_MAO"} // AO + Metalness
// back faces with zfail, for cases when camera is inside the decal volume
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
Cull Front
ZWrite Off
ZTest Greater

Pass
{
Name "DBufferProjector_S" // Name is not used
Tags{"LightMode" = "DBufferProjector_S"} // Smoothness
Tags{"LightMode" = "DBufferProjector_S"} // Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

Pass
{
Name "DBufferProjector_MS" // Name is not used
Tags{"LightMode" = "DBufferProjector_MS"} // Smoothness and Metalness
Tags{"LightMode" = "DBufferProjector_MS"} // Smoothness and Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

{
Name "DBufferProjector_AOS" // Name is not used
Tags{"LightMode" = "DBufferProjector_AOS"} // AO + Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

{
Name "DBufferProjector_MAOS" // Name is not used
Tags { "LightMode" = "DBufferProjector_MAOS" } // Metalness AO and Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

Pass
{
Name "DBufferMesh_M" // Name is not used
Tags{"LightMode" = "DBufferMesh_M"} // Metalness
Tags{"LightMode" = "DBufferMesh_M"} // Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_AO" // Name is not used
Tags{"LightMode" = "DBufferMesh_AO"} // AO only
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_MAO" // Name is not used
Tags{"LightMode" = "DBufferMesh_MAO"} // AO + Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

Pass
{
Name "DBufferMesh_S" // Name is not used
Tags{"LightMode" = "DBufferMesh_S"} // Smoothness
Tags{"LightMode" = "DBufferMesh_S"} // Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

Pass
{
Name "DBufferMesh_MS" // Name is not used
Tags{"LightMode" = "DBufferMesh_MS"} // Smoothness and Metalness
Tags{"LightMode" = "DBufferMesh_MS"} // Smoothness and Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_AOS" // Name is not used
Tags{"LightMode" = "DBufferMesh_AOS"} // AO + Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_MAOS" // Name is not used
Tags{"LightMode" = "DBufferMesh_MAOS"} // Metalness AO and Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

3
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProjectorComponent.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
#if UNITY_EDITOR
[CanEditMultipleObjects]
#endif
public class DecalProjectorComponent : MonoBehaviour
{
public Material m_Material = null;

6
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl


#endif
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
#endif
#if defined(UNITY_MATERIAL_STACKLIT)
surfaceData.perceptualSmoothnessA = surfaceData.perceptualSmoothnessA * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
surfaceData.perceptualSmoothnessB = surfaceData.perceptualSmoothnessB * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
surfaceData.coatPerceptualSmoothness = surfaceData.coatPerceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
#else
#endif
}
}
}

7
com.unity.render-pipelines.high-definition/HDRP/Material/GBufferManager.cs


public override void CreateBuffers()
{
RenderTextureFormat[] rtFormat;
bool[] sRGBFlags;
m_DeferredMaterial.GetMaterialGBufferDescription(m_asset, out rtFormat, out sRGBFlags, out m_GBufferUsage);
bool[] sRGBFlags;
bool[] enableWrite;
m_DeferredMaterial.GetMaterialGBufferDescription(m_asset, out rtFormat, out sRGBFlags, out m_GBufferUsage, out enableWrite);
m_RTs[gbufferIndex] = RTHandles.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point, name: string.Format("GBuffer{0}", gbufferIndex));
m_RTs[gbufferIndex] = RTHandles.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point, name: string.Format("GBuffer{0}", gbufferIndex), enableRandomWrite: enableWrite[gbufferIndex]);
m_RTIDs[gbufferIndex] = m_RTs[gbufferIndex].nameID;
m_TextureShaderIDs[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex];

9
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs


return gBufferCount;
}
public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage)
public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage, out bool[] enableWrite)
{
int gBufferCount;
bool supportShadowMask;

RTFormat = new RenderTextureFormat[gBufferCount];
sRGBFlag = new bool[gBufferCount];
gBufferUsage = new GBufferUsage[gBufferCount];
gBufferUsage = new GBufferUsage[gBufferCount];
enableWrite = new bool[gBufferCount];
enableWrite[0] = false;
enableWrite[1] = true; // normal buffer is used as RWTexture to composite decals in forward
enableWrite[2] = false;
enableWrite[3] = false;
int index = 4;

5
com.unity.render-pipelines.high-definition/HDRP/Material/RenderPipelineMaterial.cs


// GBuffer management
public virtual bool IsDefferedMaterial() { return false; }
public virtual int GetMaterialGBufferCount(HDRenderPipelineAsset asset) { return 0; }
public virtual void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage)
public virtual void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage, out bool[] enableWrite)
}
enableWrite = null;
}
// Regular interface
public virtual void Build(HDRenderPipelineAsset hdAsset) {}

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


[HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 7 // StencilMask.Lighting (fixed at compile time)
[HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 128 // StencilLightingUsage.RegularLighting (fixed at compile time)
[HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 128 // StencilMask.ObjectsVelocity (fixed at compile time)
[HideInInspector] _StencilDepthPrepassRef("_StencilDepthPrepassRef", Int) = 16
[HideInInspector] _StencilDepthPrepassWriteMask("_StencilDepthPrepassWriteMask", Int) = 16
// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0

Cull[_CullMode]
ZWrite On
Stencil
{
WriteMask[_StencilDepthPrepassWriteMask]
Ref[_StencilDepthPrepassRef]
Comp Always
Pass Replace
}
HLSLPROGRAM

5
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl


#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "HDRP/Material/BuiltinUtilities.hlsl"
#include "HDRP/Material/MaterialUtilities.hlsl"
#include "HDRP/Material/Decal/DecalUtilities.hlsl"
//-----------------------------------------------------------------------------
// Texture Mapping

surfaceData.coatNormalWS = SurfaceGradientResolveNormal(input.worldToTangent[2], coatGradient.xyz);
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
#if HAVE_DECALS
AddDecalContribution(posInput, surfaceData, alpha);
#endif
if ((_GeometricNormalFilteringEnabled + _TextureNormalFilteringEnabled) > 0.0)
{

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDCustomSamplerId.cs


GBuffer,
DBufferRender,
DBufferPrepareDrawData,
DBufferNormal,
DisplayDebugDecalsAtlas,
DisplayDebugViewMaterial,
DebugViewMaterialGBuffer,

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


int m_applyDistortionKernel;
Material m_CameraMotionVectorsMaterial;
Material m_DecalNormalBufferMaterial;
// Debug material
Material m_DebugViewMaterialGBuffer;

[Flags]
public enum StencilBitMask
{
Clear = 0, // 0x0
LightingMask = 7, // 0x7 - 3 bit
ObjectVelocity = 128, // 0x80 - 1 bit
All = 255 // 0xFF - 8 bit
Clear = 0, // 0x0
LightingMask = 7, // 0x7 - 3 bit
Decals = 8, // 0x8 - 1 bit
DecalsForwardOutputNormalBuffer = 16, // 0x10 - 1 bit
ObjectVelocity = 128, // 0x80 - 1 bit
All = 255 // 0xFF - 8 bit
}
RenderStateBlock m_DepthStateOpaque;

m_CopyStencilForNoLighting.SetInt(HDShaderIDs._StencilRef, (int)StencilLightingUsage.NoLighting);
m_CopyStencilForNoLighting.SetInt(HDShaderIDs._StencilMask, (int)StencilBitMask.LightingMask);
m_CameraMotionVectorsMaterial = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.cameraMotionVectors);
m_DecalNormalBufferMaterial = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.decalNormalBuffer);
m_CopyDepth = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.copyDepthBuffer);

CoreUtils.Destroy(m_CopyStencilForNoLighting);
CoreUtils.Destroy(m_CameraMotionVectorsMaterial);
CoreUtils.Destroy(m_DecalNormalBufferMaterial);
CoreUtils.Destroy(m_DebugViewMaterialGBuffer);
CoreUtils.Destroy(m_DebugViewMaterialGBufferShadowMask);

// We can now bind the normal buffer to be use by any effect
m_NormalBufferManager.BindNormalBuffers(cmd);
if (!hdCamera.frameSettings.enableMSAA) // MSAA not supported
{
using (new ProfilingSample(cmd, "DBuffer Normal (forward)", CustomSamplerId.DBufferNormal.GetSampler()))
{
int stencilMask;
int stencilRef;
if (hdCamera.frameSettings.enableForwardRenderingOnly) // in forward rendering all pixels that decals wrote into have to be composited
{
stencilMask = (int)StencilBitMask.Decals;
stencilRef = (int)StencilBitMask.Decals;
}
else // in deferred rendering only pixels affected by both forward materials and decals need to be composited
{
stencilMask = (int)StencilBitMask.Decals | (int)StencilBitMask.DecalsForwardOutputNormalBuffer;
stencilRef = (int)StencilBitMask.Decals | (int)StencilBitMask.DecalsForwardOutputNormalBuffer;
}
m_DecalNormalBufferMaterial.SetInt(HDShaderIDs._DecalNormalBufferStencilReadMask, stencilMask);
m_DecalNormalBufferMaterial.SetInt(HDShaderIDs._DecalNormalBufferStencilRef, stencilRef);
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraDepthStencilBuffer);
cmd.SetRandomWriteTarget(1, m_NormalBufferManager.GetNormalBuffer(0));
cmd.DrawProcedural(Matrix4x4.identity, m_DecalNormalBufferMaterial, 0, MeshTopology.Triangles, 3, 1);
cmd.ClearRandomWriteTargets();
}
}
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
CopyDepthBufferIfNeeded(cmd);

2
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _DecalIndexShift = Shader.PropertyToID("_DecalIndexShift");
public static readonly int _DecalCount = Shader.PropertyToID("_DecalCount");
public static readonly int _DecalDatas = Shader.PropertyToID("_DecalDatas");
public static readonly int _DecalNormalBufferStencilReadMask = Shader.PropertyToID("_DecalNormalBufferStencilReadMask");
public static readonly int _DecalNormalBufferStencilRef = Shader.PropertyToID("_DecalNormalBufferStencilRef");
public static readonly int _WorldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos");
public static readonly int _ViewMatrix = Shader.PropertyToID("_ViewMatrix");

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


public Shader shadowClearShader;
public ComputeShader shadowBlurMoments;
public Shader debugShadowMapShader;
// Decal
public Shader decalNormalBuffer;
#if UNITY_EDITOR
public void UpgradeIfNeeded()

shadowClearShader = Load<Shader>(CorePath + "Shadow/ShadowClear.shader");
shadowBlurMoments = Load<ComputeShader>(CorePath + "Shadow/ShadowBlurMoments.compute");
debugShadowMapShader = Load<Shader>(CorePath + "Shadow/DebugDisplayShadowMap.shader");
// decal
decalNormalBuffer = Load<Shader>(HDRenderPipelinePath + "Material/Decal/DecalNormalBuffer.shader");
}
#endif
}

87
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader


Shader "Hidden/HDRenderPipeline/Material/Decal/DecalNormalBuffer"
{
Properties
{
// Stencil state
[HideInInspector] _DecalNormalBufferStencilRef("_DecalNormalBufferStencilRef", Int) = 0 // set at runtime
[HideInInspector] _DecalNormalBufferStencilReadMask("_DecalNormalBufferStencilReadMask", Int) = 0 // set at runtime
}
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../../ShaderVariables.hlsl"
#include "Decal.hlsl"
#include "../NormalBuffer.hlsl"
RW_TEXTURE2D(float4, _NormalBuffer);
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
DECLARE_DBUFFER_TEXTURE(_DBufferTexture);
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
float4 FragNearest(Varyings input) : SV_Target
{
FETCH_DBUFFER(DBuffer, _DBufferTexture, input.texcoord * _ScreenSize.xy);
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);
float4 GBufferNormal = _NormalBuffer[input.texcoord * _ScreenSize.xy];
NormalData normalData;
DecodeFromNormalBuffer(GBufferNormal, uint2(0, 0), normalData);
normalData.normalWS.xyz = normalize(normalData.normalWS.xyz * decalSurfaceData.normalWS.w + decalSurfaceData.normalWS.xyz);
EncodeIntoNormalBuffer(normalData, uint2(0, 0), GBufferNormal);
_NormalBuffer[input.texcoord * _ScreenSize.xy] = GBufferNormal;
return float4(0, 0, 0, 0); // normal buffer is written into as a RWTexture
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" }
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off
Stencil
{
ReadMask[_DecalNormalBufferStencilReadMask]
Ref[_DecalNormalBufferStencilRef]
Comp Equal
Pass Zero // doesn't really matter, but clear to 0 for debugging
}
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearest
ENDHLSL
}
}
Fallback Off
}

9
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader.meta


fileFormatVersion: 2
guid: fd532bf1795188c4daaa66ea798b8b0a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存