Skip to content

Commit 8e8fc19

Browse files
2 parents c3296fc + a433ed1 commit 8e8fc19

35 files changed

+1962
-529
lines changed

Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Must be in sync with ShaderConfig.cs
2-
//#define VELOCITY_IN_GBUFFER
3-
41
using UnityEngine.Rendering;
52
using UnityEngine.Experimental.Rendering;
63
using System.Collections.Generic;
@@ -136,7 +133,6 @@ public void BindBuffers(Material mat)
136133
TextureSettings m_TextureSettings = TextureSettings.Default;
137134

138135
// Various set of material use in render loop
139-
Material m_DeferredMaterial;
140136
Material m_FinalPassMaterial;
141137
Material m_DebugViewMaterialGBuffer;
142138

@@ -150,8 +146,7 @@ public void BindBuffers(Material mat)
150146
RenderTargetIdentifier m_CameraDepthBufferRT;
151147
RenderTargetIdentifier m_VelocityBufferRT;
152148
RenderTargetIdentifier m_DistortionBufferRT;
153-
154-
149+
155150
public class LightList
156151
{
157152
public List<DirectionalLightData> directionalLights;
@@ -237,8 +232,7 @@ public override void Rebuild()
237232

238233
m_SkyRenderer = new SkyRenderer();
239234
m_SkyRenderer.Rebuild();
240-
241-
m_DeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
235+
242236
m_FinalPassMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/FinalPass");
243237
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/DebugViewMaterialGBuffer");
244238

@@ -295,7 +289,6 @@ void OnDisable()
295289
m_SinglePassLightLoop.OnDisable();
296290
m_TilePassLightLoop.OnDisable();
297291

298-
Utilities.Destroy(m_DeferredMaterial);
299292
Utilities.Destroy(m_FinalPassMaterial);
300293
Utilities.Destroy(m_DebugViewMaterialGBuffer);
301294

@@ -341,6 +334,7 @@ void InitAndClearBuffer(Camera camera, RenderLoop renderLoop)
341334
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearDepth);
342335
}
343336

337+
344338
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
345339

346340
// Clear HDR target
@@ -392,10 +386,10 @@ void RenderDepthPrepass(CullResults cull, Camera camera, RenderLoop renderLoop)
392386
if (!debugParameters.useDepthPrepass)
393387
return;
394388

395-
// TODO: Must do opaque then alpha masked for performance!
389+
// TODO: Must do opaque then alpha masked for performance!
396390
// TODO: front to back for opaque and by materal for opaque tested when we split in two
397391
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT, "Depth Prepass");
398-
RenderOpaqueRenderList(cull, camera, renderLoop, "DepthOnly");
392+
RenderOpaqueRenderList(cull, camera, renderLoop, "DepthOnly");
399393
}
400394

401395
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop)
@@ -437,11 +431,11 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
437431
// Render GBuffer opaque
438432
if (!debugParameters.useForwardRenderingOnly)
439433
{
440-
Vector4 screenSize = ComputeScreenSize(camera);
434+
Vector4 screenSize = Utilities.ComputeScreenSize(camera);
441435
m_DebugViewMaterialGBuffer.SetVector("_ScreenSize", screenSize);
442436
m_DebugViewMaterialGBuffer.SetFloat("_DebugViewMaterial", (float)debugParameters.debugViewMaterial);
443437

444-
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
438+
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
445439
// TODO: Bind depth textures
446440
var cmd = new CommandBuffer { name = "GBuffer Debug Pass" };
447441
cmd.Blit(null, m_CameraColorBufferRT, m_DebugViewMaterialGBuffer, 0);
@@ -463,21 +457,6 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
463457
}
464458
}
465459

