浏览代码

HDRenderLoop: FPTL Tile pass working with direct light, not working correctly with cubemap

/main
Sebastien Lagarde 8 年前
当前提交
41117464
共有 7 个文件被更改,包括 132 次插入33 次删除
  1. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  2. 37
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Resources/Deferred.shader
  4. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs
  5. 84
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  6. 17
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl
  7. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs

8
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


public readonly GUIContent useForwardRenderingOnly = new GUIContent("Use Forward Rendering Only");
public readonly GUIContent useDepthPrepass = new GUIContent("Use Depth Prepass");
public readonly GUIContent useSinglePassLightLoop = new GUIContent("Use single Pass light loop");
public bool isDebugViewMaterialInit = false;
public GUIContent[] debugViewMaterialStrings = null;

public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop settings");
public readonly GUIContent tileLightLoopDebugMode = new GUIContent("Enable Debug mode", "Toggle overheat map mode");
public readonly GUIContent directIndirectSinglePass = new GUIContent("Enable direct and indirect lighting in single pass", "Toggle");
}
private static Styles s_Styles = null;

debugParameters.displayOpaqueObjects = EditorGUILayout.Toggle(styles.displayOpaqueObjects, debugParameters.displayOpaqueObjects);
debugParameters.displayTransparentObjects = EditorGUILayout.Toggle(styles.displayTransparentObjects, debugParameters.displayTransparentObjects);
debugParameters.useForwardRenderingOnly = EditorGUILayout.Toggle(styles.useForwardRenderingOnly, debugParameters.useForwardRenderingOnly);
debugParameters.useDepthPrepass = EditorGUILayout.Toggle(styles.useDepthPrepass, debugParameters.useDepthPrepass);
debugParameters.useDepthPrepass = EditorGUILayout.Toggle(styles.useDepthPrepass, debugParameters.useDepthPrepass);
debugParameters.useSinglePassLightLoop = EditorGUILayout.Toggle(styles.useSinglePassLightLoop, debugParameters.useSinglePassLightLoop);
if (EditorGUI.EndChangeCheck())
{

EditorGUI.BeginChangeCheck();
renderLoop.tilePassLightLoop.enableDrawTileDebug = EditorGUILayout.Toggle(styles.tileLightLoopDebugMode, renderLoop.tilePassLightLoop.enableDrawTileDebug);
renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass = EditorGUILayout.Toggle(styles.directIndirectSinglePass, renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass);
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint

37
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


public bool enableTonemap = true;
public float exposure = 0;
public bool useSinglePassLightLoop = true;
}
DebugParameters m_DebugParameters = new DebugParameters();

{
// Bind material data
m_LitRenderLoop.Bind();
m_SinglePassLightLoop.RenderDeferredLighting(camera, renderLoop, m_CameraColorBuffer);
//tilePassLightLoop.RenderDeferredLighting(camera, renderLoop, m_CameraColorBufferRT);
if (debugParameters.useSinglePassLightLoop)
{
m_SinglePassLightLoop.RenderDeferredLighting(camera, renderLoop, m_CameraColorBuffer);
}
else
{
tilePassLightLoop.RenderDeferredLighting(camera, renderLoop, m_CameraColorBufferRT);
}
}
}

lightList.envCullIndices.Add(probeIndex);
}
// build per tile light lists
m_SinglePassLightLoop.PrepareLightsForGPU(cullResults, camera, m_lightList);
tilePassLightLoop.PrepareLightsForGPU(cullResults, camera, m_lightList);
// build per tile light lists
if (debugParameters.useSinglePassLightLoop)
{
m_SinglePassLightLoop.PrepareLightsForGPU(cullResults, camera, m_lightList);
}
else
{
tilePassLightLoop.PrepareLightsForGPU(cullResults, camera, m_lightList);
}
}
void Resize(Camera camera)

