浏览代码

Moved MipMap Debug rendering to its own mode.

Improved the visualisation of mip ratio to handle mip reduction.
Improved the mip level count visualisation now mip streaming shown more clearly in other mip debug mode
Moved common shader functions to HLSL file
/feature-ReflectionProbeFit
lyndon homewood 7 年前
当前提交
595016ea
共有 18 个文件被更改,包括 345 次插入192 次删除
  1. 17
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
  2. 180
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Debug.hlsl
  3. 54
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
  5. 31
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MaterialDebug.cs
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MaterialDebug.cs.hlsl
  7. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  9. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  10. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitData.hlsl
  11. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/UnlitData.hlsl
  12. 126
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/FragInputs.hlsl
  13. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForward.hlsl
  14. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForwardUnlit.hlsl
  15. 32
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs
  16. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs.hlsl
  17. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs.hlsl.meta
  18. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs.meta

17
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl


// The reason is that for compute shader we need to guarantee that the layout of CBs is consistent across kernels. Something that we can't control with the global namespace (uniforms get optimized out if not used, modifying the global CBuffer layout per kernel)
// Structure definition that are share between C# and hlsl.
// These structures need to be align on float4 to respect various packing rules from sahder language.
// These structures need to be align on float4 to respect various packing rules from shader language.
// This mean that these structure need to be padded.
// Do not use "in", only "out" or "inout" as califier, not "inline" keyword either, useless.

return ComputeTextureLOD(uv);
}
uint GetMipCount(Texture2D tex)
{
#if defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_XBOXONE) || defined(SHADER_API_PSSL)
uint width, height, depth, mipCount;
width = height = depth = mipCount = 0;
tex.GetDimensions(width, height, depth, mipCount);
return mipCount;
#else
// SHADER_API_OPENGL only supports textureSize for width, height, depth
return 0;
#endif
}
// ----------------------------------------------------------------------------
// Texture format sampling
// ----------------------------------------------------------------------------

}
// Normalize that account for vectors with zero length
/*
*/
// Generates a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).

180
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Debug.hlsl


