浏览代码

adressed PR comments

moved DecalProjector transform update check to LateUpdate so it works correctly when attached to bones.
/main
Paul Melamed 6 年前
当前提交
1fc5aacc
共有 12 个文件被更改,包括 86 次插入98 次删除
  1. 22
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  2. 22
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs
  3. 112
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.hlsl
  4. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  5. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProjectorComponent.cs
  6. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl
  7. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader
  8. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  9. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader
  10. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader
  11. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  12. 9
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs

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


Smoothness,
AO
}
enum MaskBlendFlags
{
Metal = 1 << 0,
Smoothness = 1 << 1,
AO = 1 << 2,
}
protected string[] blendModeNames = Enum.GetNames(typeof(BlendMode));
protected MaterialProperty baseColorMap = new MaterialProperty();

protected MaterialProperty maskBlendSrc = new MaterialProperty();
protected const string kMaskBlendSrc = "_MaskBlendSrc";
protected MaterialProperty maskBlendMode2 = new MaterialProperty();
protected const string kMaskBlendMode2 = "_MaskBlendMode2";
protected MaterialProperty maskBlendMode = new MaterialProperty();
protected const string kMaskBlendMode = "_MaskBlendMode";

normalBlendSrc = FindProperty(kNormalBlendSrc, props);
maskBlendSrc = FindProperty(kMaskBlendSrc, props);
maskBlendMode = FindProperty(kMaskBlendMode, props);
maskBlendMode2 = FindProperty(kMaskBlendMode2, props);
// always instanced
SerializedProperty instancing = m_MaterialEditor.serializedObject.FindProperty("m_EnableInstancingVariants");

float normalBlendSrcValue = normalBlendSrc.floatValue;
float maskBlendSrcValue = maskBlendSrc.floatValue;
float maskBlendModeValue = maskBlendMode.floatValue;
float maskBlendModeValue2 = maskBlendMode2.floatValue;
MaskBlendFlags maskBlendFlags = (MaskBlendFlags) maskBlendModeValue2;
HDRenderPipelineAsset hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
bool perChannelMask = hdrp.renderPipelineSettings.decalSettings.perChannelMask;

normalBlendSrcValue = EditorGUILayout.Popup( "Normal blend source", (int)normalBlendSrcValue, blendSourceNames);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
maskBlendSrcValue = EditorGUILayout.Popup( "Mask blend source", (int)maskBlendSrcValue, blendSourceNames);
EditorGUILayout.LabelField("Individual mask map channel blending mode can be enabled/disabled in pipeline asset.");
EditorGUILayout.LabelField("Warning!!! Enabling this feature incurs a performance cost.");
EditorGUILayout.HelpBox("Individual mask map channel blending mode can be enabled/disabled in pipeline asset.\nEnabling this feature incurs a performance cost.", MessageType.Warning);
maskBlendModeValue = EditorGUILayout.Popup( "Mask blend mode", (int)maskBlendModeValue, blendModeNames);
maskBlendModeValue = EditorGUILayout.Popup( "Mask blend mode", (int)maskBlendModeValue, blendModeNames);
maskBlendFlags = (MaskBlendFlags)EditorGUILayout.EnumFlagsField( "Mask blend mode", maskBlendFlags);
}
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
EditorGUI.indentLevel--;

normalBlendSrc.floatValue = normalBlendSrcValue;
maskBlendSrc.floatValue = maskBlendSrcValue;
maskBlendMode.floatValue = maskBlendModeValue;
maskBlendMode2.floatValue = (float) maskBlendFlags;
foreach (var obj in m_MaterialEditor.targets)
SetupMaterialKeywordsAndPassInternal((Material)obj);
}

22
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs


RTHandles.Release(m_HTile);
}
public void ClearTargets(CommandBuffer cmd, HDCamera camera)
public void ClearAndSetTargets(CommandBuffer cmd, HDCamera camera, bool rtCount4, RTHandleSystem.RTHandle cameraDepthStencilBuffer)
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[rtCount4 ? 4 :3];
// this clears the targets
Color clearColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
Color clearColorNormal = new Color(0.5f, 0.5f, 0.5f, 1.0f); // for normals 0.5 is neutral
Color clearColorAOSBlend = new Color(1.0f, 1.0f, 1.0f, 1.0f);

