|
|
|
|
|
|
// enable unity's original left-hand shader camera space (right-hand internally in unity).
|
|
|
|
public static int USE_LEFTHAND_CAMERASPACE = 1; |
|
|
|
|
|
|
|
public static int TILE_SIZE_FPTL = 16; |
|
|
|
public static int TILE_SIZE_CLUSTERED = 32; |
|
|
|
|
|
|
|
// flags
|
|
|
|
public static int IS_CIRCULAR_SPOT_SHAPE = 1; |
|
|
|
public static int HAS_COOKIE_TEXTURE = 2; |
|
|
|
|
|
|
Material m_SingleDeferredMaterialSRT = null; |
|
|
|
Material m_SingleDeferredMaterialMRT = null; |
|
|
|
|
|
|
|
const int k_TileSize = 16; |
|
|
|
|
|
|
|
#if (SHADOWS_ENABLED)
|
|
|
|
// shadow related stuff
|
|
|
|
FrameId m_FrameId; |
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
int GetNumTileX(Camera camera) |
|
|
|
int GetNumTileFtplX(Camera camera) |
|
|
|
{ |
|
|
|
return (camera.pixelWidth + (LightDefinitions.TILE_SIZE_FPTL - 1)) / LightDefinitions.TILE_SIZE_FPTL; |
|
|
|
} |
|
|
|
int GetNumTileFtplY(Camera camera) |
|
|
|
{ |
|
|
|
return (camera.pixelHeight + (LightDefinitions.TILE_SIZE_FPTL - 1)) / LightDefinitions.TILE_SIZE_FPTL; |
|
|
|
} |
|
|
|
|
|
|
|
int GetNumTileClusteredX(Camera camera) |
|
|
|
return (camera.pixelWidth + (k_TileSize - 1)) / k_TileSize; |
|
|
|
return (camera.pixelWidth + (LightDefinitions.TILE_SIZE_CLUSTERED - 1)) / LightDefinitions.TILE_SIZE_CLUSTERED; |
|
|
|
int GetNumTileY(Camera camera) |
|
|
|
int GetNumTileClusteredY(Camera camera) |
|
|
|
return (camera.pixelHeight + (k_TileSize - 1)) / k_TileSize; |
|
|
|
return (camera.pixelHeight + (LightDefinitions.TILE_SIZE_CLUSTERED - 1)) / LightDefinitions.TILE_SIZE_CLUSTERED; |
|
|
|
} |
|
|
|
|
|
|
|
TileLightLoopProducer.TileSettings m_PassSettings; |
|
|
|
|
|
|
|
|
|
|
public override void AllocResolutionDependentBuffers(int width, int height) |
|
|
|
{ |
|
|
|
var nrTilesX = (width + k_TileSize - 1) / k_TileSize; |
|
|
|
var nrTilesY = (height + k_TileSize - 1) / k_TileSize; |
|
|
|
var nrTilesX = (width + LightDefinitions.TILE_SIZE_FPTL - 1) / LightDefinitions.TILE_SIZE_FPTL; |
|
|
|
var nrTilesY = (height + LightDefinitions.TILE_SIZE_FPTL - 1) / LightDefinitions.TILE_SIZE_FPTL; |
|
|
|
var nrTiles = nrTilesX * nrTilesY; |
|
|
|
const int capacityUShortsPerTile = 32; |
|
|
|
const int dwordsPerTile = (capacityUShortsPerTile + 1) >> 1; // room for 31 lights and a nrLights value.
|
|
|
|
|
|
|
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_logBaseBuffer", s_PerTileLogBaseTweak); |
|
|
|
} |
|
|
|
|
|
|
|
var numTilesX = GetNumTileX(camera); |
|
|
|
var numTilesY = GetNumTileY(camera); |
|
|
|
var numTilesX = GetNumTileClusteredX(camera); |
|
|
|
var numTilesY = GetNumTileClusteredY(camera); |
|
|
|
cmd.DispatchCompute(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, numTilesX, numTilesY, 1); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var h = camera.pixelHeight; |
|
|
|
var numTilesX = GetNumTileX(camera); |
|
|
|
var numTilesY = GetNumTileY(camera); |
|
|
|
var numBigTilesX = (w + 63) / 64; |
|
|
|
var numBigTilesY = (h + 63) / 64; |
|
|
|
|
|
|
|
|
|
|
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vLightList", s_LightList); |
|
|
|
if (m_PassSettings.enableBigTilePrepass) |
|
|
|
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vBigTileLightList", s_BigTileLightList); |
|
|
|
var numTilesX = GetNumTileFtplX(camera); |
|
|
|
var numTilesY = GetNumTileFtplY(camera); |
|
|
|
cmd.DispatchCompute(buildPerTileLightListShader, s_GenListPerTileKernel, numTilesX, numTilesY, 1); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
SetGlobalBuffer("_ShadowDatas", s_shadowDatas); |
|
|
|
SetGlobalVectorArray("_DirShadowSplitSpheres", m_lightList.directionalShadowSplitSphereSqr); |
|
|
|
|
|
|
|
SetGlobalInt("_NumTileX", GetNumTileX(camera)); |
|
|
|
SetGlobalInt("_NumTileY", GetNumTileY(camera)); |
|
|
|
SetGlobalInt("_NumTileFtplX", GetNumTileFtplX(camera)); |
|
|
|
SetGlobalInt("_NumTileFtplY", GetNumTileFtplY(camera)); |
|
|
|
|
|
|
|
SetGlobalInt("_NumTileClusteredX", GetNumTileClusteredX(camera)); |
|
|
|
SetGlobalInt("_NumTileClusteredY", GetNumTileClusteredY(camera)); |
|
|
|
|
|
|
|
if (m_PassSettings.enableBigTilePrepass) |
|
|
|
SetGlobalBuffer("g_vBigTileLightList", s_BigTileLightList); |
|
|
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
using (new Utilities.ProfilingSample(m_PassSettings.disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass", renderContext)) |
|
|
|
using (new Utilities.ProfilingSample(m_PassSettings.enableTileAndCluster ? "TilePass - Deferred Lighting Pass" : "SinglePass - Deferred Lighting Pass", renderContext)) |
|
|
|
{ |
|
|
|
var cmd = new CommandBuffer(); |
|
|
|
|
|
|
|
|
|
|
// Must be done after setting up the compute shader above.
|
|
|
|
SetupRenderingForDebug(lightDebugSettings); |
|
|
|
|
|
|
|
if (m_PassSettings.disableTileAndCluster) |
|
|
|
if (!m_PassSettings.enableTileAndCluster) |
|
|
|
{ |
|
|
|
// This is a debug brute force renderer to debug tile/cluster which render all the lights
|
|
|
|
if (outputSplitLightingForSSS) |
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (!m_PassSettings.disableDeferredShadingInCompute) |
|
|
|
if (m_PassSettings.enableComputeLightEvaluation) |
|
|
|
|
|
|
|
int w = camera.pixelWidth; |
|
|
|
int h = camera.pixelHeight; |
|
|
|
int numTilesX = GetNumTileX(camera); |
|
|
|
int numTilesY = GetNumTileY(camera); |
|
|
|
|
|
|
|
// Pass global parameters to compute shader
|
|
|
|
// TODO: get rid of this by making global parameters visible to compute shaders
|
|
|
|
BindGlobalParams(cmd, shadeOpaqueShader, kernel, camera, renderContext); |
|
|
|
|
|
|
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_SkyTexture", skyTexture ? skyTexture : m_DefaultTexture2DArray); |
|
|
|
|
|
|
|
// Since we need the stencil test, the compute path does not currently support SSS.
|
|
|
|
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "combinedLightingUAV", colorBuffers[0]); |
|
|
|
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "combinedLightingUAV", colorBuffers[0]); |
|
|
|
|
|
|
|
int w = camera.pixelWidth; |
|
|
|
int h = camera.pixelHeight; |
|
|
|
int numTilesX = bUseClusteredForDeferred ? GetNumTileClusteredX(camera) : GetNumTileFtplX(camera); |
|
|
|
int numTilesY = bUseClusteredForDeferred ? GetNumTileClusteredY(camera) : GetNumTileFtplY(camera); |
|
|
|
cmd.DispatchCompute(shadeOpaqueShader, kernel, numTilesX, numTilesY, 1); |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
var cmd = new CommandBuffer(); |
|
|
|
|
|
|
|
if (m_PassSettings.disableTileAndCluster) |
|
|
|
if (!m_PassSettings.enableTileAndCluster) |
|
|
|
{ |
|
|
|
cmd.name = "Forward pass"; |
|
|
|
cmd.EnableShaderKeyword("LIGHTLOOP_SINGLE_PASS"); |
|
|
|