if (number <= 9)
{
return SampleDebugFont(pixCoord - int2(6, 0), number);
}
else
{

float4 GetStreamingMipColor(uint mipCount, float4 mipInfo)
{
// alpha is amount to blend with source color (0.0 = use original, 1.0 = use new color)
// mipInfo :
// x = quality setings minStreamingMipLevel
// y = original mip count for texture
// z = desired on screen mip level
// w = 0
uint originalTextureMipCount = uint(mipInfo.y);
// If material/shader mip info (original mip level) has not been set its not a streamed texture
if (originalTextureMipCount == 0)
return float4(1.0, 1.0, 1.0, 0.0);
uint desiredMipLevel = uint(mipInfo.z);
uint mipCountDesired = uint(originalTextureMipCount)-uint(desiredMipLevel);
if (mipCount == 0)
{
// Magenta if mip count invalid
return float4(1.0, 0.0, 1.0, 1.0);
}
else if (mipCount < mipCountDesired)
{
// red tones when not at the desired mip level (reduction due to budget). Brighter is further from original, alpha 0 when at desired
float ratioToDesired = float(mipCount) / float(mipCountDesired);
return float4(1.0, 0.0, 0.0, 1.0 - ratioToDesired);
}
else if (mipCount >= originalTextureMipCount)
{
// original color when at (or beyond) original mip count
return float4(1.0, 1.0, 1.0, 0.0);
}
else
{
// green tones when not at the original mip level. Brighter is closer to original, alpha 0 when at original
float ratioToOriginal = float(mipCount) / float(originalTextureMipCount);
return float4(0.0, 1.0, 0.0, 1.0 - ratioToOriginal);
}
}
float4 GetSimpleMipCountColor(uint mipCount)
{
// Grey scale for mip counts where mip count of 12 = white
float mipCountColor = float(mipCount) / 12.0;
float4 color = float4(mipCountColor, mipCountColor, mipCountColor, 1.0f);
// alpha is amount to blend with source color (0.0 = use original, 1.0 = use new color)
// Magenta is no valid mip count
// Original colour if greater than 12
return mipCount==0 ? float4(1.0, 0.0, 1.0, 1.0) : (mipCount > 12 ? float4(1.0, 1.0, 1.0, 0.0) : color );
}
float4 GetMipLevelColor(float2 iUV, float4 texelSize)
{
// Push down into colors list to "optimal level" in following table.
// .zw is texture width,height so *2 is down one mip, *4 is down two mips
texelSize.zw *= 4.0;
float mipLevel = ComputeTextureLOD(iUV, texelSize);
mipLevel = clamp(mipLevel, 0.0, 5.0 - 0.0001);
float4 colors[6] = {
float4(0.0, 0.0, 1.0, 0.8), // 0 BLUE = too little texture detail
float4(0.0, 0.5, 1.0, 0.4), // 1
float4(1.0, 1.0, 1.0, 0.0), // 2 = optimal level
float4(1.0, 0.7, 0.0, 0.2), // 3 (YELLOW tint)
float4(1.0, 0.3, 0.0, 0.6), // 4 (clamped mipLevel 4.9999)
float4(1.0, 0.0, 0.0, 0.8) // 5 RED = too much texture detail (max blended value)
};
int mipLevelInt = floor(mipLevel);
float t = frac(mipLevel);
float4 a = colors[mipLevelInt];
float4 b = colors[mipLevelInt + 1];
float4 color = lerp(a, b, t);
return color;
}
float3 GetDebugMipColor(float3 originalColor, Texture2D tex, float4 texelSize, float2 uv)
{
// https://aras-p.info/blog/2011/05/03/a-way-to-visualize-mip-levels/
float4 mipColor= GetMipLevelColor(uv, texelSize);
return lerp(originalColor, mipColor.rgb, mipColor.a);
}
float3 GetDebugMipCountColor(float3 originalColor, Texture2D tex)
{
uint mipCount = GetMipCount(tex);
float4 mipColor = GetSimpleMipCountColor(mipCount);
return lerp(originalColor, mipColor.rgb, mipColor.a);
}
float3 GetDebugStreamingMipColor(Texture2D tex, float4 mipInfo)
{
uint mipCount = GetMipCount(tex);
return GetStreamingMipColor(mipCount, mipInfo).xyz;
}
float3 GetDebugStreamingMipColorBlended(float3 originalColor, Texture2D tex, float4 mipInfo)
{
uint mipCount = GetMipCount(tex);
float4 mipColor = GetStreamingMipColor(mipCount, mipInfo);
return lerp(originalColor, mipColor.rgb, mipColor.a);
}
float3 GetDebugMipColorIncludingMipReduction(float3 originalColor, Texture2D tex, float4 texelSize, float2 uv, float4 mipInfo)
{
uint originalTextureMipCount = uint(mipInfo.y);
if (originalTextureMipCount != 0)
{
// mipInfo :
// x = quality setings minStreamingMipLevel
// y = original mip count for texture
// z = desired on screen mip level
// w = 0
// Mip count has been reduced but the texelSize was not updated to take that into account
uint mipCount = GetMipCount(tex);
uint mipReductionLevel = originalTextureMipCount - mipCount;
uint mipReductionFactor = 1 << mipReductionLevel;
if (mipReductionFactor)
{
float oneOverMipReductionFactor = 1.0 / mipReductionFactor;
// texelSize.xy *= mipReductionRatio; // Unused in GetDebugMipColor so lets not re-calculate it
texelSize.zw *= oneOverMipReductionFactor;
}
}
return GetDebugMipColor(originalColor, tex, texelSize, uv);
}
float3 GetDebugMipReductionColor(Texture2D tex, float4 mipInfo)
{
uint originalTextureMipCount = uint(mipInfo.y);
if (originalTextureMipCount != 0)
{
// mipInfo :
// x = quality setings minStreamingMipLevel
// y = original mip count for texture
// z = desired on screen mip level
// w = 0
// Mip count has been reduced but the texelSize was not updated to take that into account
uint mipCount = GetMipCount(tex);
uint mipReductionLevel = originalTextureMipCount - mipCount;
float mipCol = float(mipReductionLevel) / 12.0;
return float3(0, mipCol, 0);
}
// Can't calculate without original mip count - return magenta
return float3(1.0, 0.0, 1.0);
}
#ifdef DEBUG_DISPLAY
#ifdef FRAG_INPUTS_DEFINED
float3 GetTextureDataDebug(uint paramId, FragInputs input, Texture2D tex, float4 texelSize, float4 mipInfo, float3 originalColor)
{
switch (paramId)
{
case DEBUGMIPMAPMODE_MIP_RATIO:
return GetDebugMipColorIncludingMipReduction(originalColor, tex, texelSize, input.texCoord0.xy, mipInfo);
case DEBUGMIPMAPMODE_MIP_COUNT:
return GetDebugMipCountColor(originalColor, tex);
case DEBUGMIPMAPMODE_MIP_COUNT_REDUCTION:
return GetDebugMipReductionColor(tex, mipInfo);
case DEBUGMIPMAPMODE_STREAMING_MIP_BUDGET:
return GetDebugStreamingMipColor(tex, mipInfo);
case DEBUGMIPMAPMODE_STREAMING_MIP:
return GetDebugStreamingMipColorBlended(originalColor, tex, mipInfo);
}
return originalColor;
}
#endif // FRAG_INPUTS_DEFINED
#endif // DEBUG_DISPLAY
#endif // UNITY_DEBUG_INCLUDED

54
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs


public static string kSkyReflectionMipmapDebug = "Sky Reflection Mipmap";
public static string kTileClusterCategoryDebug = "Tile/Cluster Debug By Category";
public static string kTileClusterDebug = "Tile/Cluster Debug";
public static string kMipMapDebugMode = "Mip Map Debug Mode";
public float debugOverlayRatio = 0.33f;

public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings();
public LightingDebugSettings lightingDebugSettings = new LightingDebugSettings();
public MipMapDebugSettings mipMapDebugSettings = new MipMapDebugSettings();
public static GUIContent[] lightingFullScreenDebugStrings = null;
public static int[] lightingFullScreenDebugValues = null;

public DebugLightingMode GetDebugLightingMode()
{
return lightingDebugSettings.debugLightingMode;
}
public DebugMipMapMode GetDebugMipMapMode()
{
return mipMapDebugSettings.debugMipMapMode;
return materialDebugSettings.IsDebugDisplayEnabled() || lightingDebugSettings.IsDebugDisplayEnabled();
return materialDebugSettings.IsDebugDisplayEnabled() || lightingDebugSettings.IsDebugDisplayEnabled() || mipMapDebugSettings.IsDebugDisplayEnabled();
}
public bool IsDebugMaterialDisplayEnabled()

public bool IsDebugMipMapDisplayEnabled()
{
return mipMapDebugSettings.IsDebugDisplayEnabled();
}
private void DisableNonMaterialDebugSettings()
{
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
}
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
DisableNonMaterialDebugSettings();
materialDebugSettings.SetDebugViewMaterial(value);
}

lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
DisableNonMaterialDebugSettings();
materialDebugSettings.SetDebugViewEngine(value);
}

lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
DisableNonMaterialDebugSettings();
materialDebugSettings.SetDebugViewVarying(value);
}

lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
DisableNonMaterialDebugSettings();
public void SetDebugViewTexture(Attributes.DebugViewTexture value)
{
if (value != 0)
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
materialDebugSettings.SetDebugViewTexture(value);
}
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
DisableNonMaterialDebugSettings();
if(value != 0)
if (value != 0)
{
mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
}
public void SetMipMapMode(DebugMipMapMode value)
{
if (value != 0)
{
materialDebugSettings.DisableMaterialDebug();
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
}
mipMapDebugSettings.debugMipMapMode = value;
}
//if (materialDebugSettings.debugViewTexture != 0)
// if (mipMapDebugSettings.debugMipMapMode != 0)
// Texture.SetStreamingTextureMaterialDebugProperties();
}

DebugMenuManager.instance.AddDebugItem<int>("Material", "Engine",() => materialDebugSettings.debugViewEngine, (value) => SetDebugViewEngine((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(MaterialDebugSettings.debugViewEngineStrings, MaterialDebugSettings.debugViewEngineValues));
DebugMenuManager.instance.AddDebugItem<Attributes.DebugViewVarying>("Material", "Attributes",() => materialDebugSettings.debugViewVarying, (value) => SetDebugViewVarying((Attributes.DebugViewVarying)value));
DebugMenuManager.instance.AddDebugItem<Attributes.DebugViewProperties>("Material", "Properties", () => materialDebugSettings.debugViewProperties, (value) => SetDebugViewProperties((Attributes.DebugViewProperties)value));
DebugMenuManager.instance.AddDebugItem<Attributes.DebugViewTexture>("Material", "Texture", () => materialDebugSettings.debugViewTexture, (value) => SetDebugViewTexture((Attributes.DebugViewTexture)value));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(MaterialDebugSettings.debugViewMaterialGBufferStrings, MaterialDebugSettings.debugViewMaterialGBufferValues));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, ShadowMapDebugMode>(kShadowDebugMode, () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);

DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, LightLoop.TileClusterCategoryDebug>(kTileClusterCategoryDebug,() => lightingDebugSettings.tileClusterDebugByCategory, (value) => lightingDebugSettings.tileClusterDebugByCategory = (LightLoop.TileClusterCategoryDebug)value);
DebugMenuManager.instance.AddDebugItem<int>("Rendering", kFullScreenDebugMode, () => (int)fullScreenDebugMode, (value) => fullScreenDebugMode = (FullScreenDebugMode)value, DebugItemFlag.None, new DebugItemHandlerIntEnum(DebugDisplaySettings.renderingFullScreenDebugStrings, DebugDisplaySettings.renderingFullScreenDebugValues));
DebugMenuManager.instance.AddDebugItem<DebugMipMapMode>("Rendering", "MipMaps", () => mipMapDebugSettings.debugMipMapMode, (value) => SetMipMapMode((DebugMipMapMode)value));
}
public void OnValidate()

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl


