浏览代码

Albedo contribution flag works on transparency

/main
Paul Melamed 7 年前
当前提交
f961e596
共有 5 个文件被更改,包括 32 次插入18 次删除
  1. 14
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs
  2. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalSystem.cs
  3. 9
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl
  4. 10
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  5. 14
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/DefaultHDMaterial.mat

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


sRGBFlags = m_sRGBFlags;
}
}
// normalToWorld.m03 - total blend factor
// normalToWorld.m13 - diffuse texture index in atlas
// normalToWorld.m23 - normal texture index in atlas
// normalToWorld.m33 - mask texture index in atlas
// normal to world only uses 3x3 for actual matrix so some data is packed in the unused space
// blend:
// float decalBlend = decalData.normalToWorld[0][3];
// albedo contribution on/off:
// float albedoContribution = decalData.normalToWorld[1][3];
// tiling:
// float2 uvScale = float2(decalData.normalToWorld[3][0], decalData.normalToWorld[3][1]);
// float2 uvBias = float2(decalData.normalToWorld[3][2], decalData.normalToWorld[3][3]);
[GenerateHLSL]
public struct DecalData
{

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


m_Normal.m_Texture = m_Material.GetTexture("_NormalMap");
m_Mask.m_Texture = m_Material.GetTexture("_MaskMap");
m_Blend = m_Material.GetFloat("_DecalBlend");
m_AlbedoContribution = m_Material.GetFloat("_AlbedoMode");
}
public DecalSet(Material material)

normalToWorldBatch[instanceCount] = m_CachedNormalToWorld[decalIndex];
float fadeFactor = Mathf.Clamp((cullDistance - distanceToDecal) / (cullDistance * (1.0f - m_CachedDrawDistances[decalIndex].y)), 0.0f, 1.0f);
normalToWorldBatch[instanceCount].m03 = fadeFactor * m_Blend; // vector3 rotation matrix so bottom row and last column can be used for other data to save space
normalToWorldBatch[instanceCount].m13 = m_AlbedoContribution;
normalToWorldBatch[instanceCount].SetRow(3, m_CachedUVScaleBias[decalIndex]);
// clustered forward data

private Vector4[] m_CachedUVScaleBias = new Vector4[kDecalBlockSize]; // xy - scale, zw bias
private Material m_Material;
private float m_Blend = 0;
private float m_AlbedoContribution = 0;
TextureScaleBias m_Diffuse = new TextureScaleBias();
TextureScaleBias m_Normal = new TextureScaleBias();

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


if((decalData.diffuseScaleBias.x > 0) && (decalData.diffuseScaleBias.y > 0))
{
ApplyBlendDiffuse(DBuffer0, mask, sampleDiffuse, DBUFFERHTILEBIT_DIFFUSE, decalBlend, lodDiffuse);
alpha = alpha < decalBlend ? decalBlend : alpha; // use decal alpha if it is higher than transparent alpha
ApplyBlendDiffuse(DBuffer0, mask, sampleDiffuse, DBUFFERHTILEBIT_DIFFUSE, decalBlend, lodDiffuse);
float albedoContribution = decalData.normalToWorld[1][3];
if (albedoContribution == 0.0f)
{
mask = 0; // diffuse will not get modified
}
alpha = alpha < decalBlend ? decalBlend : alpha; // use decal alpha if it is higher than transparent alpha
}
if ((decalData.normalScaleBias.x > 0) && (decalData.normalScaleBias.y > 0))

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


if (hdCamera.frameSettings.enableDBuffer)
{
DecalSystem.instance.EndCull();
//m_DbufferManager.vsibleDecalCount = DecalSystem.m_DecalsVisibleThisFrame;
m_DbufferManager.EnableDBUffer = true;
m_DbufferManager.EnableDBUffer = true; // mesh decals are renderers managed by c++ runtime and we have no way to query if any are visible, so set to true
DecalSystem.instance.UpdateCachedMaterialData(); // textures, alpha or fade distances could've changed
DecalSystem.instance.CreateDrawData(); // prepare data is separate from draw
DecalSystem.instance.UpdateTextureAtlas(cmd); // as this is only used for transparent pass, would've been nice not to have to do this if no transparent renderers are visible, needs to happen after CreateDrawData

ClearBuffers(hdCamera, cmd);
// TODO: Add stereo occlusion mask
bool forcePrepassForDecals = m_DbufferManager.EnableDBUffer;
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, forcePrepassForDecals);
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, m_DbufferManager.EnableDBUffer);
// This will bind the depth buffer if needed for DBuffer)
RenderDBuffer(hdCamera, cmd, renderContext, m_CullResults);

else
{
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraColorBuffer, m_CameraDepthStencilBuffer);
//if ((hdCamera.frameSettings.enableDBuffer) && (DecalSystem.m_DecalsVisibleThisFrame > 0)) // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered
if (hdCamera.frameSettings.enableDBuffer)
if ((hdCamera.frameSettings.enableDBuffer) && (DecalSystem.m_DecalsVisibleThisFrame > 0)) // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered
{
DecalSystem.instance.SetAtlas(cmd); // for clustered decals
}

14
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/DefaultHDMaterial.mat


Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: DefaultHDMaterial
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}

- _EnableBlendModeAccurateLighting: 1
- _EnableBlendModePreserveSpecularLighting: 1
- _EnableFogOnTransparent: 1
- _EnableGeometricSpecularAA: 0
- _EnableMotionVectorForVertexAnimation: 0
- _EnablePerPixelDisplacement: 0
- _EnableSpecularOcclusion: 0

- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _HdrpVersion: 1
- _HeightAmplitude: 0.01
- _HeightCenter: 0.5
- _HeightMapParametrization: 1

- _Parallax: 0.02
- _PreRefractionPass: 0
- _RefractionMode: 0
- _RefractionModel: 0
- _SSRefractionProjectionModel: 0
- _SSSAndTransmissionType: 0
- _ShiverDirectionality: 0.5
- _ShiverDrag: 0.2

- _SmoothnessTextureChannel: 0
- _SpecularAAScreenSpaceVariance: 0.1
- _SpecularAAThreshold: 0.2
- _SpecularHighlights: 1
- _SrcBlend: 1
- _StencilRef: 2

- _ZTestModeDistortion: 8
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.72794116, g: 0.72794116, b: 0.72794116, a: 1}
- _Color: {r: 0.72794116, g: 0.72794116, b: 0.72794116, a: 1}
- _BaseColor: {r: 0.16078432, g: 0.16078432, b: 0.16078432, a: 1}
- _Color: {r: 0.16078427, g: 0.16078427, b: 0.16078427, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
- _InvPrimScale: {r: 1, g: 1, b: 0, a: 0}
- _IridescenceThicknessRemap: {r: 0, g: 1, b: 0, a: 0}

正在加载...
取消
保存