Skip to content

Commit c4ec214

Browse files
HDRenderPipeline: Revert a small change about DebugViewMaterialGBuffer.shader
- the clean of DebugViewMaterialGBuffer was not necessary
1 parent b801b89 commit c4ec214

7 files changed

Lines changed: 134 additions & 91 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Shader "Hidden/HDRenderPipeline/DebugViewMaterialGBuffer"
2+
{
3+
SubShader
4+
{
5+
Pass
6+
{
7+
ZWrite Off
8+
Blend SrcAlpha OneMinusSrcAlpha // We will lerp only the values that are valid
9+
10+
HLSLPROGRAM
11+
#pragma target 4.5
12+
#pragma only_renderers d3d11 ps4 metal // TEMP: until we go further in dev
13+
14+
#pragma vertex Vert
15+
#pragma fragment Frag
16+
17+
#include "../../../ShaderLibrary/Common.hlsl"
18+
#include "../../../ShaderLibrary/Color.hlsl"
19+
20+
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
21+
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
22+
#include "../../ShaderConfig.cs.hlsl"
23+
#include "../../ShaderVariables.hlsl"
24+
#define DEBUG_DISPLAY
25+
#include "../../Debug/DebugDisplay.hlsl"
26+
#include "../../Material/Material.hlsl"
27+
28+
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
29+
30+
struct Attributes
31+
{
32+
float3 positionOS : POSITION;
33+
};
34+
35+
struct Varyings
36+
{
37+
float4 positionCS : SV_POSITION;
38+
};
39+
40+
Varyings Vert(Attributes input)
41+
{
42+
// TODO: implement SV_vertexID full screen quad
43+
Varyings output;
44+
float3 positionWS = TransformObjectToWorld(input.positionOS);
45+
output.positionCS = TransformWorldToHClip(positionWS);
46+
47+
return output;
48+
}
49+
50+
float4 Frag(Varyings input) : SV_Target
51+
{
52+
// input.positionCS is SV_Position
53+
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
54+
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.unPositionSS).x;
55+
UpdatePositionInput(depth, _InvViewProjMatrix, _ViewProjMatrix, posInput);
56+
57+
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
58+
BSDFData bsdfData;
59+
float3 bakeDiffuseLighting;
60+
DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, bakeDiffuseLighting);
61+
62+
// Init to not expected value
63+
float3 result = float3(-666.0, 0.0, 0.0);
64+
bool needLinearToSRGB = false;
65+
66+
if (_DebugViewMaterial == DEBUGVIEWGBUFFER_DEPTH)
67+
{
68+
float linearDepth = frac(posInput.depthVS * 0.1);
69+
result = linearDepth.xxx;
70+
}
71+
// Caution: This value is not the same than the builtin data bakeDiffuseLighting. It also include emissive and multiply by the albedo
72+
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE)
73+
{
74+
// TODO: require a remap
75+
// TODO: we should not gamma correct, but easier to debug for now without correct high range value
76+
result = bakeDiffuseLighting; needLinearToSRGB = true;
77+
}
78+
79+
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB);
80+
81+
// f we haven't touch result, we don't blend it. This allow to have the GBuffer debug pass working with the regular forward debug pass.
82+
// The forward debug pass will write its value and then the deferred will overwrite only touched texels.
83+
if (result.x == -666.0)
84+
{
85+
return float4(0.0, 0.0, 0.0, 0.0);
86+
}
87+
else
88+
{
89+
// TEMP!
90+
// For now, the final blit in the backbuffer performs an sRGB write
91+
// So in the meantime we apply the inverse transform to linear data to compensate.
92+
if (!needLinearToSRGB)
93+
result = SRGBToLinear(max(0, result));
94+
95+
return float4(result, 1.0);
96+
}
97+
}
98+
99+
ENDHLSL
100+
}
101+
102+
}
103+
Fallback Off
104+
}

Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void ApplyDebugDisplaySettings()
130130
Shader.SetGlobalInt("_DebugDisplayMode", (int)debugDisplaySettings.debugDisplayMode);
131131
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugDisplaySettings.materialDebugSettings.debugViewMaterial);
132132
Shader.SetGlobalVector("_DebugLightingAlbedo", debugAlbedo);
133-
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
133+
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
134134
}
135135

136136
public void UpdateCommonSettings()
@@ -238,6 +238,7 @@ public class HDRenderPipelineInstance : RenderPipeline
238238
readonly Material m_FilterAndCombineSubsurfaceScattering;
239239

240240
private Material m_DebugDisplayShadowMap;
241+
private Material m_DebugViewMaterialGBuffer;
241242
private Material m_DebugDisplayLatlong;
242243

243244
// Various buffer
@@ -343,6 +344,7 @@ public HDRenderPipelineInstance(HDRenderPipeline owner)
343344
void InitializeDebugMaterials()
344345
{
345346
m_DebugDisplayShadowMap = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugDisplayShadowMap");
347+
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugViewMaterialGBuffer");
346348
m_DebugDisplayLatlong = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugDisplayLatlong");
347349
}
348350

