浏览代码

Clean up decal culling. New global shader variable to skip decal contribution when none are visible.

/prototype-decals
Paul Melamed 7 年前
当前提交
57775e99
共有 6 个文件被更改,包括 53 次插入16 次删除
  1. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs
  2. 19
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset.meta
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  5. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.hlsl
  6. 19
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalUtilities.hlsl

24
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs


}
}
Mesh m_DecalMesh;
CullingGroup m_CullingGroup;
Mesh m_DecalMesh = null;
CullingGroup m_CullingGroup = null;
private const int kDecalBlockSize = 128;
private BoundingSphere[] m_BoundingSpheres = new BoundingSphere[kDecalBlockSize];
private DecalProjectorComponent[] m_Decals = new DecalProjectorComponent[kDecalBlockSize];

decal.CullIndex = DecalProjectorComponent.kInvalidIndex;
}
public void Cull(Camera camera)
public void BeginCull(Camera camera)
if (m_CullingGroup != null)
{
Debug.LogError("Begin/EndCull() called out of sequence for decal projectors.");
}
m_NumResults = 0;
m_CullingGroup = new CullingGroup();
m_CullingGroup.targetCamera = camera;

cmd.DrawMesh(m_DecalMesh, m_Decals[decalIndex].transform.localToWorldMatrix, m_Decals[decalIndex].m_Material, 0, 0,
m_Decals[decalIndex].GetPropertyBlock());
}
}
m_CullingGroup.Dispose();
m_CullingGroup = null;
public void EndCull()
{
if (m_CullingGroup == null)
{
Debug.LogError("Begin/EndCull() called out of sequence for decal projectors.");
}
else
{
m_CullingGroup.Dispose();
m_CullingGroup = null;
}
}
}
}

19
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


public const int k_MaxDbuffer = 4;
public int dbufferCount { get; set; }
public int vsibleDecalCount { get; set; }
RenderTargetIdentifier[] m_ColorMRTs;
RenderTargetIdentifier[] m_RTIDs = new RenderTargetIdentifier[k_MaxDbuffer];

}
return m_ColorMRTs;
}
public void PushGlobalParams(CommandBuffer cmd)
{
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, vsibleDecalCount > 0 ? 1 : 0);
}
}

hdCamera.SetupGlobalParams(cmd);
m_SSSBufferManager.PushGlobalParams(cmd, sssParameters, m_FrameSettings);
m_DbufferManager.PushGlobalParams(cmd);
}
}

#endif
// decal system needs to be updated with current camera
if (m_FrameSettings.enableDBuffer)
DecalSystem.instance.Cull(camera);
DecalSystem.instance.BeginCull(camera);
}
m_DbufferManager.vsibleDecalCount = 0;
if (m_FrameSettings.enableDBuffer)
{
m_DbufferManager.vsibleDecalCount = DecalSystem.instance.QueryCullResults();
DecalSystem.instance.EndCull();
}
var postProcessLayer = camera.GetComponent<PostProcessLayer>();

InitAndClearBuffer(hdCamera, enableBakeShadowMask, cmd);
bool forcePrepassForDecals = m_FrameSettings.enableDBuffer && (DecalSystem.instance.QueryCullResults() > 0);
bool forcePrepassForDecals = m_DbufferManager.vsibleDecalCount > 0;
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, forcePrepassForDecals);
RenderObjectsVelocity(m_CullResults, hdCamera, renderContext, cmd);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset.meta


fileFormatVersion: 2
guid: 449281dd2b4fbee49b8397de0541ea3c
guid: 1fa8c4c8604deee4e99ff30888538ca5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _CameraFilteringBuffer = Shader.PropertyToID("_CameraFilteringTexture");
public static readonly int _IrradianceSource = Shader.PropertyToID("_IrradianceSource");
public static readonly int _EnableDBuffer = Shader.PropertyToID("_EnableDBuffer");
public static readonly int[] _GBufferTexture =
{
Shader.PropertyToID("_GBufferTexture0"),

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.hlsl


#endif
#endif // #ifdef DBUFFERMATERIAL_COUNT
CBUFFER_START(UnityDecalParameters)
uint _EnableDBuffer;
CBUFFER_END
// Must be in sync with RT declared in HDRenderPipeline.cs ::Rebuild
void EncodeIntoDBuffer( DecalSurfaceData surfaceData,

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


void AddDecalContribution(uint2 unPositionSS, inout SurfaceData surfaceData)
{
FETCH_DBUFFER(DBuffer, _DBufferTexture, unPositionSS);
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);
if(_EnableDBuffer)
{
FETCH_DBUFFER(DBuffer, _DBufferTexture, unPositionSS);
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);
surfaceData.baseColor.xyz = lerp(surfaceData.baseColor.xyz, decalSurfaceData.baseColor.xyz, decalSurfaceData.baseColor.w);
surfaceData.normalWS.xyz = normalize(lerp(surfaceData.normalWS.xyz, decalSurfaceData.normalWS.xyz, decalSurfaceData.normalWS.w));
surfaceData.metallic = lerp(surfaceData.metallic, decalSurfaceData.mask.x, decalSurfaceData.mask.z);
surfaceData.ambientOcclusion = lerp(surfaceData.ambientOcclusion, decalSurfaceData.mask.y, decalSurfaceData.mask.z);
surfaceData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothness, decalSurfaceData.mask.w, decalSurfaceData.mask.z);
surfaceData.baseColor.xyz = lerp(surfaceData.baseColor.xyz, decalSurfaceData.baseColor.xyz, decalSurfaceData.baseColor.w);
surfaceData.normalWS.xyz = normalize(lerp(surfaceData.normalWS.xyz, decalSurfaceData.normalWS.xyz, decalSurfaceData.normalWS.w));
surfaceData.metallic = lerp(surfaceData.metallic, decalSurfaceData.mask.x, decalSurfaceData.mask.z);
surfaceData.ambientOcclusion = lerp(surfaceData.ambientOcclusion, decalSurfaceData.mask.y, decalSurfaceData.mask.z);
surfaceData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothness, decalSurfaceData.mask.w, decalSurfaceData.mask.z);
}
}
正在加载...
取消
保存