466-
Matrix4x4 GetViewProjectionMatrix(Camera camera)
467-
{
468-
// The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
469-
// (different Z value ranges etc.)
470-
var gpuProj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);
471-
var gpuVP = gpuProj * camera.worldToCameraMatrix;
472-
473-
return gpuVP;
474-
}
475-
476-
Vector4 ComputeScreenSize(Camera camera)
477-
{
478-
return new Vector4(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight);
479-
}
480-
481460
void RenderDeferredLighting(Camera camera, RenderLoop renderLoop)
482461
{
483462
if (debugParameters.useForwardRenderingOnly)
@@ -488,24 +467,14 @@ void RenderDeferredLighting(Camera camera, RenderLoop renderLoop)
488467
// Bind material data
489468
m_LitRenderLoop.Bind();
490469

491-
var invViewProj = GetViewProjectionMatrix(camera).inverse;
492-
m_DeferredMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
493-
494-
var screenSize = ComputeScreenSize(camera);
495-
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
496-
497-
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
498-
// TODO: Bind depth textures
499-
var cmd = new CommandBuffer { name = "Deferred Ligthing Pass" };
500-
cmd.Blit(null, m_CameraColorBufferRT, m_DeferredMaterial, 0);
501-
renderLoop.ExecuteCommandBuffer(cmd);
502-
cmd.Dispose();
470+
m_SinglePassLightLoop.RenderDeferredLighting(camera, renderLoop, m_CameraColorBuffer);
471+
// m_TilePassLightLoop.RenderDeferredLighting(camera, renderLoop, );
503472
}
504473

505474
void RenderSky(Camera camera, RenderLoop renderLoop)
506475
{
507476
m_SkyRenderer.RenderSky(camera, m_SkyParameters, m_CameraColorBufferRT, m_CameraDepthBufferRT, renderLoop);
508-
}
477+
}
509478

510479
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop)
511480
{
@@ -683,10 +652,10 @@ void PrepareLightsForGPU(CullResults cullResults, Camera camera, ref ShadowOutpu
683652

684653
if (additionalData.archetype == LightArchetype.Rectangle)
685654
{
686-
lightData.lightType = GPULightType.Rectangle;
687-
}
688-
else
689-
{
655+
lightData.lightType = GPULightType.Rectangle;
656+
}
657+
else
658+
{
690659
lightData.lightType = GPULightType.Line;
691660
}
692661
}
@@ -926,8 +895,6 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
926895

927896
PushGlobalParams(camera, renderLoop, m_lightList);
928897

929-
930-
931898
RenderDeferredLighting(camera, renderLoop);
932899

933900
RenderSky(camera, renderLoop);

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Resources/Deferred.shader

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Shader "Hidden/HDRenderLoop/Deferred"
1919
#pragma multi_compile LIGHTLOOP_SINGLE_PASS
2020
//#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF
2121

22+
// TODO: This must be on lightloop side and include here....
23+
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
24+
#pragma multi_compile __ ENABLE_DEBUG
25+
2226
//-------------------------------------------------------------------------------------
2327
// Include
2428
//-------------------------------------------------------------------------------------
@@ -71,7 +75,7 @@ Shader "Hidden/HDRenderLoop/Deferred"
7175
Coordinate coord = GetCoordinate(unPositionSS.xy, _ScreenSize.zw);
7276

7377
// No need to manage inverse depth, this is handled by the projection matrix
74-
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
78+
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, uint3(coord.unPositionSS, 0)).x;
7579
float3 positionWS = UnprojectToWorld(depth, coord.positionSS, _InvViewProjMatrix);
7680
float3 V = GetWorldSpaceNormalizeViewDir(positionWS);
7781

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using UnityEngine;
2+
using UnityEngine.Rendering;
23
using UnityEngine.Experimental.Rendering;
34
using System;
45

@@ -25,6 +26,8 @@ string GetKeyword()
2526
static ComputeBuffer s_PunctualShadowList;
2627
static ComputeBuffer s_DirectionalShadowList;
2728

29+
Material m_DeferredMaterial;
30+
2831
void ClearComputeBuffers()
2932
{
3033
if (s_DirectionalLights != null)
@@ -56,6 +59,8 @@ public void Rebuild()
5659
s_AreaLightList = new ComputeBuffer(HDRenderLoop.k_MaxAreaLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
5760
s_EnvLightList = new ComputeBuffer(HDRenderLoop.k_MaxEnvLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
5861
s_PunctualShadowList = new ComputeBuffer(HDRenderLoop.k_MaxShadowOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualShadowData)));
62+
63+
m_DeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
5964
}
6065

6166
public void OnDisable()
@@ -72,6 +77,8 @@ public void OnDisable()
7277
s_EnvLightList = null;
7378
s_PunctualShadowList.Release();
7479
s_PunctualShadowList = null;
80+
81+
Utilities.Destroy(m_DeferredMaterial);
7582
}
7683

