浏览代码

[PlanarRelfection] Fixed projection for plaanr reflection, added debug mode for proxy volumes

/main
Frédéric Vauchelles 7 年前
当前提交
df67690c
共有 14 个文件被更改,包括 85 次插入46 次删除
  1. 10
      ScriptableRenderPipeline/Core/CoreRP/GeometryUtils.cs
  2. 17
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
  3. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  4. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
  5. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl
  7. 42
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebugPanel.cs
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  10. 25
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  11. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs
  12. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs
  13. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl
  14. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

10
ScriptableRenderPipeline/Core/CoreRP/GeometryUtils.cs


namespace UnityEngine.Experimental.Rendering
using System;
namespace UnityEngine.Experimental.Rendering
{
public static class GeometryUtils
{

var inversion = sourceProjection.inverse;
var cps = new Vector4(
(clipPlane.x > 0 ? 1 : 0) - (clipPlane.x < 0 ? 1 : 0),
(clipPlane.y > 0 ? 1 : 0) - (clipPlane.y < 0 ? 1 : 0),
Mathf.Sign(clipPlane.x),
Mathf.Sign(clipPlane.y),
1.0f,
1.0f);
var q = inversion * cps;

public static Matrix4x4 CalculateReflectionMatrix(Vector3 position, Vector3 normal)
{
return CalculateReflectionMatrix(Plane(position, normal));
return CalculateReflectionMatrix(Plane(position, normal.normalized));
}
public static Matrix4x4 CalculateReflectionMatrix(Vector4 plane)

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


0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
float2 ComputeNormalizedDeviceCoordinates(float3 position, float4x4 clipSpaceTransform = k_identity4x4)
float4 ComputeClipSpaceCoordinates(float3 position, float4x4 clipSpaceTransform = k_identity4x4)
{
float4 positionCS = mul(clipSpaceTransform, float4(position, 1.0));

positionCS.y = -positionCS.y;
#endif
return positionCS.xy * (rcp(positionCS.w) * 0.5) + 0.5;
return positionCS;
}
// Use case examples:
// (position = positionCS) => (clipSpaceTransform = use default)
// (position = positionVS) => (clipSpaceTransform = UNITY_MATRIX_P)
// (position = positionWS) => (clipSpaceTransform = UNITY_MATRIX_VP)
float2 ComputeNormalizedDeviceCoordinates(float3 position, float4x4 clipSpaceTransform = k_identity4x4)
{
float4 positionCS = ComputeClipSpaceCoordinates(position, clipSpaceTransform);
return positionCS.xy * (rcp(positionCS.w) * 0.5) + 0.5;
}
float4 ComputeClipSpacePosition(float2 positionNDC, float deviceDepth)

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


public static string kShadowMaxValueDebug = "Shadow Range Max Value";
public static string kLightingDebugMode = "Lighting Debug Mode";
public static string kOverrideSmoothnessDebug = "Override Smoothness";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";
public static string kDebugEnvironmentProxyDepthScale = "Debug Environment Proxy Depth Scale";
public static string kDebugLightingAlbedo = "Debug Lighting Albedo";
public static string kFullScreenDebugMode = "Fullscreen Debug Mode";
public static string kFullScreenDebugMip = "Fullscreen Debug Mip";

DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kSkyReflectionMipmapDebug, () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, LightLoop.TileClusterDebug>(kTileClusterDebug,() => lightingDebugSettings.tileClusterDebug, (value) => lightingDebugSettings.tileClusterDebug = (LightLoop.TileClusterDebug)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, LightLoop.TileClusterCategoryDebug>(kTileClusterCategoryDebug,() => lightingDebugSettings.tileClusterDebugByCategory, (value) => lightingDebugSettings.tileClusterDebugByCategory = (LightLoop.TileClusterCategoryDebug)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kDebugEnvironmentProxyDepthScale, () => lightingDebugSettings.environmentProxyDepthScale, value => lightingDebugSettings.environmentProxyDepthScale = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.1f, 50f));
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));

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