@@ -356,6 +358,8 @@ public override void Dispose()
356358
m_LitRenderLoop.Cleanup();
357359

358360
Utilities.Destroy(m_DebugDisplayShadowMap);
361+
Utilities.Destroy(m_DebugViewMaterialGBuffer);
362+
Utilities.Destroy(m_DebugDisplayLatlong);
359363

360364
m_SkyManager.Cleanup();
361365

@@ -747,8 +751,14 @@ void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRend
747751
// Render GBuffer opaque
748752
if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
749753
{
750-
RenderTargetIdentifier[] colorRTs = { m_CameraColorBufferRT, m_CameraSubsurfaceBufferRT };
751-
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, debugDisplaySettings, colorRTs, m_CameraDepthStencilBufferRT, new RenderTargetIdentifier(GetDepthTexture()), false);
754+
Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewMaterialGBuffer);
755+
756+
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
757+
// TODO: Bind depth textures
758+
var cmd = new CommandBuffer { name = "DebugViewMaterialGBuffer" };
759+
cmd.Blit(null, m_CameraColorBufferRT, m_DebugViewMaterialGBuffer, 0);
760+
renderContext.ExecuteCommandBuffer(cmd);
761+
cmd.Dispose();
752762
}
753763

754764
// Render forward transparent
@@ -842,7 +852,7 @@ void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderConte
842852

843853
if (m_LightLoop != null)
844854
m_LightLoop.RenderForward(camera, renderContext, renderOpaque);
845-
855+
846856
if (renderOpaque)
847857
{
848858
RenderOpaqueRenderList(cullResults, camera, renderContext, passName, Utilities.kRendererConfigurationBakedLighting);

Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -123,57 +123,6 @@ Shader "Hidden/HDRenderPipeline/Deferred"
123123
outputs.combinedLighting = float4(diffuseLighting + specularLighting, 1.0);
124124
#endif
125125

126-
#ifdef DEBUG_DISPLAY
127-
if (_DebugDisplayMode == DEBUGDISPLAYMODE_VIEW_MATERIAL)
128-
{
129-
// Init to not expected value
130-
float3 result = float3(-666.0, 0.0, 0.0);
131-
bool needLinearToSRGB = false;
132-
133-
if (_DebugViewMaterial == DEBUGVIEWGBUFFER_DEPTH)
134-
{
135-
float linearDepth = frac(posInput.depthVS * 0.1);
136-
result = linearDepth.xxx;
137-
}
138-
// Caution: This value is not the same than the builtin data bakeDiffuseLighting. It also include emissive and multiply by the albedo
139-
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE)
140-
{
141-
// TODO: require a remap
142-
// TODO: we should not gamma correct, but easier to debug for now without correct high range value
143-
result = bakeDiffuseLighting; needLinearToSRGB = true;
144-
}
145-
146-
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB);
147-
148-
float4 value;
149-
150-
// If we haven't touch result, we don't blend it. This allow to have the GBuffer debug pass working with the regular forward debug pass.
151-
// The forward debug pass will write its value and then the deferred will overwrite only touched texels.
152-
if (result.x == -666.0)
153-
{
154-
value = float4(0.0, 0.0, 0.0, 0.0);
155-
}
156-
else
157-
{
158-
// TEMP!
159-
// For now, the final blit in the backbuffer performs an sRGB write
160-
// So in the meantime we apply the inverse transform to linear data to compensate.
161-
if (!needLinearToSRGB)
162-
result = SRGBToLinear(max(0, result));
163-
164-
value = float4(result, 1.0);
165-
}
166-
167-
// Note: When DEBUG_DISPLAY is on for DEBUGDISPLAYMODE_VIEW_MATERIAL there is no OUTPUT_SPLIT_LIGHTING
168-
#ifdef OUTPUT_SPLIT_LIGHTING
169-
outputs.specularLighting = value;
170-
outputs.diffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
171-
#else
172-
outputs.combinedLighting = value;
173-
#endif
174-
}
175-
#endif // DEBUG_DISPLAY
176-
177126
return outputs;
178127
}
179128

Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ private static AdditionalLightData DefaultAdditionalLightData
331331
Material m_DeferredIndirectMaterialSRT = null;
332332
Material m_DeferredIndirectMaterialMRT = null;
333333
Material m_DeferredAllMaterialSRT = null;
334-
Material m_DeferredViewMaterial = null; // Only use for DisplayDebug view material
335334
Material m_DeferredAllMaterialMRT = null;
336335

337336
Material m_DebugViewTilesMaterial = null;
@@ -508,16 +507,6 @@ public override void Build(TextureSettings textureSettings)
508507
m_DeferredAllMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
509508
m_DeferredAllMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);
510509