7784
public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRenderLoop.LightList lightList) {}
@@ -96,8 +103,23 @@ public void PushGlobalParams(Camera camera, RenderLoop loop, HDRenderLoop.LightL
96103
Shader.SetGlobalBuffer("_EnvLightList", s_EnvLightList);
97104
Shader.SetGlobalInt("_EnvLightCount", lightList.envLights.Count);
98105

99-
Shader.SetGlobalVectorArray("_DirShadowSplitSpheres", lightList.directionalShadowSplitSphereSqr);
100-
106+
Shader.SetGlobalVectorArray("_DirShadowSplitSpheres", lightList.directionalShadowSplitSphereSqr);
107+
}
108+
109+
public void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderTargetIdentifier colorBuffer)
110+
{
111+
var invViewProj = Utilities.GetViewProjectionMatrix(camera).inverse;
112+
m_DeferredMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
113+
114+
var screenSize = Utilities.ComputeScreenSize(camera);
115+
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
116+
117+
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
118+
// TODO: Bind depth textures
119+
var cmd = new CommandBuffer { name = "Single Pass - Deferred Ligthing Pass" };
120+
cmd.Blit(null, colorBuffer, m_DeferredMaterial, 0);
121+
renderLoop.ExecuteCommandBuffer(cmd);
122+
cmd.Dispose();
101123
}
102124
}
103125
}

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePassLoop.hlsl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ void LightLoop( float3 V, float3 positionWS, PreLightData prelightData, BSDFData
4141
{
4242
float3 localDiffuseLighting, localSpecularLighting;
4343

44-
EvaluateBSDF_Area(context, V, positionWS, prelightData, _AreaLightList[i], bsdfData,
45-
localDiffuseLighting, localSpecularLighting);
44+
if (_AreaLightList[i].lightType == GPULIGHTTYPE_LINE)
45+
{
46+
EvaluateBSDF_Line(context, V, positionWS, prelightData, _AreaLightList[i], bsdfData,
47+
localDiffuseLighting, localSpecularLighting);
48+
}
49+
else
50+
{
51+
EvaluateBSDF_Area(context, V, positionWS, prelightData, _AreaLightList[i], bsdfData,
52+
localDiffuseLighting, localSpecularLighting);
53+
}
4654

4755
diffuseLighting += localDiffuseLighting;
4856
specularLighting += localSpecularLighting;

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma kernel BigTileLightListGen
22

3+
#include "common.hlsl"
34
#include "../TilePass.cs.hlsl"
45
#include "../LightingConvexHullUtils.hlsl"
56
#if !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_PSSL)

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-clustered.compute

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma kernel TileLightListGen_DepthRT_MSAA_SrcBigTile LIGHTLISTGEN=TileLightListGen_DepthRT_MSAA_SrcBigTile ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED USE_TWO_PASS_TILED_LIGHTING
77
#pragma kernel ClearAtomic
88

9+
#include "common.hlsl"
910
#include "../ShaderBase.hlsl"
1011
#include "../TilePass.cs.hlsl"
1112
#include "../LightingConvexHullUtils.hlsl"

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild.compute

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma kernel TileLightListGen LIGHTLISTGEN=TileLightListGen
55
#pragma kernel TileLightListGen_SrcBigTile LIGHTLISTGEN=TileLightListGen_SrcBigTile USE_TWO_PASS_TILED_LIGHTING
66

7+
#include "common.hlsl"
78
#include "../ShaderBase.hlsl"
89
#include "../TilePass.cs.hlsl"
910
#include "../LightingConvexHullUtils.hlsl"

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/scrbound.compute

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma kernel ScreenBoundsAABB
55

6+
#include "common.hlsl"
67
#include "../TilePass.cs.hlsl"
78

89
uniform int g_iNrVisibLights;

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/ShaderBase.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
2121
{
22-
return 1 - depthTexture.Load(uint3(pixCoord.xy, 0)).x;
22+
return 1 - LOAD_TEXTURE2D(depthTexture, uint3(pixCoord.xy, 0)).x;
2323
}
2424

2525
float FetchDepthMSAA(Texture2DMS<float> depthTexture, uint2 pixCoord, uint sampleIdx)
2626
{
27-
return 1 - depthTexture.Load(uint3(pixCoord.xy, 0), sampleIdx).x;
27+
return 1 - LOAD_TEXTURE2D_MSAA(depthTexture, uint3(pixCoord.xy, 0), sampleIdx).x;
2828
}
2929

3030
#endif

0 commit comments

Comments
 (0)