浏览代码

Refactor all the code of colorpicking to make a more general version

/main
sebastienlagarde 7 年前
当前提交
6c8462a0
共有 17 个文件被更改,包括 390 次插入204 次删除
  1. 19
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  2. 22
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
  4. 70
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebugPanel.cs
  7. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
  8. 250
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  9. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  10. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  11. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  12. 39
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/ColorPickerDebug.cs
  13. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/ColorPickerDebug.cs.hlsl
  14. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/ColorPickerDebug.cs.hlsl.meta
  15. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/ColorPickerDebug.cs.meta
  16. 120
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader
  17. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader.meta

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


// Lighting
MinLightingFullScreenDebug,
LuxMeterBuffer,
SSAO,
DeferredShadows,
PreRefractionColorPyramid,

// Rendering
MinRenderingFullScreenDebug,
HDRBuffer,
MotionVectors,
NanTracker,
MaxRenderingFullScreenDebug

public static string kOverrideSmoothnessDebug = "Override Smoothness";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";
public static string kDebugLightingAlbedo = "Debug Lighting Albedo";
public static string kLuxMeterThreshold0Debug = "Lux Range Threshold 0";
public static string kLuxMeterThreshold1Debug = "Lux Range Threshold 1";
public static string kLuxMeterThreshold2Debug = "Lux Range Threshold 2";
public static string kLuxMeterThreshold3Debug = "Lux Range Threshold 3";
public static string kFullScreenDebugMode = "Fullscreen Debug Mode";
public static string kFullScreenDebugMip = "Fullscreen Debug Mip";
public static string kDisplaySkyReflectionDebug = "Display Sky Reflection";

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

DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kOverrideSmoothnessDebug, () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kOverrideSmoothnessValueDebug, () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, Color>(kDebugLightingAlbedo, () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kLuxMeterThreshold0Debug, () => lightingDebugSettings.kLuxMeterThreshold0Debug, (value) => lightingDebugSettings.kLuxMeterThreshold0Debug = (float)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kLuxMeterThreshold1Debug, () => lightingDebugSettings.kLuxMeterThreshold1Debug, (value) => lightingDebugSettings.kLuxMeterThreshold1Debug = (float)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kLuxMeterThreshold2Debug, () => lightingDebugSettings.kLuxMeterThreshold2Debug, (value) => lightingDebugSettings.kLuxMeterThreshold2Debug = (float)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kLuxMeterThreshold3Debug, () => lightingDebugSettings.kLuxMeterThreshold3Debug, (value) => lightingDebugSettings.kLuxMeterThreshold3Debug = (float)value);
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", kDisplaySkyReflectionDebug, () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
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<DebugMipMapMode>("Rendering", "MipMaps", () => mipMapDebugSettings.debugMipMapMode, (value) => SetMipMapMode((DebugMipMapMode)value));
DebugMenuManager.instance.AddDebugItem<ColorPickerDebugMode>("Rendering", ColorPickerDebugSettings.kColorPickerDebugMode, () => (int)colorPickerDebugSettings.colorPickerMode, (value) => colorPickerDebugSettings.colorPickerMode = (ColorPickerDebugMode)value);
DebugMenuManager.instance.AddDebugItem<float>("Rendering", ColorPickerDebugSettings.kColorPickerThreshold0Debug, () => colorPickerDebugSettings.colorThreshold0, (value) => colorPickerDebugSettings.colorThreshold0 = (float)value);
DebugMenuManager.instance.AddDebugItem<float>("Rendering", ColorPickerDebugSettings.kColorPickerThreshold1Debug, () => colorPickerDebugSettings.colorThreshold1, (value) => colorPickerDebugSettings.colorThreshold1 = (float)value);
DebugMenuManager.instance.AddDebugItem<float>("Rendering", ColorPickerDebugSettings.kColorPickerThreshold2Debug, () => colorPickerDebugSettings.colorThreshold2, (value) => colorPickerDebugSettings.colorThreshold2 = (float)value);
DebugMenuManager.instance.AddDebugItem<float>("Rendering", ColorPickerDebugSettings.kColorPickerThreshold3Debug, () => colorPickerDebugSettings.colorThreshold3, (value) => colorPickerDebugSettings.colorThreshold3 = (float)value);
DebugMenuManager.instance.AddDebugItem<Color>("Rendering", ColorPickerDebugSettings.kColorPickerFontColor, () => colorPickerDebugSettings.fontColor, (value) => colorPickerDebugSettings.fontColor = (Color)value);
}
public void OnValidate()

22
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl


//
#define FULLSCREENDEBUGMODE_NONE (0)
#define FULLSCREENDEBUGMODE_MIN_LIGHTING_FULL_SCREEN_DEBUG (1)
#define FULLSCREENDEBUGMODE_LUX_METER_BUFFER (2)
#define FULLSCREENDEBUGMODE_SSAO (3)
#define FULLSCREENDEBUGMODE_DEFERRED_SHADOWS (4)
#define FULLSCREENDEBUGMODE_PRE_REFRACTION_COLOR_PYRAMID (5)
#define FULLSCREENDEBUGMODE_DEPTH_PYRAMID (6)
#define FULLSCREENDEBUGMODE_FINAL_COLOR_PYRAMID (7)
#define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (8)
#define FULLSCREENDEBUGMODE_MIN_RENDERING_FULL_SCREEN_DEBUG (9)
#define FULLSCREENDEBUGMODE_HDRBUFFER (10)
#define FULLSCREENDEBUGMODE_MOTION_VECTORS (11)
#define FULLSCREENDEBUGMODE_NAN_TRACKER (12)
#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (13)
#define FULLSCREENDEBUGMODE_SSAO (2)
#define FULLSCREENDEBUGMODE_DEFERRED_SHADOWS (3)
#define FULLSCREENDEBUGMODE_PRE_REFRACTION_COLOR_PYRAMID (4)
#define FULLSCREENDEBUGMODE_DEPTH_PYRAMID (5)
#define FULLSCREENDEBUGMODE_FINAL_COLOR_PYRAMID (6)
#define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (7)
#define FULLSCREENDEBUGMODE_MIN_RENDERING_FULL_SCREEN_DEBUG (8)
#define FULLSCREENDEBUGMODE_MOTION_VECTORS (9)
#define FULLSCREENDEBUGMODE_NAN_TRACKER (10)
#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (11)
#endif

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