511-
m_DeferredViewMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
512-
Utilities.SelectKeyword(m_DeferredViewMaterial, tileKeywords, 2);
513-
m_DeferredViewMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
514-
m_DeferredViewMaterial.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
515-
m_DeferredViewMaterial.EnableKeyword("DEBUG_DISPLAY");
516-
m_DeferredViewMaterial.SetInt("_StencilRef", 0);
517-
m_DeferredViewMaterial.SetInt("_StencilCmp", 4 /* LEqual */);
518-
m_DeferredViewMaterial.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
519-
m_DeferredViewMaterial.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
520-
521510
m_DeferredAllMaterialMRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
522511
Utilities.SelectKeyword(m_DeferredAllMaterialMRT, tileKeywords, 2);
523512
m_DeferredAllMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
@@ -601,7 +590,6 @@ public override void Cleanup()
601590
Utilities.Destroy(m_DeferredIndirectMaterialSRT);
602591
Utilities.Destroy(m_DeferredIndirectMaterialMRT);
603592
Utilities.Destroy(m_DeferredAllMaterialSRT);
604-
Utilities.Destroy(m_DeferredViewMaterial);
605593
Utilities.Destroy(m_DeferredAllMaterialMRT);
606594

607595
Utilities.Destroy(m_DebugViewTilesMaterial);
@@ -1853,20 +1841,6 @@ public override void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderC
18531841

18541842
SetupDebugDisplayMode(debugDisplaySettings.IsDebugDisplayEnable());
18551843

1856-
// If we visualize material properties we do only one pass with a specific blend mode
1857-
if (debugDisplaySettings.debugDisplayMode == DebugDisplayMode.ViewMaterial)
1858-
{
1859-
Utilities.SelectKeyword(m_DeferredViewMaterial, "USE_CLUSTERED_LIGHTLIST", "USE_FPTL_LIGHTLIST", bUseClusteredForDeferred); // Not used, but setup it to avoid corruption just in case
1860-
Utilities.DrawFullScreen(cmd, m_DeferredViewMaterial, hdCamera, colorBuffers, depthStencilBuffer);
1861-
1862-
SetGlobalPropertyRedirect(null, 0, null);
1863-
1864-
renderContext.ExecuteCommandBuffer(cmd);
1865-
cmd.Dispose();
1866-
1867-
return;
1868-
}
1869-
18701844
if (!m_PassSettings.enableTileAndCluster)
18711845
{
18721846
PushGlobalParams(camera, renderContext, null, 0);
@@ -1920,7 +1894,7 @@ public override void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderC
19201894
}
19211895

19221896
// Pass global parameters to compute shader
1923-
// TODO: get rid of this by making global parameters visible to compute shaders
1897+
// TODO: get rid of this by making global parameters visible to compute shaders
19241898
PushGlobalParams(camera, renderContext, shadeOpaqueShader, kernel);
19251899

19261900
// TODO: Update value like in ApplyDebugDisplaySettings() call. Sadly it is high likely that this will not be keep in sync. we really need to get rid of this by making global parameters visible to compute shaders

Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassResources.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,5 @@ static void CreateTilePassSetup()
1919
public ComputeShader buildPerVoxelLightListShader = null; // clustered
2020
public ComputeShader clearDispatchIndirectShader = null;
2121
public ComputeShader shadeOpaqueShader = null;
22-
23-
// For image based lighting
24-
public Shader m_InitPreFGD;
2522
}
2623
}

Assets/ScriptableRenderPipeline/ShaderLibrary/Wind.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ float WIND_SETTINGS_GustWorldScale;
1515
float AttenuateTrunk(float x, float s)
1616
{
1717
float r = (x / s);
18-
return pow(r,1/s);
18+
return PositivePow(r,1/s);
1919
}
2020

2121

@@ -71,10 +71,10 @@ WindData GetAnalyticalWind(float3 WorldPosition, float3 PivotPosition, float dra
7171
gust = pow(gust, 2) * WIND_SETTINGS_GustScale;
7272
}
7373

74-
float3 trunkNoise =
74+
float3 trunkNoise =
7575
(
76-
(normalizedDir * WIND_SETTINGS_WorldDirectionAndSpeed.w)
77-
+ (gust * normalizedDir * WIND_SETTINGS_GustSpeed)
76+
(normalizedDir * WIND_SETTINGS_WorldDirectionAndSpeed.w)
77+
+ (gust * normalizedDir * WIND_SETTINGS_GustSpeed)
7878
+ (trunk * WIND_SETTINGS_Turbulence)
7979
) * drag;
8080

@@ -95,7 +95,7 @@ WindData GetAnalyticalWind(float3 WorldPosition, float3 PivotPosition, float dra
9595

9696

9797

98-
void ApplyWind( inout float3 worldPos,
98+
void ApplyWind( inout float3 worldPos,
9999
inout float3 worldNormal,
100100
float3 rootWP,
101101
float stiffness,
@@ -114,7 +114,7 @@ void ApplyWind( inout float3 worldPos,
114114
float3 rotAxis = cross(float3(0, 1, 0), wind.Direction);
115115

116116
worldPos = Rotate(rootWP, worldPos, rotAxis, (wind.Strength) * 0.001 * att);
117-
117+
118118
float3 shiverDirection = normalize(lerp(worldNormal, normalize(wind.Direction + wind.ShiverDirection), shiverDirectionality));
119119
worldPos += wind.ShiverStrength * shiverDirection * shiverMask;
120120
}

0 commit comments

Comments
 (0)