浏览代码

cleaned up gecal group culling code, mask blend uses total material blend

/prototype-decals
Paul Melamed 7 年前
当前提交
a1129802
共有 5 个文件被更改,包括 93 次插入67 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalProjectorComponent.cs
  2. 78
      ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
  3. 74
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset
  4. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
  5. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl

2
ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalProjectorComponent.cs


{
DrawGizmo(true);
// if this object is selected there is a chance the transform was changed so update culling info
DecalSystem.instance.UpdateCulling(this);
DecalSystem.instance.UpdateBoundingSphere(this);
}
public void UpdatePropertyBlock(Vector3 cameraPos)

78
ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs


return m_Instance;
}
}
internal List<DecalProjectorComponent> m_Decals = new List<DecalProjectorComponent>();
private BoundingSphere[] m_BoundingSpheres;
private int[] m_ResultIndices;
private const int kDecalBlockSize = 128;
private BoundingSphere[] m_BoundingSpheres = new BoundingSphere[kDecalBlockSize];
private DecalProjectorComponent[] m_Decals = new DecalProjectorComponent[kDecalBlockSize];
private int[] m_ResultIndices = new int[kDecalBlockSize];
private int m_DecalsCount = 0;
public DecalSystem()
{

// updates bounding spheres for all decals, also refreshes cull indices
void UpdateCulling()
// update bounding sphere for a single decal
public void UpdateBoundingSphere(DecalProjectorComponent decal)
m_BoundingSpheres = new BoundingSphere[m_Decals.Count];
m_ResultIndices = new int[m_Decals.Count];
int cullIndex = 0;
foreach (var decal in m_Decals)
{
decal.CullIndex = cullIndex;
m_BoundingSpheres[cullIndex] = CoreUtils.GetDecalMeshBoundingSphere(decal.transform.localToWorldMatrix);
cullIndex++;
}
m_BoundingSpheres[decal.CullIndex] = CoreUtils.GetDecalMeshBoundingSphere(decal.transform.localToWorldMatrix);
// update bounding sphere for a single decal
public void UpdateCulling(DecalProjectorComponent decal)
public void AddDecal(DecalProjectorComponent decal)
int cullIndex = decal.CullIndex;
m_BoundingSpheres[cullIndex] = CoreUtils.GetDecalMeshBoundingSphere(decal.transform.localToWorldMatrix);
}
if (decal.CullIndex != DecalProjectorComponent.kInvalidIndex) //do not add the same decal more than once
return;
public void AddDecal(DecalProjectorComponent d)
{
if (d.CullIndex != DecalProjectorComponent.kInvalidIndex)
// increase array size if no space left
if(m_DecalsCount == m_Decals.Length)
RemoveDecal(d);
}
d.CullIndex = m_Decals.Count;
m_Decals.Add(d);
UpdateCulling();
DecalProjectorComponent[] newDecals = new DecalProjectorComponent[m_DecalsCount + kDecalBlockSize];
BoundingSphere[] newSpheres = new BoundingSphere[m_DecalsCount + kDecalBlockSize];
m_ResultIndices = new int[m_DecalsCount + kDecalBlockSize];
m_Decals.CopyTo(newDecals, 0);
m_BoundingSpheres.CopyTo(newSpheres, 0);
m_Decals = newDecals;
m_BoundingSpheres = newSpheres;
}
m_Decals[m_DecalsCount] = decal;
m_Decals[m_DecalsCount].CullIndex = m_DecalsCount;
UpdateBoundingSphere(m_Decals[m_DecalsCount]);
m_DecalsCount++;
public void RemoveDecal(DecalProjectorComponent d)
public void RemoveDecal(DecalProjectorComponent decal)
m_Decals.Remove(d);
UpdateCulling();
if (decal.CullIndex == DecalProjectorComponent.kInvalidIndex) //do not remove decal that has not been added
return;
int removeAtIndex = decal.CullIndex;
// replace with last decal in the list and update index
m_Decals[removeAtIndex] = m_Decals[m_DecalsCount - 1]; // move the last decal in list
m_Decals[removeAtIndex].CullIndex = removeAtIndex;
m_Decals[m_DecalsCount - 1] = null;
// update the bounding spheres array
m_BoundingSpheres[removeAtIndex] = m_BoundingSpheres[m_DecalsCount - 1];
m_DecalsCount--;
decal.CullIndex = DecalProjectorComponent.kInvalidIndex;
m_NumResults = 0;
m_CullingGroup.SetBoundingSpheres(m_BoundingSpheres);
m_CullingGroup.SetBoundingSpheres(m_BoundingSpheres);
m_CullingGroup.SetBoundingSphereCount(m_DecalsCount);
}
public int QueryCullResults()

74
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset


m_EditorClassIdentifier:
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7,
type: 2}
defaultFrameSettings:
lightingSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSSSAndTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
renderSettings:
enableForwardRenderingOnly: 1
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrePass: 1
enableMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostPass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 0
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableMaterialDisplayDebug: 0
enableShadowMask: 0
serializedFrameSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSSSAndTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrePass: 1
enableMotionVectors: 1
enableObjectMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostPass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 0
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableShadowMask: 0
lightLoopSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1

enableBigTilePrepass: 1
isFptlEnabled: 1
m_globalFrameSettings: {fileID: 0}
m_sssSettings: {fileID: 0}
renderPipelineSettings:
supportShadowMask: 1
supportSSR: 1
supportSSAO: 1
supportSSSAndTransmission: 1
supportDBuffer: 1
supportMSAA: 0
supportAsyncCompute: 0
lightLoopSettings:
spotCookieSize: 128
cookieTexArraySize: 16
pointCookieSize: 512
cubeCookieTexArraySize: 16
reflectionProbeCacheSize: 128
reflectionCubemapSize: 128
reflectionCacheCompressed: 0
shadowInitParams:
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096
sssSettings: {fileID: 0}
m_DefaultDiffuseMaterial: {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17,
type: 2}
m_DefaultShader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}

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


#endif
#if _MASKMAP
surfaceData.mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, texCoordDS.xy);
surfaceData.normalWS.w *= surfaceData.mask.z;
surfaceData.mask.z *= totalBlend;
surfaceData.mask.z = totalBlend;
#endif
}

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


void AddDecalContribution(uint2 unPositionSS, inout SurfaceData surfaceData)
{
// Currently disabled
#if 1
FETCH_DBUFFER(DBuffer, _DBufferTexture, unPositionSS);
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);

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);
#endif
}
正在加载...
取消
保存