#include "DebugDisplay.cs.hlsl"
#include "MaterialDebug.cs.hlsl"
#include "LightingDebug.cs.hlsl"
#include "MipMapDebug.cs.hlsl"
int _DebugMipMapMode; // Match enum DebugMipMapMode
float4 _DebugLightingAlbedo; // xyz = albedo for diffuse, w unused
float4 _DebugLightingSmoothness; // x == bool override, y == override value

31
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MaterialDebug.cs


Lightmap,
Last,
}
// Number must be contiguous
[GenerateHLSL]
public enum DebugViewTexture
{
None = 0,
ShowMipRatio = DebugViewProperties.Last,
MaxMip,
StreamingMips,
Last,
}
}
[Serializable]

index = 0;
FillWithPropertiesEnum(typeof(Attributes.DebugViewProperties), debugViewMaterialPropertiesStrings, debugViewMaterialPropertiesValues, "", ref index);
// Textures debug
var textureNames = Enum.GetNames(typeof(Attributes.DebugViewTexture));
debugViewMaterialTextureStrings = new GUIContent[textureNames.Length];
debugViewMaterialTextureValues = new int[textureNames.Length];
index = 0;
FillWithPropertiesEnum(typeof(Attributes.DebugViewTexture), debugViewMaterialTextureStrings, debugViewMaterialTextureValues, "", ref index);
// Gbuffer debug
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer));
debugViewMaterialGBufferStrings = new GUIContent[gbufferNames.Length + bsdfDataDeferredType.GetFields().Length];

