|
|
|
|
|
|
//#define SHADOWS_ENABLED
|
|
|
|
//#define SHADOWS_ENABLED
|
|
|
|
//#define SHADOWS_FIXSHADOWIDX
|
|
|
|
using UnityEngine.Rendering; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
s_ConvexBoundsBuffer = new ComputeBuffer(k_MaxLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightBound))); |
|
|
|
s_LightVolumeDataBuffer = new ComputeBuffer(k_MaxLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightVolumeData))); |
|
|
|
|
|
|
|
buildScreenAABBShader.SetBuffer(s_GenAABBKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "_LightVolumeData", s_LightVolumeDataBuffer); |
|
|
|
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
|
|
|
|
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "_LightVolumeData", s_LightVolumeDataBuffer); |
|
|
|
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
|
|
|
|
s_GlobalLightListAtomic = new ComputeBuffer(1, sizeof(uint)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "_LightVolumeData", s_LightVolumeDataBuffer); |
|
|
|
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
} |
|
|
|
|
|
|
|
s_shadeOpaqueClusteredKernel = shadeOpaqueShader.FindKernel("ShadeOpaque_Clustered"); |
|
|
|
|
|
|
|
|
|
|
// Restore values after "special rendering"
|
|
|
|
m_PassSettings.specularGlobalDimmer = oldSpecularGlobalDimmer; |
|
|
|
|
|
|
|
UpdateDataBuffers(); |
|
|
|
} |
|
|
|
|
|
|
|
void VoxelLightListGeneration(CommandBuffer cmd, Camera camera, Matrix4x4 projscr, Matrix4x4 invProjscr, RenderTargetIdentifier cameraDepthBufferRT) |
|
|
|
|
|
|
{ |
|
|
|
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_logBaseBuffer", s_PerTileLogBaseTweak); |
|
|
|
} |
|
|
|
|
|
|
|
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "_LightVolumeData", s_LightVolumeDataBuffer); |
|
|
|
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
|
|
|
|
var numTilesX = GetNumTileClusteredX(camera); |
|
|
|
var numTilesY = GetNumTileClusteredY(camera); |
|
|
|
|
|
|
var invProjh = projh.inverse; |
|
|
|
|
|
|
|
cmd.SetComputeIntParam(buildScreenAABBShader, "g_iNrVisibLights", m_lightCount); |
|
|
|
cmd.SetComputeBufferParam(buildScreenAABBShader, s_GenAABBKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
|
|
|
|
Utilities.SetMatrixCS(cmd, buildScreenAABBShader, "g_mProjection", projh); |
|
|
|
Utilities.SetMatrixCS(cmd, buildScreenAABBShader, "g_mInvProjection", invProjh); |
|
|
|
cmd.SetComputeBufferParam(buildScreenAABBShader, s_GenAABBKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
|
|
|
cmd.SetComputeFloatParam(buildPerBigTileLightListShader, "g_fNearPlane", camera.nearClipPlane); |
|
|
|
cmd.SetComputeFloatParam(buildPerBigTileLightListShader, "g_fFarPlane", camera.farClipPlane); |
|
|
|
cmd.SetComputeBufferParam(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, "g_vLightList", s_BigTileLightList); |
|
|
|
cmd.SetComputeBufferParam(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
cmd.SetComputeBufferParam(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, "_LightVolumeData", s_LightVolumeDataBuffer); |
|
|
|
cmd.SetComputeBufferParam(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
cmd.DispatchCompute(buildPerBigTileLightListShader, s_GenListPerBigTileKernel, numBigTilesX, numBigTilesY, 1); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
cmd.SetComputeIntParam(buildPerTileLightListShader, "_EnvLightIndexShift", m_lightList.lights.Count); |
|
|
|
cmd.SetComputeIntParam(buildPerTileLightListShader, "g_iNrVisibLights", m_lightCount); |
|
|
|
|
|
|
|
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer); |
|
|
|
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "_LightVolumeData", s_LightVolumeDataBuffer); |
|
|
|
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_data", s_ConvexBoundsBuffer); |
|
|
|
|
|
|
|
Utilities.SetMatrixCS(cmd, buildPerTileLightListShader, "g_mScrProjection", projscr); |
|
|
|
Utilities.SetMatrixCS(cmd, buildPerTileLightListShader, "g_mInvScrProjection", invProjscr); |
|
|
|
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_depth_tex", cameraDepthBufferRT); |
|
|
|
|
|
|
if (activeComputeShader) |
|
|
|
activeCommandBuffer.SetComputeTextureParam(activeComputeShader, activeComputeKernel, name, value); |
|
|
|
else |
|
|
|
Shader.SetGlobalTexture(name, value); |
|
|
|
activeCommandBuffer.SetGlobalTexture(name, value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
activeCommandBuffer.SetComputeBufferParam(activeComputeShader, activeComputeKernel, name, buffer); |
|
|
|
else |
|
|
|
Shader.SetGlobalBuffer(name, buffer); |
|
|
|
activeCommandBuffer.SetGlobalBuffer(name, buffer); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetGlobalInt(string name, int value) |
|
|
|
|
|
|
if (activeComputeShader) |
|
|
|
activeCommandBuffer.SetComputeFloatParam(activeComputeShader, name, value); |
|
|
|
else |
|
|
|
Shader.SetGlobalFloat(name, value); |
|
|
|
activeCommandBuffer.SetGlobalFloat(name, value); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetGlobalVector(string name, Vector4 value) |
|
|
|
|
|
|
else |
|
|
|
Shader.SetGlobalVector(name, value); |
|
|
|
activeCommandBuffer.SetGlobalVector(name, value); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetGlobalVectorArray(string name, Vector4[] values) |
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Shader.SetGlobalVectorArray(name, values); |
|
|
|
activeCommandBuffer.SetGlobalVectorArray(name, values); |
|
|
|
private void UpdateDataBuffers() |
|
|
|
{ |
|
|
|
s_DirectionalLightDatas.SetData(m_lightList.directionalLights.ToArray()); |
|
|
|
s_LightDatas.SetData(m_lightList.lights.ToArray()); |
|
|
|
s_EnvLightDatas.SetData(m_lightList.envLights.ToArray()); |
|
|
|
s_shadowDatas.SetData(m_lightList.shadows.ToArray()); |
|
|
|
|
|
|
|
// These two buffers have been set in Rebuild()
|
|
|
|
s_ConvexBoundsBuffer.SetData(m_lightList.bounds.ToArray()); |
|
|
|
s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes.ToArray()); |
|
|
|
} |
|
|
|
|
|
|
|
SetGlobalPropertyRedirect(computeShader, kernelIndex, cmd); |
|
|
|
SetGlobalBuffer("g_vLightListGlobal", !usingFptl ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)
|
|
|
|
|
|
|
|
SetGlobalTexture("_CookieTextures", m_CookieTexArray.GetTexCache()); |
|
|
|
SetGlobalTexture("_CookieCubeTextures", m_CubeCookieTexArray.GetTexCache()); |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void PushGlobalParams(Camera camera, ScriptableRenderContext loop) |
|
|
|
private void PushGlobalParams(Camera camera, ScriptableRenderContext loop, ComputeShader computeShader, int kernelIndex) |
|
|
|
|
|
|
|
s_DirectionalLightDatas.SetData(m_lightList.directionalLights.ToArray()); |
|
|
|
s_LightDatas.SetData(m_lightList.lights.ToArray()); |
|
|
|
s_EnvLightDatas.SetData(m_lightList.envLights.ToArray()); |
|
|
|
s_shadowDatas.SetData(m_lightList.shadows.ToArray()); |
|
|
|
|
|
|
|
// These two buffers have been set in Rebuild()
|
|
|
|
s_ConvexBoundsBuffer.SetData(m_lightList.bounds.ToArray()); |
|
|
|
s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes.ToArray()); |
|
|
|
|
|
|
|
BindGlobalParams(cmd, null, 0, camera, loop); |
|
|
|
|
|
|
|
SetGlobalPropertyRedirect(computeShader, kernelIndex, cmd); |
|
|
|
BindGlobalParams(cmd, computeShader, kernelIndex, camera, loop); |
|
|
|
SetGlobalPropertyRedirect(null, 0, null); |
|
|
|
|
|
|
|
loop.ExecuteCommandBuffer(cmd); |
|
|
|
|
|
|
using (new Utilities.ProfilingSample(m_PassSettings.enableTileAndCluster ? "TilePass - Deferred Lighting Pass" : "SinglePass - Deferred Lighting Pass", renderContext)) |
|
|
|
{ |
|
|
|
var cmd = new CommandBuffer(); |
|
|
|
|
|
|
|
SetGlobalBuffer("g_vLightListGlobal", bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)
|
|
|
|
|
|
|
|
if (lightDebugSettings.lightingDebugMode == LightingDebugMode.None) |
|
|
|
SetGlobalPropertyRedirect(shadeOpaqueShader, usingFptl ? s_shadeOpaqueFptlKernel : s_shadeOpaqueClusteredKernel, cmd); |
|
|
|
else |
|
|
|
SetGlobalPropertyRedirect(shadeOpaqueShader, usingFptl ? s_shadeOpaqueFptlDebugLightingKernel : s_shadeOpaqueClusteredDebugLightingKernel, cmd); |
|
|
|
|
|
|
|
// In case of bUseClusteredForDeferred disable toggle option since we're using m_perVoxelLightLists as opposed to lightList
|
|
|
|
if (bUseClusteredForDeferred) |
|
|
|
{ |
|
|
|
SetGlobalFloat("_UseTileLightList", 0); |
|
|
|
} |
|
|
|
var camera = hdCamera.camera; |
|
|
|
|
|
|
|
// Must be done after setting up the compute shader above.
|
|
|
|
SetupRenderingForDebug(lightDebugSettings); |
|
|
|
|
|
|
PushGlobalParams(camera, renderContext, null, 0); |
|
|
|
|
|
|
|
// This is a debug brute force renderer to debug tile/cluster which render all the lights
|
|
|
|
if (outputSplitLightingForSSS) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
if (m_PassSettings.enableComputeLightEvaluation) |
|
|
|
{ |
|
|
|
// Compute shader evaluation
|
|
|
|
int kernel = bUseClusteredForDeferred ? s_shadeOpaqueClusteredKernel : s_shadeOpaqueFptlKernel; |
|
|
|
int kernel = 0; |
|
|
|
if (lightDebugSettings.lightingDebugMode == LightingDebugMode.None) |
|
|
|
kernel = usingFptl ? s_shadeOpaqueFptlKernel : s_shadeOpaqueClusteredKernel; |
|
|
|
else |
|
|
|
kernel = usingFptl ? s_shadeOpaqueFptlDebugLightingKernel : s_shadeOpaqueClusteredDebugLightingKernel; |
|
|
|
var camera = hdCamera.camera; |
|
|
|
BindGlobalParams(cmd, shadeOpaqueShader, kernel, camera, renderContext); |
|
|
|
PushGlobalParams(camera, renderContext, shadeOpaqueShader, kernel); |
|
|
|
|
|
|
|
cmd.SetComputeBufferParam(shadeOpaqueShader, kernel, "g_vLightListGlobal", bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList); |
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
{ |
|
|
|
// Pixel shader evaluation
|
|
|
|
PushGlobalParams(camera, renderContext, null, 0); |
|
|
|
|
|
|
|
if (m_PassSettings.enableSplitLightEvaluation) |
|
|
|
{ |
|
|
|
if (outputSplitLightingForSSS) |
|
|
|