float4 _DebugLightingAlbedo; // xyz = albedo for diffuse, w unused
float4 _DebugLightingSmoothness; // x == bool override, y == override value
float4 _MousePixelCoord; // xy unorm, zw norm
float _DebugEnvironmentProxyDepthScale;
CBUFFER_END
TEXTURE2D(_DebugFont); // Debug font to write string in shader

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs


IndirectDiffuseOcclusionFromSsao,
IndirectDiffuseGtaoFromSsao,
IndirectSpecularOcclusionFromSsao,
IndirectSpecularGtaoFromSsao
IndirectSpecularGtaoFromSsao,
EnvironmentProxyVolume,
}
public enum ShadowMapDebugMode

public bool displaySkyReflection = false;
public float skyReflectionMipmap = 0.0f;
public float environmentProxyDepthScale = 20;
public LightLoop.TileClusterDebug tileClusterDebug = LightLoop.TileClusterDebug.None;
public LightLoop.TileClusterCategoryDebug tileClusterDebugByCategory = LightLoop.TileClusterCategoryDebug.Punctual;

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl


#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_GTAO_FROM_SSAO (6)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_OCCLUSION_FROM_SSAO (7)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_GTAO_FROM_SSAO (8)
#define DEBUGLIGHTINGMODE_ENVIRONMENT_PROXY_VOLUME (9)
#endif

42
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebugPanel.cs


DebugItem lightingDebugModeItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLightingDebugMode);
lightingDebugModeItem.handler.OnEditorGUI();
if ((DebugLightingMode)lightingDebugModeItem.GetValue() == DebugLightingMode.SpecularLighting)
switch ((DebugLightingMode)lightingDebugModeItem.GetValue())
EditorGUI.indentLevel++;
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessDebug);
overrideSmoothnessItem.handler.OnEditorGUI();
if ((bool)overrideSmoothnessItem.GetValue())
{
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessValueDebug).handler.OnEditorGUI();
}
EditorGUI.indentLevel--;
}
else if ((DebugLightingMode)lightingDebugModeItem.GetValue() == DebugLightingMode.DiffuseLighting)
{
EditorGUI.indentLevel++;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDebugLightingAlbedo).handler.OnEditorGUI();
EditorGUI.indentLevel--;
case DebugLightingMode.SpecularLighting:
{
EditorGUI.indentLevel++;
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessDebug);
overrideSmoothnessItem.handler.OnEditorGUI();
if ((bool)overrideSmoothnessItem.GetValue())
{
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessValueDebug).handler.OnEditorGUI();
}
EditorGUI.indentLevel--;
break;
}
case DebugLightingMode.DiffuseLighting:
{
EditorGUI.indentLevel++;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDebugLightingAlbedo).handler.OnEditorGUI();
EditorGUI.indentLevel--;
break;
}
case DebugLightingMode.EnvironmentProxyVolume:
{
++EditorGUI.indentLevel;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDebugEnvironmentProxyDepthScale).handler.OnEditorGUI();
--EditorGUI.indentLevel;
break;
}
}
var fullScreenDebugModeHandler = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kFullScreenDebugMode);

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _MousePixelCoord = Shader.PropertyToID("_MousePixelCoord");
public static readonly int _DebugFont = Shader.PropertyToID("_DebugFont");
public static readonly int _DebugEnvironmentProxyDepthScale = Shader.PropertyToID("_DebugEnvironmentProxyDepthScale");
public static readonly int _DebugViewMaterial = Shader.PropertyToID("_DebugViewMaterial");
public static readonly int _DebugLightingMode = Shader.PropertyToID("_DebugLightingMode");
public static readonly int _DebugLightingAlbedo = Shader.PropertyToID("_DebugLightingAlbedo");

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