#include "MaterialDebug.cs.hlsl"
#include "LightingDebug.cs.hlsl"
#include "MipMapDebug.cs.hlsl"
#include "ColorPickerDebug.cs.hlsl"
// Set of parameters available when switching to debug shader mode
int _DebugLightingMode; // Match enum DebugLightingMode

float4 _DebugLuxMeterParam; // 4 increasing threshold
float4 _DebugLightingSmoothness; // x == bool override, y == override value
float4 _MousePixelCoord; // xy unorm, zw norm

70
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader


#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../ShaderVariables.hlsl"
#include "../Debug/DebugDisplay.cs.hlsl"
#include "../Debug/DebugDisplay.hlsl"
TEXTURE2D(_DebugFullScreenTexture);
SAMPLER(sampler_DebugFullScreenTexture);

}
// <<<
float4 DisplayPixelInformationAtMousePosition(Varyings input, float4 result, float4 mouseResult)
{
if (_MousePixelCoord.z >= 0.0 && _MousePixelCoord.z <= 1.0 && _MousePixelCoord.w >= 0 && _MousePixelCoord.w <= 1.0)
{
// Display message offset:
int displayTextOffsetX = 1.5 * DEBUG_FONT_TEXT_WIDTH;
#if UNITY_UV_STARTS_AT_TOP
int displayTextOffsetY = -DEBUG_FONT_TEXT_HEIGHT;
#else
int displayTextOffsetY = DEBUG_FONT_TEXT_HEIGHT;
#endif
uint2 displayUnormCoord = uint2(_MousePixelCoord.x + displayTextOffsetX, _MousePixelCoord.y + displayTextOffsetY);
uint2 unormCoord = input.positionCS.xy;
float3 fontColor = float3(1.0, 0.0, 0.0);
DrawFloat(mouseResult.x, fontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawFloat(mouseResult.y, fontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawFloat(mouseResult.z, fontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawFloat(mouseResult.w, fontColor, unormCoord, displayUnormCoord, result.rgb);
}
return result;
}
float4 GetResult(Varyings input, float2 coord)
float4 Frag(Varyings input) : SV_Target
return 1.0f - SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord).xxxx;
return 1.0f - SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, input.texcoord).xxxx;
#if UNITY_UV_STARTS_AT_TOP
#if UNITY_UV_STARTS_AT_TOP
#endif
#endif
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord);
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, input.texcoord);
if (any(isnan(color)) || any(isinf(color)))
{

}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_MOTION_VECTORS)
{
float2 mv = SampleMotionVectors(coord);
float2 mv = SampleMotionVectors(input.texcoord);
// Background color intensity - keep this low unless you want to make your eyes bleed
const float kIntensity = 0.15;

}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_DEFERRED_SHADOWS)
{
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord);
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, input.texcoord);
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord);
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, input.texcoord);
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord);
float4 color = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, input.texcoord);
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_HDRBUFFER)
{
float4 result = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord);
float4 mouseResult = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, _MousePixelCoord.zw);
return DisplayPixelInformationAtMousePosition(input, result, mouseResult);
}
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_LUX_METER_BUFFER)
{
float4 result = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, coord);
result.rgb = GetColorCodeFunction(result.x, _DebugLuxMeterParam);
float4 mouseResult = SAMPLE_TEXTURE2D(_DebugFullScreenTexture, sampler_DebugFullScreenTexture, _MousePixelCoord.zw);
return DisplayPixelInformationAtMousePosition(input, result, mouseResult);
}
}
float4 Frag(Varyings input) : SV_Target
{
float4 result = GetResult(input, input.texcoord);
return result;
}
ENDHLSL

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


public bool overrideSmoothness = false;
public float overrideSmoothnessValue = 0.5f;
public Color debugLightingAlbedo = new Color(0.5f, 0.5f, 0.5f);
public float kLuxMeterThreshold0Debug = 0.0f;
public float kLuxMeterThreshold1Debug = 200.0f;
public float kLuxMeterThreshold2Debug = 9000.0f;
public float kLuxMeterThreshold3Debug = 10000.0f;
public bool displaySkyReflection = false;
public float skyReflectionMipmap = 0.0f;

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


m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDebugLightingAlbedo).handler.OnEditorGUI();
EditorGUI.indentLevel--;
}
else if ((DebugLightingMode)lightingDebugModeItem.GetValue() == DebugLightingMode.LuxMeter)
{
EditorGUI.indentLevel++;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLuxMeterThreshold0Debug).handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLuxMeterThreshold1Debug).handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLuxMeterThreshold2Debug).handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLuxMeterThreshold3Debug).handler.OnEditorGUI();
EditorGUI.indentLevel--;
}
var fullScreenDebugModeHandler = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kFullScreenDebugMode);
fullScreenDebugModeHandler.handler.OnEditorGUI();

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs


newAsset.debugViewMaterialGBufferShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugViewMaterialGBuffer.Shader");
newAsset.debugViewTilesShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugViewTiles.Shader");
newAsset.debugFullScreenShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugFullScreen.Shader");
newAsset.debugColorPickerShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugColorPicker.Shader");
newAsset.deferredShader = Load<Shader>(HDRenderPipelinePath + "Lighting/Deferred.Shader");
newAsset.gaussianPyramidCS = Load<ComputeShader>(PostProcessingPath + "Shaders/Builtins/GaussianDownsample.compute");

250
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


};
static readonly RenderQueueRange k_RenderQueue_PreRefraction = new RenderQueueRange { min = (int)HDRenderQueue.PreRefraction, max = (int)HDRenderQueue.Transparent - 1 };
static readonly RenderQueueRange k_RenderQueue_Transparent = new RenderQueueRange { min = (int)HDRenderQueue.Transparent, max = (int)HDRenderQueue.Overlay - 1};
static readonly RenderQueueRange k_RenderQueue_Transparent = new RenderQueueRange { min = (int)HDRenderQueue.Transparent, max = (int)HDRenderQueue.Overlay - 1 };
static readonly RenderQueueRange k_RenderQueue_AllTransparent = new RenderQueueRange { min = (int)HDRenderQueue.PreRefraction, max = (int)HDRenderQueue.Overlay - 1 };
readonly HDRenderPipelineAsset m_Asset;

Material m_currentDebugViewMaterialGBuffer;
Material m_DebugDisplayLatlong;
Material m_DebugFullScreen;
Material m_DebugColorPicker;
Material m_Blit;
Material m_ErrorMaterial;

RenderTargetIdentifier m_CameraStencilBufferCopyRT;
// The pass "SRPDefaultUnlit" is a fall back to legacy unlit rendering and is required to support unity 2d + unity UI that render in the scene.
ShaderPassName[] m_ForwardAndForwardOnlyPassNames = { new ShaderPassName(), new ShaderPassName(), HDShaderPassNames.s_SRPDefaultUnlitName};
ShaderPassName[] m_ForwardOnlyPassNames = { new ShaderPassName(), HDShaderPassNames.s_SRPDefaultUnlitName};
ShaderPassName[] m_ForwardAndForwardOnlyPassNames = { new ShaderPassName(), new ShaderPassName(), HDShaderPassNames.s_SRPDefaultUnlitName };
ShaderPassName[] m_ForwardOnlyPassNames = { new ShaderPassName(), HDShaderPassNames.s_SRPDefaultUnlitName };
ShaderPassName[] m_AllTransparentPassNames = { HDShaderPassNames.s_TransparentBackfaceName,
HDShaderPassNames.s_ForwardOnlyName,

[Flags]
public enum StencilBitMask
{
Clear = 0, // 0x0
LightingMask = 7, // 0x7 - 3 bit
ObjectVelocity = 128, // 0x80 - 1 bit
All = 255 // 0xFF - 8 bit
Clear = 0, // 0x0
LightingMask = 7, // 0x7 - 3 bit
ObjectVelocity = 128, // 0x80 - 1 bit
All = 255 // 0xFF - 8 bit
}
RenderStateBlock m_DepthStateOpaque;

FrameSettings m_FrameSettings; // Init every frame
// For debug
int m_DebugColorPickerRT;
int m_DebugFullScreenTempRT;
bool m_FullScreenDebugPushed;

// whereas it work. Don't know what is happening, DebugDisplay use the same code and name is correct there.
// Debug.Assert(m_DeferredMaterial != null);
m_CameraColorBuffer = HDShaderIDs._CameraColorTexture;
m_CameraColorBufferRT = new RenderTargetIdentifier(m_CameraColorBuffer);
m_CameraSssDiffuseLightingBuffer = HDShaderIDs._CameraSssDiffuseLightingBuffer;
m_CameraColorBuffer = HDShaderIDs._CameraColorTexture;
m_CameraColorBufferRT = new RenderTargetIdentifier(m_CameraColorBuffer);
m_CameraSssDiffuseLightingBuffer = HDShaderIDs._CameraSssDiffuseLightingBuffer;
m_CameraSssDiffuseLightingBufferRT = new RenderTargetIdentifier(m_CameraSssDiffuseLightingBuffer);
m_SSSBufferManager.Build(asset);

m_DebugDisplaySettings.RegisterDebug();
FrameSettings.RegisterDebug("Default Camera", m_Asset.GetFrameSettings());
m_DebugColorPickerRT = HDShaderIDs._DebugColorPickerTexture;
m_DebugFullScreenTempRT = HDShaderIDs._DebugFullScreenTexture;
// For debugging

m_DebugViewMaterialGBufferShadowMask.EnableKeyword("SHADOWS_SHADOWMASK");
m_DebugDisplayLatlong = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.debugDisplayLatlongShader);
m_DebugFullScreen = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.debugFullScreenShader);
m_DebugColorPicker = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.debugColorPickerShader);
m_Blit = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.blit);
m_ErrorMaterial = CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader");
}

CoreUtils.Destroy(m_DebugViewMaterialGBufferShadowMask);
CoreUtils.Destroy(m_DebugDisplayLatlong);
CoreUtils.Destroy(m_DebugFullScreen);
CoreUtils.Destroy(m_DebugColorPicker);
CoreUtils.Destroy(m_Blit);
CoreUtils.Destroy(m_ErrorMaterial);

{
// For now we consider only PS4 to be able to read from a bound depth buffer.
// TODO: test/implement for other platforms.
return SystemInfo.graphicsDeviceType != GraphicsDeviceType.PlayStation4 &&
return SystemInfo.graphicsDeviceType != GraphicsDeviceType.PlayStation4 &&
SystemInfo.graphicsDeviceType != GraphicsDeviceType.XboxOne &&
SystemInfo.graphicsDeviceType != GraphicsDeviceType.XboxOneD3D12;
}