public int debugViewEngine { get { return m_DebugViewEngine; } }
public Attributes.DebugViewVarying debugViewVarying { get { return m_DebugViewVarying; } }
public Attributes.DebugViewProperties debugViewProperties { get { return m_DebugViewProperties; } }
public Attributes.DebugViewTexture debugViewTexture { get { return m_DebugViewTexture; } }
public int debugViewGBuffer { get { return m_DebugViewGBuffer; } }
int m_DebugViewMaterial = 0; // No enum there because everything is generated from materials.

Attributes.DebugViewTexture m_DebugViewTexture = Attributes.DebugViewTexture.None;
int m_DebugViewGBuffer = 0; // Can't use GBuffer enum here because the values are actually split between this enum and values from Lit.BSDFData
public int GetDebugMaterialIndex()

// They are all mutually exclusive so return the sum will return the right index.
return m_DebugViewGBuffer + m_DebugViewMaterial + m_DebugViewEngine + (int)m_DebugViewVarying + (int)m_DebugViewProperties + (int)m_DebugViewTexture;
return m_DebugViewGBuffer + m_DebugViewMaterial + m_DebugViewEngine + (int)m_DebugViewVarying + (int)m_DebugViewProperties;
}
public void DisableMaterialDebug()

m_DebugViewVarying = Attributes.DebugViewVarying.None;
m_DebugViewProperties = Attributes.DebugViewProperties.None;
m_DebugViewTexture = Attributes.DebugViewTexture.None;
m_DebugViewGBuffer = 0;
}

DisableMaterialDebug();
m_DebugViewProperties = value;
}
public void SetDebugViewTexture(Attributes.DebugViewTexture value)
{
if (value != 0)
DisableMaterialDebug();
m_DebugViewTexture = value;
}
public void SetDebugViewGBuffer(int value)
{

public bool IsDebugDisplayEnabled()
{
return (m_DebugViewEngine != 0 || m_DebugViewMaterial != 0 || m_DebugViewVarying != Attributes.DebugViewVarying.None || m_DebugViewProperties != Attributes.DebugViewProperties.None || m_DebugViewTexture != Attributes.DebugViewTexture.None || m_DebugViewGBuffer != 0);
return (m_DebugViewEngine != 0 || m_DebugViewMaterial != 0 || m_DebugViewVarying != Attributes.DebugViewVarying.None || m_DebugViewProperties != Attributes.DebugViewProperties.None || m_DebugViewGBuffer != 0);
}
}
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MaterialDebug.cs.hlsl


#define DEBUGVIEWPROPERTIES_LIGHTMAP (21)
#define DEBUGVIEWPROPERTIES_LAST (22)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Attributes.DebugViewTexture: static fields
//
#define DEBUGVIEWTEXTURE_NONE (0)
#define DEBUGVIEWTEXTURE_SHOW_MIP_RATIO (22)
#define DEBUGVIEWTEXTURE_MAX_MIP (23)
#define DEBUGVIEWTEXTURE_STREAMING_MIPS (24)
#define DEBUGVIEWTEXTURE_LAST (25)
#endif

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


Resize(camera);
if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled())
{
m_CurrentDebugDisplaySettings.UpdateMaterials();
}
renderContext.SetupCameraProperties(camera);
PushGlobalParams(hdCamera, cmd, sssSettings);

RenderPyramidDepth(camera, cmd, renderContext, FullScreenDebugMode.DepthPyramid);
if (m_CurrentDebugDisplaySettings.IsDebugMaterialDisplayEnabled())
{
RenderDebugViewMaterial(m_CullResults, hdCamera, renderContext, cmd);

// Render opaque objects into GBuffer
if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled())
{
m_CurrentDebugDisplaySettings.UpdateMaterials();
// When doing debug display, the shader has the clip instruction regardless of the depth prepass so we can use regular depth test.
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferDebugDisplayName, m_currentRendererConfigurationBakedLighting, RenderQueueRange.opaque, m_DepthStateOpaque);
}