//Shader.SetGlobalTexture("_CubeCookieTextures", m_CubeCookieTexArray.GetTexCache());
Shader.SetGlobalTexture("_EnvTextures", m_CubeReflTexArray.GetTexCache());
m_SinglePassLightLoop.PushGlobalParams(camera, renderLoop, lightList);
tilePassLightLoop.PushGlobalParams(camera, renderLoop, lightList);
if (debugParameters.useSinglePassLightLoop)
{
m_SinglePassLightLoop.PushGlobalParams(camera, renderLoop, lightList);
}
else
{
tilePassLightLoop.PushGlobalParams(camera, renderLoop, lightList);
}
}
public override void Render(Camera[] cameras, RenderLoop renderLoop)

using (new Utilities.ProfilingSample("Build Light list", renderLoop))
{
PrepareLightsForGPU(cullResults, camera, ref shadows, ref m_lightList);
tilePassLightLoop.BuildGPULightLists(camera, renderLoop, m_lightList, m_CameraDepthBufferRT);
if (!debugParameters.useSinglePassLightLoop)
tilePassLightLoop.BuildGPULightLists(camera, renderLoop, m_lightList, m_CameraDepthBufferRT);
PushGlobalParams(camera, renderLoop, m_lightList);
}

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


Shader "Hidden/HDRenderLoop/Deferred"
{
Properties
{
// We need to be able to control the blend mode for deferred shader in case we do multiple pass
_SrcBlend("", Float) = 1
_DstBlend("", Float) = 1
}
SubShader
{

Blend Off
Blend[_SrcBlend][_DstBlend]
HLSLPROGRAM
#pragma target 5.0

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


var screenSize = Utilities.ComputeScreenSize(camera);
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
m_DeferredMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "" };

84
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs


public bool enableBigTilePrepass = false; // SebL - TODO: I get a crash when enabling this
public bool enableDrawLightBoundsDebug = false;
public bool enableDrawTileDebug = false;
public bool enableDirectIndirectSinglePass = false;
public bool enableComputeLightEvaluation = false;
const bool k_UseDepthBuffer = true; // only has an impact when EnableClustered is true (requires a depth-prepass)
const bool k_UseAsyncCompute = true; // should not use on mobile

static ComputeBuffer s_PunctualShadowList;
static ComputeBuffer s_DirectionalShadowList;
Material m_DeferredMaterial;
Material m_DeferredReflectionMaterial;
Material m_DeferredDirectMaterial;
Material m_DeferredIndirectMaterial;
Material m_DeferredAllMaterial;
const int k_TileSize = 16;

s_EnvLightList = new ComputeBuffer(HDRenderLoop.k_MaxEnvLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
s_PunctualShadowList = new ComputeBuffer(HDRenderLoop.k_MaxShadowOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualShadowData)));
m_DeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredMaterial.EnableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredReflectionMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredReflectionMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredReflectionMaterial.EnableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredDirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredDirectMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredDirectMaterial.EnableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredDirectMaterial.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredDirectMaterial.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredIndirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredIndirectMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredIndirectMaterial.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredIndirectMaterial.EnableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredIndirectMaterial.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredAllMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredAllMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredAllMaterial.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredAllMaterial.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredAllMaterial.EnableKeyword("LIGHTLOOP_TILE_ALL");
}
public void OnDisable()

s_PunctualShadowList.Release();
s_PunctualShadowList = null;
Utilities.Destroy(m_DeferredMaterial);
Utilities.Destroy(m_DeferredReflectionMaterial);
Utilities.Destroy(m_DeferredDirectMaterial);
Utilities.Destroy(m_DeferredIndirectMaterial);
Utilities.Destroy(m_DeferredAllMaterial);
}
public bool NeedResize()

lightData.boxInnerDist = e;
lightData.boxInvRange.Set(1.0f / delta.x, 1.0f / delta.y, 1.0f / delta.z);
lightData.lightType = (uint)LightDefinitions.BOX_LIGHT;
lightData.lightModel = (uint)LightDefinitions.REFLECTION_LIGHT;
int i = LightDefinitions.REFLECTION_LIGHT, j = LightDefinitions.BOX_LIGHT;
int index = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];
m_boundData[index] = bound;

