Skip to content

Commit 7300644

Browse files
GGijonUnitypastasfuture
authored andcommitted
Ported heightmap debugview to 10.3 (#20)
1 parent fb76291 commit 7300644

File tree

12 files changed

+116
-4
lines changed

12 files changed

+116
-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
@@ -668,6 +668,16 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p
668668
// We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
669669
// as it can modify attribute use for static lighting
670670
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
671+
672+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
673+
{
674+
float3 heightmap = _DebugShowHeightMaps.rgb;
675+
#if defined(_HEIGHTMAP)
676+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
677+
heightmap = SAMPLE_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base.uvZY, lod).rrr;
678+
#endif
679+
surfaceData.diffuseColor = lerp(heightmap, surfaceData.diffuseColor, _DebugShowHeightMaps.a);
680+
}
671681
#endif
672682

673683
// -------------------------------------------------------------

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
@@ -813,6 +813,36 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p
813813
// We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
814814
// as it can modify attribute use for static lighting
815815
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
816+
817+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
818+
{
819+
float3 heightmap = _DebugShowHeightMaps.rgb;
820+
821+
#if LAYERS_HEIGHTMAP_ENABLE
822+
LayerTexCoord layerTexCoord;
823+
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord);
824+
GetLayerTexCoord(input, layerTexCoord);
825+
826+
float4 blendMasks = GetBlendMask(layerTexCoord, input.color);
827+
SetEnabledHeightByLayer(blendMasks.x, blendMasks.y, blendMasks.z, blendMasks.w); // Nullify weights for unused layers
828+
829+
float totalWeight = length(blendMasks);
830+
if (totalWeight > 0)
831+
{
832+
833+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
834+
835+
float height0 = SAMPLE_TEXTURE2D_LOD(_HeightMap0, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base0.uv, lod).r;
836+
float height1 = SAMPLE_TEXTURE2D_LOD(_HeightMap1, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base1.uv, lod).r;
837+
float height2 = SAMPLE_TEXTURE2D_LOD(_HeightMap2, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base2.uv, lod).r;
838+
float height3 = SAMPLE_TEXTURE2D_LOD(_HeightMap3, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base3.uv, lod).r;
839+
840+
heightmap = dot(float4(height0, height1, height2, height3), blendMasks.argb) / totalWeight;
841+
}
842+
#endif
843+
844+
surfaceData.baseColor = lerp(heightmap, surfaceData.baseColor, _DebugShowHeightMaps.a);
845+
}
816846
#endif
817847

818848
// 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
//-----------------------------------------------------------------------------

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p
279279
// We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
280280
// as it can modify attribute use for static lighting
281281
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
282+
283+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
284+
{
285+
float3 heightmap = _DebugShowHeightMaps.rgb;
286+
#if defined(_HEIGHTMAP)
287+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
288+
heightmap = SAMPLE_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base.uvZY, lod).rrr;
289+
#endif
290+
surfaceData.baseColor = lerp(heightmap, surfaceData.baseColor, _DebugShowHeightMaps.a);
291+
}
282292
#endif
283293

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ void GetSurfaceAndBuiltinData(inout FragInputs input, float3 V, inout PositionIn
237237
// We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
238238
// as it can modify attribute use for static lighting
239239
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
240+
241+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
242+
{
243+
float3 heightmap = _DebugShowHeightMaps.rgb;
244+
#if defined(_HEIGHTMAP)
245+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
246+
heightmap = SAMPLE_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base.uvZY, lod).rrr;
247+
#endif
248+
surfaceData.baseColor = lerp(heightmap, surfaceData.baseColor, _DebugShowHeightMaps.a);
249+
}
240250
#endif
241251

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,17 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p
8787

8888
ApplyDebugToBuiltinData(builtinData);
8989

90+
#if defined(DEBUG_DISPLAY) && !defined(SHADER_STAGE_RAY_TRACING)
91+
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_HEIGHTMAPS)
92+
{
93+
float3 heightmap = _DebugShowHeightMaps.rgb;
94+
#if defined(_HEIGHTMAP)
95+
float lod = ComputeTextureLOD(GetMinUvSize(layerTexCoord));
96+
heightmap = SAMPLE_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base.uvZY, lod).rrr;
97+
#endif
98+
surfaceData.color = lerp(heightmap, surfaceData.color, _DebugShowHeightMaps.a);
99+
}
100+
#endif
101+
90102
RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
91103
}

0 commit comments

Comments
 (0)