Skip to content

Commit d5bf47d

Browse files
GGijonUnitypastasfuture
authored andcommitted
Ported heightmap debugview to 10.3 (#20)
Added missing functions that caused shader graphs with types Eye, Fabric, Hair and StackLit to not compile when a debug mode is enabled. (#57)
1 parent ba4221b commit d5bf47d

File tree

16 files changed

+135
-4
lines changed

16 files changed

+135
-4
lines changed

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ unsafe struct ShaderVariablesDebugDisplay
3535
public Vector4 _MousePixelCoord; // xy unorm, zw norm
3636
public Vector4 _MouseClickPixelCoord; // xy unorm, zw norm
3737
public Vector4 _DebugLutParams; // x: 1/width, y: 1/height, z: height-1, w: unused
38+
public Vector4 _DebugShowHeightMaps; // xyz = color to use for materials not using heightmaps, w = albedo blend
3839

3940
public int _MatcapMixAlbedo;
4041
public float _MatcapViewScale;
@@ -120,6 +121,8 @@ public enum FullScreenDebugMode
120121
ValidateDiffuseColor,
121122
/// <summary>Display specular Color validation mode.</summary>
122123
ValidateSpecularColor,
124+
/// <summary>Display material heightmaps.</summary>
125+
Heightmaps,
123126
/// <summary>Maximum Full Screen Material debug mode value (used internally).</summary>
124127
MaxMaterialFullScreenDebug,
125128
// TODO: Move before count for 11.0
@@ -336,6 +339,7 @@ internal DebugDisplaySettings()
336339

337340
s_MaterialFullScreenDebugStrings[(int)FullScreenDebugMode.ValidateDiffuseColor - ((int)FullScreenDebugMode.MinMaterialFullScreenDebug)] = new GUIContent("Diffuse Color");
338341
s_MaterialFullScreenDebugStrings[(int)FullScreenDebugMode.ValidateSpecularColor - ((int)FullScreenDebugMode.MinMaterialFullScreenDebug)] = new GUIContent("Metal or SpecularColor");
342+
s_MaterialFullScreenDebugStrings[(int)FullScreenDebugMode.Heightmaps - ((int)FullScreenDebugMode.MinMaterialFullScreenDebug)] = new GUIContent("Show Heightmaps");
339343

340344
s_MsaaSamplesDebugStrings = Enum.GetNames(typeof(MSAASamples))
341345
.Select(t => new GUIContent(t))
@@ -518,7 +522,7 @@ public bool IsDebugExposureModeEnabled()
518522
/// <returns>True if any material validation is enabled.</returns>
519523
public bool IsMaterialValidationEnabled()
520524
{
521-
return (data.fullScreenDebugMode == FullScreenDebugMode.ValidateDiffuseColor) || (data.fullScreenDebugMode == FullScreenDebugMode.ValidateSpecularColor);
525+
return (data.fullScreenDebugMode == FullScreenDebugMode.ValidateDiffuseColor) || (data.fullScreenDebugMode == FullScreenDebugMode.ValidateSpecularColor) || (data.fullScreenDebugMode == FullScreenDebugMode.Heightmaps);
522526
}
523527

524528
/// <summary>
@@ -1017,6 +1021,17 @@ void RegisterMaterialDebug()
10171021
}
10181022
});
10191023
}
1024+
else if (data.fullScreenDebugMode == FullScreenDebugMode.Heightmaps)
1025+
{
1026+
list.Add(new DebugUI.Container
1027+
{
1028+
children =
1029+
{
1030+
new DebugUI.ColorField { displayName = "No HeightMap Color", getter = () => data.materialDebugSettings.showHeightMapsDefaultColor, setter = value => data.materialDebugSettings.showHeightMapsDefaultColor = value, showAlpha = false, hdr = false },
1031+
new DebugUI.FloatField { displayName = "Blend Albedo", getter = () => data.materialDebugSettings.showHeightMapsBlendAlbedo, setter = (v) => data.materialDebugSettings.showHeightMapsBlendAlbedo = v, min = () => 0.0f, max = () => 1.0f, },
1032+
}
1033+
});
1034+
}
10201035

10211036
m_DebugMaterialItems = list.ToArray();
10221037
var panel = DebugManager.instance.GetPanel(k_PanelMaterials, true);

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (27)
3838
#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (28)
3939
#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (29)
40-
#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (30)
41-
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_PREV (31)
42-
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_ACCUM (32)
40+
#define FULLSCREENDEBUGMODE_HEIGHTMAPS (30)
41+
#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (31)
42+
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_PREV (32)
43+
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_ACCUM (33)
4344

4445
// Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesDebugDisplay
4546
// PackingRules = Exact
@@ -66,6 +67,7 @@ CBUFFER_START(ShaderVariablesDebugDisplay)
6667
float4 _MousePixelCoord;
6768
float4 _MouseClickPixelCoord;
6869
float4 _DebugLutParams;
70+
float4 _DebugShowHeightMaps;
6971
int _MatcapMixAlbedo;
7072
float _MatcapViewScale;
7173
int _DebugSingleShadowIndex;