public void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderTargetIdentifier cameraColorBufferRT)
{
var bUseClusteredForDeferred = !usingFptl; // doesn't work on reflections yet but will soon
var cmd = new CommandBuffer();
m_DeferredMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredReflectionMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
if (enableDrawTileDebug)
m_DeferredMaterial.EnableKeyword("ENABLE_DEBUG");
else
m_DeferredMaterial.DisableKeyword("ENABLE_DEBUG");
var invViewProj = Utilities.GetViewProjectionMatrix(camera).inverse;
var screenSize = Utilities.ComputeScreenSize(camera);
m_DeferredDirectMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
m_DeferredDirectMaterial.SetVector("_ScreenSize", screenSize);
m_DeferredDirectMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredDirectMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m_DeferredDirectMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredDirectMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.SetKeyword(m_DeferredDirectMaterial, "ENABLE_DEBUG", enableDrawTileDebug);
m_DeferredIndirectMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
m_DeferredIndirectMaterial.SetVector("_ScreenSize", screenSize);
m_DeferredIndirectMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredIndirectMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); // Additive
m_DeferredIndirectMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredIndirectMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.SetKeyword(m_DeferredIndirectMaterial, "ENABLE_DEBUG", enableDrawTileDebug);
m_DeferredAllMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
m_DeferredAllMaterial.SetVector("_ScreenSize", screenSize);
m_DeferredAllMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredAllMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m_DeferredAllMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredAllMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.SetKeyword(m_DeferredAllMaterial, "ENABLE_DEBUG", enableDrawTileDebug);
var cmd = new CommandBuffer();
cmd.SetGlobalBuffer("g_vLightListGlobal", bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)
// In case of bUseClusteredForDeferred disable toggle option since we're using m_perVoxelLightLists as opposed to lightList

}
else
{*/
cmd.Blit(null, cameraColorBufferRT, m_DeferredMaterial, 0);
// cmd.Blit(null, cameraColorBufferRT, m_DeferredReflectionMaterial, 0);
if (enableDirectIndirectSinglePass)
{
cmd.Blit(null, cameraColorBufferRT, m_DeferredAllMaterial, 0);
}
else
{
cmd.Blit(null, cameraColorBufferRT, m_DeferredDirectMaterial, 0);
cmd.Blit(null, cameraColorBufferRT, m_DeferredIndirectMaterial, 0);
}
//}
renderLoop.ExecuteCommandBuffer(cmd);

17
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl


specularLighting += iblSpecularLighting;
#endif
// TODO
#if ENABLE_DEBUG && defined(PROCESS_PUNCTUAL_LIGHT)
#if ENABLE_DEBUG
#if defined(PROCESS_PUNCTUAL_LIGHT) && defined(PROCESS_ENV_LIGHT)
diffuseLighting = OverlayHeatMap(coord.unPositionSS.xy & (TILE_SIZE - 1), punctualLightCount + envLightCount, diffuseLighting);
#elif defined(PROCESS_PUNCTUAL_LIGHT)
specularLighting = float3(0.0, 0.0, 0.0);
#elif defined(PROCESS_ENV_LIGHT)
diffuseLighting = OverlayHeatMap(coord.unPositionSS.xy & (TILE_SIZE - 1), envLightCount, diffuseLighting);
#endif
#endif
// Currently do lightmap with indirect specula
// TODO: test what is the most appropriate here...
#ifdef PROCESS_ENV_LIGHT
// Add indirect diffuse + emissive (if any)
diffuseLighting += bakeDiffuseLighting;
#endif
}

8
Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs


cmd.SetComputeFloatParams(shadercs, name, data);
}
public static void SetKeyword(Material m, string keyword, bool state)
{
if (state)
m.EnableKeyword(keyword);
else
m.DisableKeyword(keyword);
}
}
}
正在加载...
取消
保存