浏览代码

Implement mipmap debug mode for terrain.

/main
Yao Xiao Ling 6 年前
当前提交
6e836668
共有 9 个文件被更改,包括 111 次插入15 次删除
  1. 21
      com.unity.render-pipelines.high-definition/HDRP/Debug/DebugDisplay.cs
  2. 1
      com.unity.render-pipelines.high-definition/HDRP/Debug/DebugDisplay.hlsl
  3. 15
      com.unity.render-pipelines.high-definition/HDRP/Debug/MipMapDebug.cs
  4. 13
      com.unity.render-pipelines.high-definition/HDRP/Debug/MipMapDebug.cs.hlsl
  5. 25
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData.hlsl
  6. 15
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl
  7. 34
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitSplatCommon.hlsl
  8. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  9. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs

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


return mipMapDebugSettings.debugMipMapMode;
}
public DebugMipMapModeTerrainTexture GetDebugMipMapModeTerrainTexture()
{
return mipMapDebugSettings.terrainTexture;
}
public ColorPickerDebugMode GetDebugColorPickerMode()
{
return colorPickerDebugSettings.colorPickerMode;

widgetList.AddRange(new DebugUI.Widget[]
{
new DebugUI.EnumField { displayName = "Fullscreen Debug Mode", getter = () => (int)fullScreenDebugMode, setter = value => fullScreenDebugMode = (FullScreenDebugMode)value, enumNames = renderingFullScreenDebugStrings, enumValues = renderingFullScreenDebugValues },
new DebugUI.EnumField { displayName = "MipMaps", getter = () => (int)mipMapDebugSettings.debugMipMapMode, setter = value => SetMipMapMode((DebugMipMapMode)value), autoEnum = typeof(DebugMipMapMode) },
new DebugUI.EnumField { displayName = "MipMaps", getter = () => (int)mipMapDebugSettings.debugMipMapMode, setter = value => SetMipMapMode((DebugMipMapMode)value), autoEnum = typeof(DebugMipMapMode), onValueChanged = RefreshRenderingDebug },
});
if (mipMapDebugSettings.debugMipMapMode != DebugMipMapMode.None)
{
widgetList.Add(new DebugUI.Container
{
children =
{
new DebugUI.EnumField { displayName = "Terrain Texture", getter = ()=>(int)mipMapDebugSettings.terrainTexture, setter = value => mipMapDebugSettings.terrainTexture = (DebugMipMapModeTerrainTexture)value, autoEnum = typeof(DebugMipMapModeTerrainTexture) }
}
});
}
widgetList.AddRange(new []
{
new DebugUI.Container
{
displayName = "Color Picker",

1
com.unity.render-pipelines.high-definition/HDRP/Debug/DebugDisplay.hlsl


int _DebugLightingSubMode;
int _DebugViewMaterial; // Contain the id (define in various materialXXX.cs.hlsl) of the property to display
int _DebugMipMapMode; // Match enum DebugMipMapMode
int _DebugMipMapModeTerrainTexture; // Match enum DebugMipMapModeTerrainTexture
int _ColorPickerMode; // Match enum ColorPickerDebugMode
int _DebugStep;
float4 _DebugLightingAlbedo; // x == bool override, yzw = albedo for diffuse

15
com.unity.render-pipelines.high-definition/HDRP/Debug/MipMapDebug.cs


StreamingMip
}
[GenerateHLSL]
public enum DebugMipMapModeTerrainTexture
{
Control,
Layer0,
Layer1,
Layer2,
Layer3,
Layer4,
Layer5,
Layer6,
Layer7
}
public DebugMipMapModeTerrainTexture terrainTexture = DebugMipMapModeTerrainTexture.Control;
public bool IsDebugDisplayEnabled()
{

13
com.unity.render-pipelines.high-definition/HDRP/Debug/MipMapDebug.cs.hlsl


#define DEBUGMIPMAPMODE_STREAMING_MIP_BUDGET (4)
#define DEBUGMIPMAPMODE_STREAMING_MIP (5)
//
// UnityEngine.Experimental.Rendering.HDPipeline.DebugMipMapModeTerrainTexture: static fields
//
#define DEBUGMIPMAPMODETERRAINTEXTURE_CONTROL (0)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER0 (1)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER1 (2)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER2 (3)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER3 (4)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER4 (5)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER5 (6)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER6 (7)
#define DEBUGMIPMAPMODETERRAINTEXTURE_LAYER7 (8)
#endif

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


AddDecalContribution(posInput, surfaceData, alpha);
#endif
#if defined(DEBUG_DISPLAY)
#ifdef DEBUG_DISPLAY
// TODO: uncomment and fix me.
surfaceData.baseColor = 1;
// surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0, _BaseColorMap0, _BaseColorMap0_TexelSize, _BaseColorMap0_MipInfo, surfaceData.baseColor);
if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_CONTROL)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0, _Control0, _Control0_TexelSize, _Control0_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER0)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat0_ST.xy + _Splat0_ST.zw, _Splat0, _Splat0_TexelSize, _Splat0_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER1)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat1_ST.xy + _Splat1_ST.zw, _Splat1, _Splat1_TexelSize, _Splat1_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER2)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat2_ST.xy + _Splat2_ST.zw, _Splat2, _Splat2_TexelSize, _Splat2_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER3)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat3_ST.xy + _Splat3_ST.zw, _Splat3, _Splat3_TexelSize, _Splat3_MipInfo, surfaceData.baseColor);
#ifdef _TERRAIN_8_LAYERS
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER4)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat4_ST.xy + _Splat4_ST.zw, _Splat4, _Splat4_TexelSize, _Splat4_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER5)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat5_ST.xy + _Splat5_ST.zw, _Splat5, _Splat5_TexelSize, _Splat5_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER6)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat6_ST.xy + _Splat6_ST.zw, _Splat6, _Splat6_TexelSize, _Splat6_MipInfo, surfaceData.baseColor);
else if (_DebugMipMapModeTerrainTexture == DEBUGMIPMAPMODETERRAINTEXTURE_LAYER7)
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0 * _Splat7_ST.xy + _Splat7_ST.zw, _Splat7, _Splat7_TexelSize, _Splat7_MipInfo, surfaceData.baseColor);
#endif
surfaceData.metallic = 0;
}
#endif