cmd.SetGlobalInt(HDShaderIDs._DebugViewMaterial, (int)m_CurrentDebugDisplaySettings.GetDebugMaterialIndex());
cmd.SetGlobalInt(HDShaderIDs._DebugLightingMode, (int)m_CurrentDebugDisplaySettings.GetDebugLightingMode());
cmd.SetGlobalInt(HDShaderIDs._DebugMipMapMode, (int)m_CurrentDebugDisplaySettings.GetDebugMipMapMode());
cmd.SetGlobalVector(HDShaderIDs._DebugLightingAlbedo, debugAlbedo);
cmd.SetGlobalVector(HDShaderIDs._DebugLightingSmoothness, debugSmoothness);
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _DebugLightingAlbedo = Shader.PropertyToID("_DebugLightingAlbedo");
public static readonly int _DebugLightingSmoothness = Shader.PropertyToID("_DebugLightingSmoothness");
public static readonly int _AmbientOcclusionTexture = Shader.PropertyToID("_AmbientOcclusionTexture");
public static readonly int _DebugMipMapMode = Shader.PropertyToID("_DebugMipMapMode");
public static readonly int _UseTileLightList = Shader.PropertyToID("_UseTileLightList");
public static readonly int _Time = Shader.PropertyToID("_Time");

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


specularLighting = float3(0.0, 0.0, 0.0); // Disable specular lighting
}
#endif
else if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
diffuseLighting = bsdfData.diffuseColor;
specularLighting = float3(0.0, 0.0, 0.0); // Disable specular lighting
}
#endif
}

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitData.hlsl


return SphericalCapIntersectionSolidArea(cosAv, cosAs, cosB) / (TWO_PI * (1.0 - cosAs));
}
void GetBuiltinData(FragInputs input, SurfaceData surfaceData, float alpha, float3 bentNormalWS, float depthOffset, out BuiltinData builtinData)
void GetBuiltinData(FragInputs input, inout SurfaceData surfaceData, float alpha, float3 bentNormalWS, float depthOffset, out BuiltinData builtinData)
{
// Builtin Data
builtinData.opacity = alpha;

#endif
builtinData.depthOffset = depthOffset;
#if defined(DEBUG_DISPLAY)
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
#ifdef LAYERED_LIT_SHADER
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input, _BaseColorMap0, _BaseColorMap0_TexelSize, _BaseColorMap0_MipInfo, surfaceData.baseColor);
#else
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, input, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor);
#endif
surfaceData.metallic = 0;
}
#endif
}
// Struct that gather UVMapping info of all layers + common calculation

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/UnlitData.hlsl


#endif
builtinData.depthOffset = 0.0;
#if defined(DEBUG_DISPLAY)
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
surfaceData.color = GetTextureDataDebug(_DebugMipMapMode, input, _UnlitColorMap, _UnlitColorMap_TexelSize, _UnlitColorMap_MipInfo, surfaceData.color);
}
#endif
}

126
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/FragInputs.hlsl