{
LightingDebugSettings lightingDebug = debugDisplaySettings.lightingDebugSettings;
if (lightingDebug.debugLightingMode == DebugLightingMode.EnvironmentProxyVolume)
cmd.SetGlobalFloat(HDShaderIDs._DebugEnvironmentProxyDepthScale, lightingDebug.environmentProxyDepthScale);
using (new ProfilingSample(cmd, "Tiled/cluster Lighting Debug", CustomSamplerId.TPTiledLightingDebug.GetSampler()))
{
if (lightingDebug.tileClusterDebug != LightLoop.TileClusterDebug.None)

25
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


#define SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES 0
#define SINGLE_PASS_CONTEXT_SAMPLE_SKY 1
#ifdef DEBUG_DISPLAY
float4 ApplyDebugProjectionVolume(float4 color, float3 texCoord, float scale)
{
float l = length(texCoord);
l = pow(l / (1 + l), scale);
return float4(l.xxx * 0.7 + color.rgb * 0.3, color.a);
}
#endif
// Note: index is whatever the lighting architecture want, it can contain information like in which texture to sample (in case we have a compressed BC6H texture and an uncompressed for real time reflection ?)
// EnvIndex can also be use to fetch in another array of struct (to atlas information etc...).
// Cubemap : texCoord = direction vector

if (cacheType == ENVCACHETYPE_TEXTURE2D)
{
//_Env2DCaptureVP is in capture space
float2 ndc = ComputeNormalizedDeviceCoordinates(texCoord, _Env2DCaptureVP[index]);
float4 color = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc, index, 0);
// Discard pixels out of oblique projection
// We only check RGB because the texture may have BC6H compression
color.a = any(ndc < 0) || any(ndc > 1) || all(color.rgb >= 1000) ? 0 : 1;
float4 ndc = ComputeClipSpaceCoordinates(texCoord, _Env2DCaptureVP[index]);
ndc *= rcp(ndc.w);
ndc.xy = ndc.xy * 0.5 + 0.5;
float4 color = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc.xy, index, 0);
color.a = any(ndc.xyz < 0) || any(ndc.xyz > 1) ? 0 : 1;
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_ENVIRONMENT_PROXY_VOLUME)
return ApplyDebugProjectionVolume(color, texCoord, _DebugEnvironmentProxyDepthScale);
#endif
return color;
}
else if (cacheType == ENVCACHETYPE_CUBEMAP)

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs


get
{
return m_ProxyVolumeReference != null
? m_ProxyVolumeReference.proxyVolume.boxSize
? m_ProxyVolumeReference.proxyVolume.boxSize * 0.5f
: influenceVolume.boxBaseSize;
}
}

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs


{
class ReflectionSystemInternal
{
// -FLT_MAX in hlsl
static readonly Color k_DiscardedColor = new Color(1000, 1000, 1000, 1000);
static Camera s_RenderCamera = null;
static HDAdditionalCameraData s_RenderCameraData;

camera.fieldOfView = fov;
camera.aspect = aspect;
camera.clearFlags = clearFlags;
// TODO: Find a cleaner way to discard pixel out of frustrum
camera.backgroundColor = k_DiscardedColor;
camera.backgroundColor = camera.backgroundColor;
camera.projectionMatrix = projection;
camera.worldToCameraMatrix = worldToCamera;

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl


float metallic;
float coatMask;
float3 specularColor;
int diffusionProfile;
uint diffusionProfile;
float subsurfaceMask;
float thickness;
float3 tangentWS;

float3 normalWS;
float perceptualRoughness;
float coatMask;
uint diffusionProfile;
int diffusionProfile;
float subsurfaceMask;
float thickness;
bool useThickObjectMode;

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


#include "CoreRP/ShaderLibrary/VolumeRendering.hlsl"
#include "../../Lighting/VolumeProjection.hlsl"
//#define ENV_PROJECTION_USE_LIGHTSPACE
//-----------------------------------------------------------------------------
// Texture and constant buffer declaration
//-----------------------------------------------------------------------------

float3 positionLS = WorldToLightPosition(lightData, worldToLS, positionWS);
float3 dirLS = mul(R, worldToLS);
#if defined(ENV_PROJECTION_USE_LIGHTSPACE)
// Projection and influence share the space
float3x3 worldToPS = worldToLS;
float3 positionPS = positionLS;
float3 dirPS = dirLS;
#else
#endif
float projectionDistance = 0;
// 1. First process the projection

正在加载...
取消
保存