浏览代码

mesh decal working with an option to use albedo as mask only

decals are always on independent of cull results
/main
Paul Melamed 6 年前
当前提交
737f9f82
共有 5 个文件被更改,包括 37 次插入10 次删除
  1. 21
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  2. 10
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipeline.cs
  3. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs
  4. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  5. 10
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl

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


{
public static string InputsText = "Inputs";
public static GUIContent baseColorText = new GUIContent("Base Color + Blend", "Albedo (RGB) and Blend Factor (A)");
public static GUIContent baseColorText = new GUIContent("Albedo (RGB) and Blend Factor (A)", "Albedo (RGB) and Blend Factor (A)");
public static GUIContent baseColorText2 = new GUIContent("Blend Factor (A)", "Blend Factor (A)");
public static GUIContent BlendText = new GUIContent("Decal Blend", "Whole decal blend");
public static GUIContent AlbedoModeText = new GUIContent("Albedo contribution", "Base color + Blend, Blend only");
}
protected MaterialProperty baseColorMap = new MaterialProperty();

protected MaterialProperty decalBlend = new MaterialProperty();
protected const string kDecalBlend = "_DecalBlend";
protected MaterialProperty albedoMode = new MaterialProperty();
protected const string kAlbedoMode = "_AlbedoMode";
protected MaterialEditor m_MaterialEditor;

normalMap = FindProperty(kNormalMap, props);
maskMap = FindProperty(kMaskMap, props);
decalBlend = FindProperty(kDecalBlend, props);
albedoMode = FindProperty(kAlbedoMode, props);
// always instanced
SerializedProperty instancing = m_MaterialEditor.serializedObject.FindProperty("m_EnableInstancingVariants");
instancing.boolValue = true;

static public void SetupMaterialKeywordsAndPass(Material material)
{
CoreUtils.SetKeyword(material, "_ALBEDOCONTRIBUTION", material.GetFloat(kAlbedoMode) == 1.0f);
CoreUtils.SetKeyword(material, "_COLORMAP", material.GetTexture(kBaseColorMap));
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap));
CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));

EditorGUILayout.LabelField(Styles.InputsText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap);
m_MaterialEditor.ShaderProperty(albedoMode, Styles.AlbedoModeText);
if (material.GetFloat(kAlbedoMode) == 1.0f)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText2, baseColorMap);
}
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);

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


m_ReflectionProbeCullResults.Cull();
m_DbufferManager.vsibleDecalCount = 0;
m_DbufferManager.EnableDBUffer = false;
m_DbufferManager.vsibleDecalCount = DecalSystem.m_DecalsVisibleThisFrame;
//m_DbufferManager.vsibleDecalCount = DecalSystem.m_DecalsVisibleThisFrame;
m_DbufferManager.EnableDBUffer = 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

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

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) && (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)
{
DecalSystem.instance.SetAtlas(cmd); // for clustered decals
}

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


{
public class DBufferManager : MRTBufferManager
{
public int vsibleDecalCount { get; set; }
public bool EnableDBUffer { get; set; }
RTHandleSystem.RTHandle m_HTile;

{
if (hdCamera.frameSettings.enableDBuffer)
{
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, vsibleDecalCount > 0 ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, EnableDBUffer ? 1 : 0);
cmd.SetGlobalVector(HDShaderIDs._DecalAtlasResolution, new Vector2(HDUtils.hdrpSettings.decalSettings.atlasWidth, HDUtils.hdrpSettings.decalSettings.atlasHeight));
BindBufferAsTextures(cmd);
}

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


_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_MaskMap("MaskMap", 2D) = "white" {}
_DecalBlend("_DecalBlend", Range(0.0, 1.0)) = 0.5
[ToggleUI] _AlbedoMode("_AlbedoMode", Range(0.0, 1.0)) = 0.0
}
HLSLINCLUDE

#pragma shader_feature _COLORMAP
#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _ALBEDOCONTRIBUTION
#pragma multi_compile_instancing
//-------------------------------------------------------------------------------------

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


surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoordDS.xy);
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
surfaceData.HTileMask |= DBUFFERHTILEBIT_DIFFUSE;
#if _ALBEDOCONTRIBUTION
surfaceData.HTileMask |= DBUFFERHTILEBIT_DIFFUSE;
#else
surfaceData.baseColor.w = 0; // dont blend any albedo
#endif
#endif
#if _NORMALMAP
surfaceData.normalWS.xyz = mul((float3x3)normalToWorld, UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoordDS))) * 0.5f + 0.5f;

surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, input.texCoord0);
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
#if _ALBEDOCONTRIBUTION
#else
surfaceData.baseColor.w = 0; // dont blend any albedo
#endif
#endif
#if _NORMALMAP
float3 normalTS = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.texCoord0));

正在加载...
取消
保存