using (new ProfilingSample(cmd, "Volume Update", CustomSamplerId.VolumeUpdate.GetSampler()))
{
LayerMask layerMask = -1;
if(additionalCameraData != null)
if (additionalCameraData != null)
{
layerMask = additionalCameraData.volumeLayerMask;
}

// This is arbitrary and should be editable in the scene view somehow.
if(camera.cameraType == CameraType.SceneView)
if (camera.cameraType == CameraType.SceneView)
{
layerMask = (-1 & ~m_Asset.renderPipelineSettings.lightLoopSettings.skyLightingOverrideLayerMask);
}

continue;
}
m_LightLoop.UpdateCullingParameters( ref cullingParams );
m_LightLoop.UpdateCullingParameters(ref cullingParams);
#if UNITY_EDITOR
// emit scene view UI

}
#endif
// decal system needs to be updated with current camera
if (m_FrameSettings.enableDBuffer)
DecalSystem.instance.BeginCull(camera);
if (m_FrameSettings.enableDBuffer)
DecalSystem.instance.BeginCull(camera);
CullResults.Cull(ref cullingParams, renderContext,ref m_CullResults);
CullResults.Cull(ref cullingParams, renderContext, ref m_CullResults);
}
m_DbufferManager.vsibleDecalCount = 0;

}
ConfigureForShadowMask(enableBakeShadowMask, cmd);
InitAndClearBuffer(hdCamera, enableBakeShadowMask, cmd);
InitAndClearBuffer(hdCamera, enableBakeShadowMask, cmd);
bool forcePrepassForDecals = m_DbufferManager.vsibleDecalCount > 0;
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, forcePrepassForDecals);