#include "../Debug/MaterialDebug.cs.hlsl"
#define FRAG_INPUTS_DEFINED
struct FragInputs
{
// Contain value return by SV_POSITION (That is name positionCS in PackedVarying).

}
}
uint GetMipCount(Texture2D tex)
{
uint width, height, depth, mipCount;
width = height = depth = mipCount = 0;
tex.GetDimensions(width, height, depth, mipCount);
return mipCount;
}
float4 GetStreamingMipColour(uint mipCount, float4 mipInfo)
{
// mipInfo :
// x = quality setings minStreamingMipLevel
// y = original mip count for texture
// z = desired on screen mip level
// w = 0
uint originalTextureMipCount = uint(mipInfo.y);
// If material/shader mip info (original mip level) has not been set its not a streamed texture
if (originalTextureMipCount == 0)
return float4(1.0f, 1.0f, 1.0f, 0.0f);
uint desiredMipLevel = uint(mipInfo.z);
uint mipCountDesired = uint(originalTextureMipCount) - uint(desiredMipLevel);
if (mipCount < mipCountDesired)
{
// red tones when not at the desired mip level (reduction due to budget). Brighter is further from original, alpha 0 when at desired
float ratioToDesired = float(mipCount) / float(mipCountDesired);
return float4(0.5f + (0.5f * ratioToDesired), 0.0f, 0.0f, 1.0f - ratioToDesired);
}
else if (mipCount >= originalTextureMipCount)
{
// original colour when at (or beyond) original mip count
return float4(1.0f, 1.0f, 1.0f, 0.0f);
}
else
{
// green tones when not at the original mip level. Brighter is closer to original, alpha 0 when at original
float ratioToOriginal = float(mipCount) / float(originalTextureMipCount);
return float4(0.0f, 0.5f + (0.5f * ratioToOriginal), 0.0f, 1.0f - ratioToOriginal);
}
}
float4 GetSimpleMipCountColour(uint mipCount)
{
// 0-4, red tones, 4-7 green tones, 8-11 blue tones
float4 color = float4(
mipCount >= 0 && mipCount < 4 ? 0.5f + (float)(mipCount) / 6.0f : 0.0f,
mipCount >= 4 && mipCount < 8 ? 0.5f + (float)(mipCount - 4) / 6.0f : 0.0f,
mipCount >= 8 && mipCount < 12 ? 0.5f + (float)(mipCount - 8) / 6.0f : 0.0f,
0.5f
);
return mipCount >= 12 ? float4(1.0f, 1.0f, 1.0f, 0.0f) : color;
}
float GetMipLevel(float2 uv, float2 textureSize)
{
float2 dx = ddx(uv * textureSize.x);
float2 dy = ddy(uv * textureSize.y);
float d = max(dot(dx, dx), dot(dy, dy));
return 0.5f * log2(d);
}
float4 GetMipLevelColour(float2 iUV, float2 iTextureSize)
{
float mipLevel = GetMipLevel(iUV, iTextureSize);
mipLevel = clamp(mipLevel, 0.0f, 6.0f - 0.0001f);
float4 colours[6] = {
float4(0.0f, 0.0f, 1.0f, 0.8f),
float4(0.0f, 0.5f, 1.0f, 0.4f),
float4(1.0f, 1.0f, 1.0f, 0.0f), // optimal level
float4(1.0f, 0.7f, 0.0f, 0.2f),
float4(1.0f, 0.3f, 0.0f, 0.6f),
float4(1.0f, 0.0f, 0.0f, 0.8f)
};
int mipLevelInt = floor(mipLevel);
float t = frac(mipLevel);
float4 a = colours[mipLevelInt];
float4 b = colours[mipLevelInt + 1];
float4 color = lerp(a, b, t);
return color;
}
float3 GetDebugMipColour(float3 originalColour, Texture2D tex, float4 texelSize, float2 uv)
{
// https://aras-p.info/blog/2011/05/03/a-way-to-visualize-mip-levels/
float4 mipColour = GetMipLevelColour(uv, texelSize.zw); // /8 to push down 2 mip levels (4 * uv difference)
return lerp(originalColour, mipColour.rgb, mipColour.a);
}
float3 GetDebugMaxMipColour(float3 originalColour, Texture2D tex)
{
uint mipCount = GetMipCount(tex);
float4 mipColour = GetSimpleMipCountColour(mipCount);
return lerp(originalColour, mipColour.rgb, mipColour.a);
}
float3 GetDebugStreamingMipColour(float3 originalColour, Texture2D tex, float4 mipInfo)
{
uint mipCount = GetMipCount(tex);
float4 mipColour = GetStreamingMipColour(mipCount, mipInfo);
return lerp(originalColour, mipColour.rgb, mipColour.a);
}
void GetTextureDataDebug(uint paramId, FragInputs input, Texture2D tex, float4 texelSize, float4 mipInfo, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEWTEXTURE_SHOW_MIP_RATIO:
result = GetDebugMipColour(result, tex, texelSize, input.texCoord0.xy);
break;
case DEBUGVIEWTEXTURE_MAX_MIP:
result = GetDebugMaxMipColour(result, tex);
break;
case DEBUGVIEWTEXTURE_STREAMING_MIPS:
result = GetDebugStreamingMipColour(result, tex, mipInfo);
break;
}
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForward.hlsl