HDUtils.SetRenderTarget(cmd, camera, m_RTs[3], ClearFlag.Color, clearColorAOSBlend);
// names IDs have to be set every frame, because they can change
RTIDs[0] = m_RTs[0].nameID;
RTIDs[1] = m_RTs[1].nameID;
RTIDs[2] = m_RTs[2].nameID;
if (rtCount4)
{
HDUtils.SetRenderTarget(cmd, camera, m_RTs[3], ClearFlag.Color, clearColorAOSBlend);
RTIDs[3] = m_RTs[3].nameID;
}
}
public void SetHTile(int bindSlot, CommandBuffer cmd)
{
cmd.SetRandomWriteTarget(bindSlot, m_HTile);
// this actually sets the MRTs and HTile RWTexture, this is done separately because we do not have an api to clear MRTs to different colors
HDUtils.SetRenderTarget(cmd, camera, RTIDs, cameraDepthStencilBuffer); // do not clear anymore
cmd.SetRandomWriteTarget(rtCount4 ? 4 : 3, m_HTile);
}
public void UnSetHTile(CommandBuffer cmd)

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


#define DBufferType0 float4
#define DBufferType1 float4
#define DBufferType2 float4
#define DBufferType3 float2
#ifdef DBUFFERMATERIAL_COUNT
#if DBUFFERMATERIAL_COUNT == 1
#define OUTPUT_DBUFFER(NAME) \
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0
#define DECLARE_DBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0));
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2);
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0))
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), DECAL_SURFACE_DATA)
#elif DBUFFERMATERIAL_COUNT == 2
#ifdef _DECALS_4RT
#define DBufferType3 float2
#define OUTPUT_DBUFFER(NAME) \
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1
#define OUTPUT_DBUFFER(NAME) \
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out DBufferType2 MERGE_NAME(NAME, 2) : SV_Target2, \
out DBufferType3 MERGE_NAME(NAME, 3) : SV_Target3
#define DECLARE_DBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1));
#define DECLARE_DBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2)); \
TEXTURE2D(MERGE_NAME(NAME, 3));
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2);
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
DBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2); \
DBufferType3 MERGE_NAME(NAME, 3) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 3), unCoord2);
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1))
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), DECAL_SURFACE_DATA)
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), MERGE_NAME(NAME,3))
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), MERGE_NAME(NAME,3), DECAL_SURFACE_DATA)
#elif DBUFFERMATERIAL_COUNT == 3
#else
#define OUTPUT_DBUFFER(NAME) \
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out DBufferType2 MERGE_NAME(NAME, 2) : SV_Target2
#define OUTPUT_DBUFFER(NAME) \
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out DBufferType2 MERGE_NAME(NAME, 2) : SV_Target2
#define DECLARE_DBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2));
#define DECLARE_DBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2));
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
DBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2);
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
DBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2);
#elif DBUFFERMATERIAL_COUNT == 4
#define OUTPUT_DBUFFER(NAME) \
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out DBufferType2 MERGE_NAME(NAME, 2) : SV_Target2, \
out DBufferType3 MERGE_NAME(NAME, 3) : SV_Target3
#define DECLARE_DBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2)); \
TEXTURE2D(MERGE_NAME(NAME, 3));
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
DBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2); \
DBufferType3 MERGE_NAME(NAME, 3) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 3), unCoord2);
#ifdef _DECALS_PER_CHANNEL_MASK
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), MERGE_NAME(NAME,3))
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), MERGE_NAME(NAME,3), DECAL_SURFACE_DATA)
#else
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), DECAL_SURFACE_DATA)
#endif
#endif // #ifdef DBUFFERMATERIAL_COUNT
CBUFFER_START(UnityDecalParameters)
uint _EnableDBuffer;

, out DBufferType0 outDBuffer0
, out DBufferType1 outDBuffer1
, out DBufferType2 outDBuffer2
#ifdef _DECALS_PER_CHANNEL_MASK
#ifdef _DECALS_4RT
, out DBufferType3 outDBuffer3
#endif
)

