浏览代码

Cleanup PR, add decal HTile mask defines

/main
Paul Melamed 7 年前
当前提交
afb8df01
共有 7 个文件被更改,包括 47 次插入15 次删除
  1. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs
  2. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs
  3. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  4. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs
  5. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalUtilities.hlsl
  7. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs


DecalSystem.instance.AddDecal(this);
m_OldMaterial = m_Material;
// notify the editor that material has changed so it can update the shader foldout
if (OnMaterialChange != null)
{
OnMaterialChange();

public bool IsValid()
{
// don't draw if no material or if material is the default decal material (empty)
var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
if ((hdrp != null) && (m_Material == hdrp.GetDefaultDecalMaterial()))
return false;
return true;
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs


// Create an instance of the MaterialEditor
m_DecalProjectorComponent = (DecalProjectorComponent)target;
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
m_DecalProjectorComponent.OnMaterialChange += new DecalProjectorComponent.OnMaterialChangeDelegate(this.OnMaterialChange);
m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
m_DecalProjectorComponent.OnMaterialChange -= new DecalProjectorComponent.OnMaterialChangeDelegate(this.OnMaterialChange);
m_DecalProjectorComponent.OnMaterialChange -= OnMaterialChange;
if (m_MaterialEditor != null)
{
// Draw the material's foldout and the material shader field
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
}
// Update material editor with the new material
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
}
public override void OnInspectorGUI()

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


cmd.SetRandomWriteTarget(bindSlot, m_HTile);
}
public void UnSetHTile(CommandBuffer cmd)
{
cmd.ClearRandomWriteTargets();
}
public void PushGlobalParams(CommandBuffer cmd)
{
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, vsibleDecalCount > 0 ? 1 : 0);

RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, HDRenderQueue.k_RenderQueue_AllOpaque, m_DepthStateOpaque);
}
}
if (m_FrameSettings.enableDBuffer)
{
m_DbufferManager.UnSetHTile(cmd);
}
}
}

CoreUtils.SetRenderTarget(cmd, m_DbufferManager.GetDBuffers(), m_CameraDepthStencilBufferRT); // do not clear anymore
m_DbufferManager.SetHTile(m_DbufferManager.dbufferCount, cmd);
DecalSystem.instance.Render(renderContext, camera, cmd);
cmd.ClearRandomWriteTargets();
m_DbufferManager.UnSetHTile(cmd);
}
}

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs


Count = 3
};
[GenerateHLSL(PackingRules.Exact)]
public enum DBufferHTileBit
{
Diffuse = 1,
Normal = 2,
Mask = 4
};
//-----------------------------------------------------------------------------
// DBuffer management
//-----------------------------------------------------------------------------

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl


//
#define DBUFFERMATERIAL_COUNT (3)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DBufferHTileBit: static fields
//
#define DBUFFERHTILEBIT_DIFFUSE (1)
#define DBUFFERHTILEBIT_NORMAL (2)
#define DBUFFERHTILEBIT_MASK (4)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Decal+DecalSurfaceData
// PackingRules = Exact
struct DecalSurfaceData

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalUtilities.hlsl


{
if(_EnableDBuffer)
{
// the code in the macros, gets moved inside the conditionals by the compiler
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html
if(mask & 1)
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html
if(mask & DBUFFERHTILEBIT_DIFFUSE)
if(mask & 2)
if(mask & DBUFFERHTILEBIT_NORMAL)
if(mask & 4)
if(mask & DBUFFERHTILEBIT_MASK)
{
surfaceData.metallic = surfaceData.metallic * decalSurfaceData.mask.w + decalSurfaceData.mask.x;
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.mask.w + decalSurfaceData.mask.y;

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl


DecalSurfaceData surfaceData;
float3x3 decalToWorld = (float3x3)UNITY_ACCESS_INSTANCED_PROP(matrix, normalToWorld);
GetSurfaceData(positionDS.xz, decalToWorld, surfaceData);
// have to do explicit test since compiler behavior is not defined for RW resources and discard instructions
mask = 1;
mask |= DBUFFERHTILEBIT_DIFFUSE;
mask |= 2;
mask |= DBUFFERHTILEBIT_NORMAL;
mask |= 4;
mask |= DBUFFERHTILEBIT_MASK;
#endif
uint oldVal = UnpackByte(_DecalHTile[posInput.positionSS.xy / 8]);
oldVal |= mask;

正在加载...
取消
保存