com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ static void BuildDebugRepresentation()
441441
public Color materialValidateTrueMetalColor = new Color(1.0f, 1.0f, 0.0f);
442442
/// <summary>Enable display of materials using a true metallic value.</summary>
443443
public bool materialValidateTrueMetal = false;
444+
/// <summary>Color for displaying materials that don't have a HeightMap in Show Heightmaps mode.</summary>
445+
public Color showHeightMapsDefaultColor = new Color(0.5f, 0.5f, 0.5f);
446+
/// <summary>How much from the albedo map is used to tint the heightmap.</summary>
447+
public float showHeightMapsBlendAlbedo = 0.2f;
444448

445449
/// <summary>
446450
/// Current Debug View Material.

com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ void GetPBRValidatorDebug(SurfaceData surfaceData, inout float3 result)
340340
result = surfaceData.diffuseColor;
341341
}
342342

343+
float4 GetHeightMapDebug(SurfaceData surfaceData)
344+
{
345+
return float4(surfaceData.diffuseColor, 1);
346+
}
343347

344348

345349
// This function is used to help with debugging and must be implemented by any lit material

com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFData.hlsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,16 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p
658658
// We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
659659
// as it can modify attribute use for static lighting
660660
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
661+
662+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
663+
{
664+
float3 heightmap = _DebugShowHeightMaps.rgb;
665+
#if defined(_HEIGHTMAP)
666+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
667+
heightmap = SAMPLE_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base.uvZY, lod).rrr;
668+
#endif
669+
surfaceData.diffuseColor = lerp(heightmap, surfaceData.diffuseColor, _DebugShowHeightMaps.a);
670+
}
661671
#endif
662672

663673
// -------------------------------------------------------------

com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ void GetPBRValidatorDebug(SurfaceData surfaceData, inout float3 result)
246246
result = surfaceData.baseColor;
247247
}
248248

249+
float4 GetHeightMapDebug(SurfaceData surfaceData)
250+
{
251+
return float4(surfaceData.baseColor, 1);
252+
}
253+
249254
//-----------------------------------------------------------------------------
250255
// PreLightData
251256
//

com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ void GetPBRValidatorDebug(SurfaceData surfaceData, inout float3 result)
250250
result = surfaceData.baseColor;
251251
}
252252

253+
float4 GetHeightMapDebug(SurfaceData surfaceData)
254+
{
255+
return float4(surfaceData.baseColor, 1);
256+
}
257+
253258
//-----------------------------------------------------------------------------
254259
// PreLightData
255260
//

com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ void GetPBRValidatorDebug(SurfaceData surfaceData, inout float3 result)
232232
result = surfaceData.diffuseColor;
233233
}
234234

235+
float4 GetHeightMapDebug(SurfaceData surfaceData)
236+
{
237+
return float4(surfaceData.diffuseColor, 1);
238+
}
239+
235240
//-----------------------------------------------------------------------------
236241
// PreLightData
237242
//

com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,36 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p
807807
// We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
808808
// as it can modify attribute use for static lighting
809809
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
810+
811+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
812+
{
813+
float3 heightmap = _DebugShowHeightMaps.rgb;
814+
815+
#if LAYERS_HEIGHTMAP_ENABLE
816+
LayerTexCoord layerTexCoord;
817+
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord);
818+
GetLayerTexCoord(input, layerTexCoord);
819+
820+
float4 blendMasks = GetBlendMask(layerTexCoord, input.color);
821+
SetEnabledHeightByLayer(blendMasks.x, blendMasks.y, blendMasks.z, blendMasks.w); // Nullify weights for unused layers
822+
823+
float totalWeight = length(blendMasks);
824+
if (totalWeight > 0)
825+
{
826+
827+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
828+
829+
float height0 = SAMPLE_TEXTURE2D_LOD(_HeightMap0, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base0.uv, lod).r;
830+
float height1 = SAMPLE_TEXTURE2D_LOD(_HeightMap1, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base1.uv, lod).r;
831+
float height2 = SAMPLE_TEXTURE2D_LOD(_HeightMap2, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base2.uv, lod).r;
832+
float height3 = SAMPLE_TEXTURE2D_LOD(_HeightMap3, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base3.uv, lod).r;
833+
834+
heightmap = dot(float4(height0, height1, height2, height3), blendMasks.argb) / totalWeight;
835+
}
836+
#endif
837+
838+
surfaceData.baseColor = lerp(heightmap, surfaceData.baseColor, _DebugShowHeightMaps.a);
839+
}
810840
#endif
811841

812842
// By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.

com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,11 @@ void GetPBRValidatorDebug(SurfaceData surfaceData, inout float3 result)
10211021
result = surfaceData.baseColor;
10221022
}
10231023

1024+
float4 GetHeightMapDebug(SurfaceData surfaceData)
1025+
{
1026+
return float4(surfaceData.baseColor, 1);
1027+
}
1028+
10241029
//-----------------------------------------------------------------------------
10251030
// PreLightData
10261031
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)