outDBuffer2 = surfaceData.mask;
#ifdef _DECALS_PER_CHANNEL_MASK
#ifdef _DECALS_4RT
outDBuffer3 = surfaceData.MAOSBlend;
#endif
}

, DBufferType1 inDBuffer1
, DBufferType2 inDBuffer2
#ifdef _DECALS_PER_CHANNEL_MASK
#ifdef _DECALS_4RT
, DBufferType3 inDBuffer3
#endif
, out DecalSurfaceData surfaceData

surfaceData.normalWS.xyz = inDBuffer1.xyz * 2.0f - 1.0f;
surfaceData.normalWS.w = inDBuffer1.w;
surfaceData.mask = inDBuffer2;
#ifdef _DECALS_PER_CHANNEL_MASK
#ifdef _DECALS_4RT
surfaceData.MAOSBlend = inDBuffer3;
#else
surfaceData.MAOSBlend = float2(surfaceData.mask.w, surfaceData.mask.w);

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


[HideInInspector] _NormalBlendSrc("_NormalBlendSrc", Float) = 0.0
[HideInInspector] _MaskBlendSrc("_MaskBlendSrc", Float) = 1.0
[HideInInspector] _MaskBlendMode("_MaskBlendMode", Float) = 0.0
[HideInInspector] _MaskBlendMode2("_MaskBlendMode2", Float) = 0.0
}
HLSLINCLUDE

#pragma shader_feature _MASK_BLEND_SRC_B
#pragma multi_compile_instancing
#pragma multi_compile _ _DECALS_PER_CHANNEL_MASK
#pragma multi_compile _ _DECALS_4RT
//-------------------------------------------------------------------------------------
// Define
//-------------------------------------------------------------------------------------

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


}
}
public void Update()
public void LateUpdate()
{
if (m_Handle != null)
{

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


DBuffer0 = float4(0.0f, 0.0f, 0.0f, 1.0f);
DBuffer1 = float4(0.5f, 0.5f, 0.5f, 1.0f);
DBuffer2 = float4(0.0f, 0.0f, 0.0f, 1.0f);
#ifdef _DECALS_4RT
#else
float2 DBuffer3 = float2(1.0f, 1.0f);
#endif
#ifdef LIGHTLOOP_TILE_PASS
GetCountAndStart(posInput, LIGHTCATEGORY_DECAL, decalStart, decalCount);

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


#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_PER_CHANNEL_MASK
#pragma multi_compile _ _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

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


#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_PER_CHANNEL_MASK
#pragma multi_compile _ _DECALS_4RT
// enable GPU instancing
#pragma multi_compile_instancing

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


#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_PER_CHANNEL_MASK
#pragma multi_compile _ _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

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


#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_PER_CHANNEL_MASK
#pragma multi_compile _ _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

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


#pragma shader_feature _STACKLIT_DEBUG
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_PER_CHANNEL_MASK
#pragma multi_compile _ _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

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


// We need to copy depth buffer texture if we want to bind it at this stage
CopyDepthBufferIfNeeded(cmd);
bool rtCount4 = m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask;
m_DbufferManager.ClearTargets(cmd, hdCamera);
HDUtils.SetRenderTarget(cmd, hdCamera, m_DbufferManager.GetBuffersRTI(), m_CameraDepthStencilBuffer); // do not clear anymore
m_DbufferManager.SetHTile(m_DbufferManager.bufferCount, cmd);
m_DbufferManager.ClearAndSetTargets(cmd, hdCamera, rtCount4, m_CameraDepthStencilBuffer);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();

sorting = { flags = SortFlags.CommonOpaque }
};
if(m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask)
if(rtCount4)
{
drawSettings.SetShaderPassName(0, HDShaderPassNames.s_MeshDecalsName);
drawSettings.SetShaderPassName(1, HDShaderPassNames.s_MeshDecalsMSName);

renderQueueRange = HDRenderQueue.k_RenderQueue_AllOpaque
};
CoreUtils.SetKeyword(cmd, "_DECALS_PER_CHANNEL_MASK", m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask);
CoreUtils.SetKeyword(cmd, "_DECALS_4RT", m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask);
renderContext.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, filterRenderersSettings);
DecalSystem.instance.RenderIntoDBuffer(cmd);

正在加载...
取消
保存