// We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4.
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode != DEBUGLIGHTINGMODE_NONE)
if (_DebugLightingMode != DEBUGLIGHTINGMODE_NONE || _DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
#endif
{
#ifdef _SURFACE_TYPE_TRANSPARENT

// Same code in ShaderPassForwardUnlit.shader
if (_DebugViewMaterial != 0)
{
float3 result = (_DebugViewMaterial >= DEBUGVIEWTEXTURE_SHOW_MIP_RATIO && _DebugViewMaterial < DEBUGVIEWTEXTURE_LAST) ? ApplyBlendMode(bsdfData.diffuseColor, builtinData.opacity).xyz : float3(1.0, 0.0, 1.0);
float3 result = float3(1.0, 0.0, 1.0);
bool needLinearToSRGB = false;

GetSurfaceDataDebug(_DebugViewMaterial, surfaceData, result, needLinearToSRGB);
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB); // TODO: This required to initialize all field from BSDFData...
#ifdef LAYERED_LIT_SHADER
GetTextureDataDebug(_DebugViewMaterial, input, _BaseColorMap0, _BaseColorMap0_TexelSize, _BaseColorMap0_MipInfo, result, needLinearToSRGB);
#else
GetTextureDataDebug(_DebugViewMaterial, input, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, result, needLinearToSRGB);
#endif
// TEMP!
// For now, the final blit in the backbuffer performs an sRGB write

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForwardUnlit.hlsl


// Same code in ShaderPassForward.shader
if (_DebugViewMaterial != 0)
{
float3 result = (_DebugViewMaterial >= DEBUGVIEWTEXTURE_SHOW_MIP_RATIO && _DebugViewMaterial < DEBUGVIEWTEXTURE_LAST) ? outColor.rgb : float3(1.0, 0.0, 1.0);
float3 result = float3(1.0, 0.0, 1.0);
bool needLinearToSRGB = false;
GetPropertiesDataDebug(_DebugViewMaterial, result, needLinearToSRGB);

GetTextureDataDebug(_DebugViewMaterial, input, _UnlitColorMap, _UnlitColorMap_TexelSize, _UnlitColorMap_MipInfo, result, needLinearToSRGB);
// TEMP!
// For now, the final blit in the backbuffer performs an sRGB write

32
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs


using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public enum DebugMipMapMode
{
None,
MipRatio,
MipCount,
MipCountReduction,
StreamingMipBudget,
StreamingMip
}
[Serializable]
public class MipMapDebugSettings
{
public DebugMipMapMode debugMipMapMode = DebugMipMapMode.None;
public bool IsDebugDisplayEnabled()
{
return debugMipMapMode != DebugMipMapMode.None;
}
public void OnValidate()
{
}
}
}

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs.hlsl


//
// This file was automatically generated. Please don't edit by hand.
//
#ifndef MIPMAPDEBUG_CS_HLSL
#define MIPMAPDEBUG_CS_HLSL
//
// UnityEngine.Experimental.Rendering.HDPipeline.DebugMipMapMode: static fields
//
#define DEBUGMIPMAPMODE_NONE (0)
#define DEBUGMIPMAPMODE_MIP_RATIO (1)
#define DEBUGMIPMAPMODE_MIP_COUNT (2)
#define DEBUGMIPMAPMODE_MIP_COUNT_REDUCTION (3)
#define DEBUGMIPMAPMODE_STREAMING_MIP_BUDGET (4)
#define DEBUGMIPMAPMODE_STREAMING_MIP (5)
#endif

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs.hlsl.meta


fileFormatVersion: 2
guid: b70bba64289151b40845a49cf9f32d18
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MipMapDebug.cs.meta


fileFormatVersion: 2
guid: 2f696bd7f8848384c985304f7e4f8fe8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存