15
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl


#include "TerrainLitSplatCommon.hlsl"
TEXTURE2D(_MainTex);
TEXTURE2D(_MetallicTex);
SAMPLER(sampler_MainTex);
#ifdef DEBUG_DISPLAY
float4 _MainTex_TexelSize;
float4 _MainTex_MipInfo;
#endif
// We don't use emission for terrain
#define _EmissiveColor float3(0,0,0)
#define _AlbedoAffectEmissive 0

AddDecalContribution(posInput, surfaceData, alpha);
#endif
#if defined(DEBUG_DISPLAY)
#ifdef DEBUG_DISPLAY
// TODO: uncomment and fix me.
surfaceData.baseColor = 1;
// surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0, _BaseColorMap0, _BaseColorMap0_TexelSize, _BaseColorMap0_MipInfo, surfaceData.baseColor);
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input.texCoord0, _MainTex, _MainTex_TexelSize, _MainTex_MipInfo, surfaceData.baseColor);
surfaceData.metallic = 0;
}
#endif

34
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitSplatCommon.hlsl


TEXTURE2D(_Control0);
SAMPLER(sampler_Splat0);
SAMPLER(sampler_Control0);
TEXTURE2D(_MainTex);
TEXTURE2D(_MetallicTex);
SAMPLER(sampler_MainTex);
#ifdef UNITY_INSTANCING_ENABLED
TEXTURE2D(_TerrainHeightmapTexture);

float4 _MaskMapRemapOffset##n; \
float4 _MaskMapRemapScale##n
CBUFFER_START(UnityPerMaterial)
CBUFFER_START(UnityTerrain)
#ifdef DEBUG_DISPLAY
float4 _Control0_TexelSize;
float4 _Control0_MipInfo;
float4 _Splat0_TexelSize;
float4 _Splat0_MipInfo;
float4 _Splat1_TexelSize;
float4 _Splat1_MipInfo;
float4 _Splat2_TexelSize;
float4 _Splat2_MipInfo;
float4 _Splat3_TexelSize;
float4 _Splat3_MipInfo;
#ifdef _TERRAIN_8_LAYERS
float4 _Splat4_TexelSize;
float4 _Splat4_MipInfo;
float4 _Splat5_TexelSize;
float4 _Splat5_MipInfo;
float4 _Splat6_TexelSize;
float4 _Splat6_MipInfo;
float4 _Splat7_TexelSize;
float4 _Splat7_MipInfo;
#endif
#endif
DECLARE_TERRAIN_LAYER_PROPS(0);
DECLARE_TERRAIN_LAYER_PROPS(1);

#endif
float _HeightTransition;
float4 _TerrainHeightmapRecipSize; // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1))
float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
#ifdef UNITY_INSTANCING_ENABLED
float4 _TerrainHeightmapRecipSize; // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1))
float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
#endif
CBUFFER_END

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


cmd.SetGlobalInt(HDShaderIDs._DebugLightingMode, (int)m_CurrentDebugDisplaySettings.GetDebugLightingMode());
cmd.SetGlobalInt(HDShaderIDs._DebugLightingSubMode, (int)m_CurrentDebugDisplaySettings.GetDebugLightingSubMode());
cmd.SetGlobalInt(HDShaderIDs._DebugMipMapMode, (int)m_CurrentDebugDisplaySettings.GetDebugMipMapMode());
cmd.SetGlobalInt(HDShaderIDs._DebugMipMapModeTerrainTexture, (int)m_CurrentDebugDisplaySettings.GetDebugMipMapModeTerrainTexture());
cmd.SetGlobalInt(HDShaderIDs._ColorPickerMode, (int)m_CurrentDebugDisplaySettings.GetDebugColorPickerMode());
cmd.SetGlobalVector(HDShaderIDs._DebugLightingAlbedo, debugAlbedo);

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _DebugLightingSpecularColor = Shader.PropertyToID("_DebugLightingSpecularColor");
public static readonly int _AmbientOcclusionTexture = Shader.PropertyToID("_AmbientOcclusionTexture");
public static readonly int _DebugMipMapMode = Shader.PropertyToID("_DebugMipMapMode");
public static readonly int _DebugMipMapModeTerrainTexture = Shader.PropertyToID("_DebugMipMapModeTerrainTexture");
public static readonly int _UseTileLightList = Shader.PropertyToID("_UseTileLightList");

正在加载...
取消
保存