if (m_CurrentDebugDisplaySettings.IsDebugMaterialDisplayEnabled())
{
RenderDebugViewMaterial(m_CullResults, hdCamera, renderContext, cmd);
PushColorPickerDebugTexture(cmd, m_CameraColorBufferRT, hdCamera);
}
else
{

cmd.ReleaseTemporaryRT(m_DeferredShadowBuffer);
CoreUtils.CreateCmdTemporaryRT(cmd, m_DeferredShadowBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, true);
m_LightLoop.RenderDeferredDirectionalShadow(hdCamera, m_DeferredShadowBufferRT, GetDepthTexture(), cmd);
PushFullScreenDebugTexture(cmd, m_DeferredShadowBuffer, hdCamera, renderContext, FullScreenDebugMode.DeferredShadows);
PushFullScreenDebugTexture(cmd, m_DeferredShadowBuffer, hdCamera, FullScreenDebugMode.DeferredShadows);
// TODO: Move this code inside LightLoop
// TODO: Move this code inside LightLoop
if (m_LightLoop.GetFeatureVariantsEnabled())
{
// For material classification we use compute shader and so can't read into the stencil, so prepare it.

RenderForward(m_CullResults, hdCamera, renderContext, cmd, ForwardPass.PreRefraction);
RenderForwardError(m_CullResults, camera, renderContext, cmd, ForwardPass.PreRefraction);
RenderGaussianPyramidColor(camera, cmd, renderContext, FullScreenDebugMode.PreRefractionColorPyramid);
RenderGaussianPyramidColor(camera, cmd, renderContext, true);
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward(m_CullResults, hdCamera, renderContext, cmd, ForwardPass.Transparent);

RenderTransparentDepthPostpass(m_CullResults, camera, renderContext, cmd, ForwardPass.Transparent);
PushFullScreenDebugTexture(cmd, m_CameraColorBuffer, hdCamera, renderContext, FullScreenDebugMode.NanTracker);
PushFullScreenDebugTexture(cmd, m_CameraColorBuffer, hdCamera, renderContext, FullScreenDebugMode.HDRBuffer);
PushFullScreenDebugTexture(cmd, m_CameraColorBuffer, hdCamera, renderContext, FullScreenDebugMode.LuxMeterBuffer);
PushFullScreenDebugTexture(cmd, m_CameraColorBuffer, hdCamera, FullScreenDebugMode.NanTracker);
RenderGaussianPyramidColor(camera, cmd, renderContext, FullScreenDebugMode.FinalColorPyramid);
RenderGaussianPyramidColor(camera, cmd, renderContext, false);
PushColorPickerDebugTexture(cmd, m_CameraColorBufferRT, hdCamera);
// Final blit
if (m_FrameSettings.enablePostprocess && CoreUtils.IsPostProcessingActive(postProcessLayer))

} // For each camera
}
void RenderOpaqueRenderList(CullResults cull,
Camera camera,
void RenderOpaqueRenderList(CullResults cull,
Camera camera,
CommandBuffer cmd,
ShaderPassName passName,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
CommandBuffer cmd,
ShaderPassName passName,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
void RenderOpaqueRenderList(CullResults cull,
Camera camera,
void RenderOpaqueRenderList(CullResults cull,
Camera camera,
CommandBuffer cmd,
ShaderPassName[] passNames,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
CommandBuffer cmd,
ShaderPassName[] passNames,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
{
if (!m_FrameSettings.enableOpaqueObjects)
return;

renderQueueRange = inRenderQueueRange == null ? RenderQueueRange.opaque : inRenderQueueRange.Value
};
if(stateBlock == null)
if (stateBlock == null)
void RenderTransparentRenderList(CullResults cull,
Camera camera,
void RenderTransparentRenderList(CullResults cull,
Camera camera,
CommandBuffer cmd,
ShaderPassName passName,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
CommandBuffer cmd,
ShaderPassName passName,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
{
m_SinglePassName[0] = passName;
RenderTransparentRenderList(cull, camera, renderContext, cmd, m_SinglePassName,

void RenderTransparentRenderList(CullResults cull,
Camera camera,
void RenderTransparentRenderList(CullResults cull,
Camera camera,
CommandBuffer cmd,
ShaderPassName[] passNames,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null
CommandBuffer cmd,
ShaderPassName[] passNames,
RendererConfiguration rendererConfiguration = 0,
RenderQueueRange? inRenderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null
)
{
if (!m_FrameSettings.enableTransparentObjects)

renderQueueRange = inRenderQueueRange == null ? k_RenderQueue_AllTransparent : inRenderQueueRange.Value
};
if(stateBlock == null)
if (stateBlock == null)
renderContext.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);
else
renderContext.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings, stateBlock.Value);

using (new ProfilingSample(cmd, addAlphaTestedOnly ? "Depth Prepass alpha test" : "Depth Prepass", CustomSamplerId.DepthPrepass.GetSampler()))
{
CoreUtils.SetRenderTarget(cmd, m_CameraDepthStencilBufferRT);
if (forcePrepass || (addFullDepthPrepass && !addAlphaTestedOnly)) // Always true in case of forward rendering, use in case of deferred rendering if requesting a full depth prepass
if (forcePrepass || (addFullDepthPrepass && !addAlphaTestedOnly)) // Always true in case of forward rendering, use in case of deferred rendering if requesting a full depth prepass
{
// We render first the opaque object as opaque alpha tested are more costly to render and could be reject by early-z (but not Hi-z as it is disable with clip instruction)
// This is handled automatically with the RenderQueue value (OpaqueAlphaTested have a different value and thus are sorted after Opaque)

{
if (m_FrameSettings.enableDepthPrepassWithDeferredRendering)
{
var rangeOpaqueNoAlphaTest = new RenderQueueRange { min = (int)RenderQueue.Geometry, max = (int)RenderQueue.AlphaTest - 1 };
var rangeOpaqueAlphaTest = new RenderQueueRange { min = (int)RenderQueue.AlphaTest, max = (int)RenderQueue.GeometryLast - 1 };
var rangeOpaqueNoAlphaTest = new RenderQueueRange { min = (int)RenderQueue.Geometry, max = (int)RenderQueue.AlphaTest - 1 };
var rangeOpaqueAlphaTest = new RenderQueueRange { min = (int)RenderQueue.AlphaTest, max = (int)RenderQueue.GeometryLast - 1 };
// When using depth prepass for opaque alpha test only we need to use regular depth test for normal opaque objects.
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, rangeOpaqueNoAlphaTest, m_FrameSettings.enableAlphaTestOnlyInDeferredPrepass ? m_DepthStateOpaque : m_DepthStateOpaqueWithPrepass);

cmd.SetGlobalTexture(HDShaderIDs._MainDepthTexture, GetDepthTexture());
CoreUtils.SetRenderTarget(cmd, m_DbufferManager.GetDBuffers(), m_CameraDepthStencilBufferRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
DecalSystem.instance.Render(renderContext, camera, cmd);
DecalSystem.instance.Render(renderContext, camera, cmd);
}
}

CoreUtils.CreateCmdTemporaryRT(cmd, HDShaderIDs._AmbientOcclusionTexture, hdCamera.renderTextureDesc, 0, FilterMode.Bilinear, RenderTextureFormat.R8, RenderTextureReadWrite.Linear, msaaSamples: 1, enableRandomWrite: true);
postProcessLayer.BakeMSVOMap(cmd, camera, HDShaderIDs._AmbientOcclusionTexture, GetDepthTexture(), true);
cmd.SetGlobalVector(HDShaderIDs._AmbientOcclusionParam, new Vector4(settings.color.value.r, settings.color.value.g, settings.color.value.b, settings.directLightingStrength.value));
PushFullScreenDebugTexture(cmd, HDShaderIDs._AmbientOcclusionTexture, hdCamera, renderContext, FullScreenDebugMode.SSAO);
PushFullScreenDebugTexture(cmd, HDShaderIDs._AmbientOcclusionTexture, hdCamera, FullScreenDebugMode.SSAO);
return;
}
}

void UpdateSkyEnvironment(HDCamera hdCamera, CommandBuffer cmd)
{
m_SkyManager.UpdateEnvironment(hdCamera,m_LightLoop.GetCurrentSunLight(), cmd);
m_SkyManager.UpdateEnvironment(hdCamera, m_LightLoop.GetCurrentSunLight(), cmd);
}
void RenderSky(HDCamera hdCamera, CommandBuffer cmd)

CoreUtils.DrawFullScreen(cmd, m_CameraMotionVectorsMaterial, m_VelocityBufferRT, m_CameraDepthStencilBufferRT, null, 0);
PushFullScreenDebugTexture(cmd, m_VelocityBuffer, hdcamera, renderContext, FullScreenDebugMode.MotionVectors);
PushFullScreenDebugTexture(cmd, m_VelocityBuffer, hdcamera, FullScreenDebugMode.MotionVectors);
void RenderGaussianPyramidColor(Camera camera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
void RenderGaussianPyramidColor(Camera camera, CommandBuffer cmd, ScriptableRenderContext renderContext, bool isPreRefraction)
if (debugMode == FullScreenDebugMode.PreRefractionColorPyramid)
if (isPreRefraction)
else if (debugMode == FullScreenDebugMode.FinalColorPyramid)
else
{
// TODO: This final Gaussian pyramid can be reuse by Bloom and SSR in the future, so disable it only if there is no postprocess AND no distortion
if (!m_FrameSettings.enableDistortion && !m_FrameSettings.enablePostprocess && !m_FrameSettings.enableSSR)

var colorPyramidDesc = m_GaussianPyramidColorBufferDesc;
var pyramidSideSize = GetPyramidSize(colorPyramidDesc);
// The gaussian pyramid compute works in blocks of 8x8 so make sure the last lod has a
// The Gaussian pyramid compute works in blocks of 8x8 so make sure the last lod has a
// minimum size of 8x8
int lodCount = Mathf.FloorToInt(Mathf.Log(pyramidSideSize, 2f) - 3f);
if (lodCount > HDShaderIDs._GaussianPyramidColorMips.Length)

last = HDShaderIDs._GaussianPyramidColorMips[i + 1];
}
PushFullScreenDebugTextureMip(cmd, m_GaussianPyramidColorBufferRT, lodCount, m_GaussianPyramidColorBufferDesc, debugMode);
PushFullScreenDebugTextureMip(cmd, m_GaussianPyramidColorBufferRT, lodCount, m_GaussianPyramidColorBufferDesc, isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
cmd.SetGlobalTexture(HDShaderIDs._GaussianPyramidColorTexture, m_GaussianPyramidColorBuffer);

{
using (new ProfilingSample(cmd, "Post-processing", CustomSamplerId.PostProcessing.GetSampler()))
{
// Note: Here we don't use GetDepthTexture() to get the depth texture but m_CameraDepthStencilBuffer as the Forward transparent pass can
// write extra data to deal with DOF/MB
cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, m_CameraDepthStencilBuffer);
cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, m_VelocityBufferRT);
// Note: Here we don't use GetDepthTexture() to get the depth texture but m_CameraDepthStencilBuffer as the Forward transparent pass can
// write extra data to deal with DOF/MB
cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, m_CameraDepthStencilBuffer);
cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, m_VelocityBufferRT);
var context = hdcamera.postprocessRenderContext;
context.Reset();
context.source = m_CameraColorBufferRT;
context.destination = BuiltinRenderTextureType.CameraTarget;
context.command = cmd;
context.camera = hdcamera.camera;
context.sourceFormat = RenderTextureFormat.ARGBHalf;
context.flip = true;
var context = hdcamera.postprocessRenderContext;
context.Reset();
context.source = m_CameraColorBufferRT;
context.destination = BuiltinRenderTextureType.CameraTarget;
context.command = cmd;
context.camera = hdcamera.camera;
context.sourceFormat = RenderTextureFormat.ARGBHalf;
context.flip = true;
layer.Render(context);
}
layer.Render(context);
}
public void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd)
{

var debugAlbedo = new Vector4(lightingDebugSettings.debugLightingAlbedo.r, lightingDebugSettings.debugLightingAlbedo.g, lightingDebugSettings.debugLightingAlbedo.b, 0.0f);
var debugSmoothness = new Vector4(lightingDebugSettings.overrideSmoothness ? 1.0f : 0.0f, lightingDebugSettings.overrideSmoothnessValue, 0.0f, 0.0f);
var luxMeterParam = new Vector4(lightingDebugSettings.kLuxMeterThreshold0Debug, lightingDebugSettings.kLuxMeterThreshold1Debug, lightingDebugSettings.kLuxMeterThreshold2Debug, lightingDebugSettings.kLuxMeterThreshold3Debug);
cmd.SetGlobalVector(HDShaderIDs._DebugLuxMeterParam, luxMeterParam);
cmd.SetGlobalVector(HDShaderIDs._DebugLightingSmoothness, debugSmoothness);
Vector2 mousePixelCoord = MousePositionDebug.instance.GetMousePosition(hdCamera.screenSize.y);

cmd.SetGlobalTexture(HDShaderIDs._DebugFont, m_Asset.renderPipelineResources.debugFontTexture);
}
public void PushFullScreenDebugTexture(CommandBuffer cb, RenderTargetIdentifier textureID, HDCamera hdCamera, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
public void PushColorPickerDebugTexture(CommandBuffer cmd, RenderTargetIdentifier textureID, HDCamera hdCamera)
{
if (m_CurrentDebugDisplaySettings.colorPickerDebugSettings.colorPickerMode != ColorPickerDebugMode.None)
{
cmd.ReleaseTemporaryRT(m_DebugColorPickerRT);
CoreUtils.CreateCmdTemporaryRT(cmd, m_DebugColorPickerRT, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.Blit(textureID, m_DebugColorPickerRT);
}
}
public void PushFullScreenDebugTexture(CommandBuffer cmd, RenderTargetIdentifier textureID, HDCamera hdCamera, FullScreenDebugMode debugMode)
m_FullScreenDebugPushed = true; // We need this flag because otherwise if no fullscreen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
cb.ReleaseTemporaryRT(m_DebugFullScreenTempRT);
CoreUtils.CreateCmdTemporaryRT(cb, m_DebugFullScreenTempRT, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cb.Blit(textureID, m_DebugFullScreenTempRT);
m_FullScreenDebugPushed = true; // We need this flag because otherwise if no full screen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
cmd.ReleaseTemporaryRT(m_DebugFullScreenTempRT);
CoreUtils.CreateCmdTemporaryRT(cmd, m_DebugFullScreenTempRT, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.Blit(textureID, m_DebugFullScreenTempRT);
var mipIndex = Mathf.FloorToInt(m_CurrentDebugDisplaySettings.fullscreenDebugMip * (lodCount));
m_FullScreenDebugPushed = true; // We need this flag because otherwise if no fullscreen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
var mipIndex = Mathf.FloorToInt(m_CurrentDebugDisplaySettings.fullscreenDebugMip * (lodCount));
m_FullScreenDebugPushed = true; // We need this flag because otherwise if no full screen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
cmd.ReleaseTemporaryRT(m_DebugFullScreenTempRT);
desc.width = desc.width >> mipIndex;

}
void PushFullScreenDebugDepthMip(CommandBuffer cmd, RenderTargetIdentifier textureID, int lodCount, RenderTextureDescriptor desc, FullScreenDebugMode debugMode)
{
var mipIndex = Mathf.FloorToInt(m_CurrentDebugDisplaySettings.fullscreenDebugMip * (lodCount));
{
var mipIndex = Mathf.FloorToInt(m_CurrentDebugDisplaySettings.fullscreenDebugMip * (lodCount));
m_FullScreenDebugPushed = true; // We need this flag because otherwise if no fullscreen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
cmd.ReleaseTemporaryRT(m_DebugFullScreenTempRT);

}
}
public void PushFullScreenDebugTexture(CommandBuffer cb, int textureID, HDCamera hdCamera, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
public void PushFullScreenDebugTexture(CommandBuffer cb, int textureID, HDCamera hdCamera, FullScreenDebugMode debugMode)
PushFullScreenDebugTexture(cb, new RenderTargetIdentifier(textureID), hdCamera, renderContext, debugMode);
PushFullScreenDebugTexture(cb, new RenderTargetIdentifier(textureID), hdCamera, debugMode);
void RenderDebug(HDCamera camera, CommandBuffer cmd)
void RenderDebug(HDCamera hdCamera, CommandBuffer cmd)
if (camera.camera.cameraType == CameraType.Reflection || camera.camera.cameraType == CameraType.Preview)
if (hdCamera.camera.cameraType == CameraType.Reflection || hdCamera.camera.cameraType == CameraType.Preview)
return;
using (new ProfilingSample(cmd, "Render Debug", CustomSamplerId.RenderDebug.GetSampler()))

{
m_FullScreenDebugPushed = false;
cmd.SetGlobalTexture(HDShaderIDs._DebugFullScreenTexture, m_DebugFullScreenTempRT);
// TODO: Replace with command buffer call when available
PushColorPickerDebugTexture(cmd, m_DebugFullScreenTempRT, hdCamera);
float overlaySize = Math.Min(camera.camera.pixelHeight, camera.camera.pixelWidth) * overlayRatio;
float y = camera.camera.pixelHeight - overlaySize;
float overlaySize = Math.Min(hdCamera.camera.pixelHeight, hdCamera.camera.pixelWidth) * overlayRatio;
float y = hdCamera.camera.pixelHeight - overlaySize;
var lightingDebug = m_CurrentDebugDisplaySettings.lightingDebugSettings;

m_SharedPropertyBlock.SetFloat(HDShaderIDs._Mipmap, lightingDebug.skyReflectionMipmap);
cmd.SetViewport(new Rect(x, y, overlaySize, overlaySize));
cmd.DrawProcedural(Matrix4x4.identity, m_DebugDisplayLatlong, 0, MeshTopology.Triangles, 3, 1, m_SharedPropertyBlock);
HDUtils.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.camera.pixelWidth);
HDUtils.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, hdCamera.camera.pixelWidth);
m_LightLoop.RenderDebugOverlay(camera, cmd, m_CurrentDebugDisplaySettings, ref x, ref y, overlaySize, camera.camera.pixelWidth);
m_LightLoop.RenderDebugOverlay(hdCamera, cmd, m_CurrentDebugDisplaySettings, ref x, ref y, overlaySize, hdCamera.camera.pixelWidth);
if (m_CurrentDebugDisplaySettings.colorPickerDebugSettings.colorPickerMode != ColorPickerDebugMode.None)
{
ColorPickerDebugSettings colorPickerDebugSettings = m_CurrentDebugDisplaySettings.colorPickerDebugSettings;
// Here we have three cases:
// - Material debug is enabled, this is the buffer we display
// - Otherwise we display the HDR buffer before postprocess and distortion
// - If fullscreen debug is enabled we always use it
cmd.SetGlobalTexture(HDShaderIDs._DebugColorPickerTexture, m_DebugColorPickerRT); // No SetTexture with RenderTarget identifier... so use SetGlobalTexture
// TODO: Replace with command buffer call when available
m_DebugColorPicker.SetColor(HDShaderIDs._ColorPickerFontColor, colorPickerDebugSettings.fontColor);
var colorPickerParam = new Vector4(colorPickerDebugSettings.colorThreshold0, colorPickerDebugSettings.colorThreshold1, colorPickerDebugSettings.colorThreshold2, colorPickerDebugSettings.colorThreshold3);
m_DebugColorPicker.SetVector(HDShaderIDs._ColorPickerParam, colorPickerParam);
m_DebugColorPicker.SetInt(HDShaderIDs._ColorPickerMode, (int)colorPickerDebugSettings.colorPickerMode);
CoreUtils.DrawFullScreen(cmd, m_DebugColorPicker, (RenderTargetIdentifier)BuiltinRenderTextureType.CameraTarget);
}
}
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _DebugViewMaterial = Shader.PropertyToID("_DebugViewMaterial");
public static readonly int _DebugLightingMode = Shader.PropertyToID("_DebugLightingMode");
public static readonly int _DebugLightingAlbedo = Shader.PropertyToID("_DebugLightingAlbedo");
public static readonly int _DebugLuxMeterParam = Shader.PropertyToID("_DebugLuxMeterParam");
public static readonly int _UseTileLightList = Shader.PropertyToID("_UseTileLightList");
public static readonly int _Time = Shader.PropertyToID("_Time");

Shader.PropertyToID("_DepthPyramidMip13"),
Shader.PropertyToID("_DepthPyramidMip14"),
};
public static readonly int _DebugColorPickerTexture = Shader.PropertyToID("_DebugColorPickerTexture");
public static readonly int _ColorPickerParam = Shader.PropertyToID("_ColorPickerParam");
public static readonly int _ColorPickerMode = Shader.PropertyToID("_ColorPickerMode");
public static readonly int _ColorPickerFontColor = Shader.PropertyToID("_ColorPickerFontColor");
public static readonly int _DebugFullScreenTexture = Shader.PropertyToID("_DebugFullScreenTexture");
public static readonly int _BlitTexture = Shader.PropertyToID("_BlitTexture");

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


type: 3}
debugFullScreenShader: {fileID: 4800000, guid: e874aca2df8300a488258738c31f85cf,
type: 3}
debugColorPickerShader: {fileID: 4800000, guid: 8137b807709e178498f22ed710864bb0,
type: 3}
deferredShader: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3}
gaussianPyramidCS: {fileID: 7200000, guid: 6dba4103d23a7904fbc49099355aff3e, type: 3}
depthPyramidCS: {fileID: 7200000, guid: 64a553bb564274041906f78ffba955e4, type: 3}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader debugViewMaterialGBufferShader;
public Shader debugViewTilesShader;
public Shader debugFullScreenShader;
public Shader debugColorPickerShader;
// Lighting resources
public Shader deferredShader;

39
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/ColorPickerDebug.cs


using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public enum ColorPickerDebugMode
{
None,
Byte,
Byte4,
Float,
Float4,
}
[Serializable]
public class ColorPickerDebugSettings
{
public static string kColorPickerFontColor = "Font Color";
public static string kColorPickerThreshold0Debug = "Color Range Threshold 0";
public static string kColorPickerThreshold1Debug = "Color Range Threshold 1";
public static string kColorPickerThreshold2Debug = "Color Range Threshold 2";
public static string kColorPickerThreshold3Debug = "Color Range Threshold 3";
public static string kColorPickerDebugMode = "Color Picker Debug Mode";
public ColorPickerDebugMode colorPickerMode = ColorPickerDebugMode.None;
public Color fontColor = new Color(1.0f, 0.0f, 0.0f);
public float colorThreshold0 = 0.0f;
public float colorThreshold1 = 200.0f;
public float colorThreshold2 = 9000.0f;
public float colorThreshold3 = 10000.0f;
public void OnValidate()
{
}
}
}

17
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/ColorPickerDebug.cs.hlsl


//
// This file was automatically generated. Please don't edit by hand.
//
#ifndef COLORPICKERDEBUG_CS_HLSL
#define COLORPICKERDEBUG_CS_HLSL
//
// UnityEngine.Experimental.Rendering.HDPipeline.ColorPickerDebugMode: static fields
//
#define COLORPICKERDEBUGMODE_NONE (0)
#define COLORPICKERDEBUGMODE_BYTE (1)
#define COLORPICKERDEBUGMODE_BYTE4 (2)
#define COLORPICKERDEBUGMODE_FLOAT (3)
#define COLORPICKERDEBUGMODE_FLOAT4 (4)
#endif

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


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

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


fileFormatVersion: 2
guid: 8892f1d2d1b1ba443b871cf984ef8665
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

120
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader


Shader "Hidden/HDRenderPipeline/DebugColorPicker"
{
SubShader
{
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#pragma vertex Vert
#pragma fragment Frag
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../ShaderVariables.hlsl"
#include "../Debug/DebugDisplay.cs.hlsl"
#include "../Debug/DebugDisplay.hlsl"
TEXTURE2D(_DebugColorPickerTexture);
SAMPLER(sampler_DebugColorPickerTexture);
float4 _ColorPickerParam; // 4 increasing threshold
int _ColorPickerMode;
float3 _ColorPickerFontColor;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
float4 DisplayPixelInformationAtMousePosition(Varyings input, float4 result, float4 mouseResult)
{
if (_MousePixelCoord.z >= 0.0 && _MousePixelCoord.z <= 1.0 && _MousePixelCoord.w >= 0 && _MousePixelCoord.w <= 1.0)
{
// Display message offset:
int displayTextOffsetX = 1.5 * DEBUG_FONT_TEXT_WIDTH;
#if UNITY_UV_STARTS_AT_TOP
int displayTextOffsetY = -DEBUG_FONT_TEXT_HEIGHT;
#else
int displayTextOffsetY = DEBUG_FONT_TEXT_HEIGHT;
#endif
uint2 displayUnormCoord = uint2(_MousePixelCoord.x + displayTextOffsetX, _MousePixelCoord.y + displayTextOffsetY);
uint2 unormCoord = input.positionCS.xy;
if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE || _ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)
{
uint4 mouseValue = int4(mouseResult * 255.5);
DrawInteger(mouseValue.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)
{
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawInteger(mouseValue.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawInteger(mouseValue.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawInteger(mouseValue.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
}
}
else // float
{
DrawFloat(mouseResult.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
if (_ColorPickerMode == COLORPICKERDEBUGMODE_FLOAT4)
{
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawFloat(mouseResult.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawFloat(mouseResult.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.y += displayTextOffsetY;
DrawFloat(mouseResult.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
}
}
}
return result;
}
float4 Frag(Varyings input) : SV_Target
{
float4 result = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, input.texcoord);
//result.rgb = GetColorCodeFunction(result.x, _ColorPickerParam);
float4 mouseResult = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, _MousePixelCoord.zw);
return DisplayPixelInformationAtMousePosition(input, result, mouseResult);
}
ENDHLSL
}
}
Fallback Off
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader.meta


fileFormatVersion: 2
guid: 8137b807709e178498f22ed710864bb0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存