You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
3.2 KiB
77 lines
3.2 KiB
#pragma kernel DebugLightCluster
|
|
|
|
#pragma only_renderers d3d11 xboxseries ps5 switch2
|
|
|
|
#define DEBUG_LIGHT_CLUSTER_TILE_SIZE 8
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingLightCluster.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl"
|
|
|
|
// Color gradient texture used for the lightcount heatmap
|
|
TEXTURE2D(_DebugColorGradientTexture);
|
|
|
|
// The output texture for the cluster debug
|
|
RW_TEXTURE2D_X(float4, _DebutLightClusterTexture);
|
|
|
|
int _ClusterLightCategoryDebug = 0;
|
|
|
|
[numthreads(DEBUG_LIGHT_CLUSTER_TILE_SIZE, DEBUG_LIGHT_CLUSTER_TILE_SIZE, 1)]
|
|
void DebugLightCluster(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID)
|
|
{
|
|
// Fetch the current pixel coordinate
|
|
uint2 currentPixelCoordinate = groupId * DEBUG_LIGHT_CLUSTER_TILE_SIZE + groupThreadId;
|
|
|
|
// Convert this to a world space position
|
|
float depth = LoadCameraDepth(currentPixelCoordinate.xy);
|
|
|
|
// If this is a background set it to black
|
|
if (depth == UNITY_RAW_FAR_CLIP_VALUE)
|
|
{
|
|
_DebutLightClusterTexture[COORD_TEXTURE2D_X(currentPixelCoordinate)] = float4(0.0, 0.0, 0.0, 1.0f);
|
|
return;
|
|
}
|
|
|
|
// Compute the real world space position of this pixel
|
|
PositionInputs posInput = GetPositionInput(currentPixelCoordinate, 1.0 / _ScreenSize.xy, depth, UNITY_MATRIX_I_VP, GetWorldToViewMatrix(), 0);
|
|
|
|
// If this position is outside of the cluster, color is gray
|
|
if(!PointInsideCluster(posInput.positionWS))
|
|
{
|
|
_DebutLightClusterTexture[COORD_TEXTURE2D_X(currentPixelCoordinate)] = float4(0.1, 0.1, 0.1, 1.0f);
|
|
return;
|
|
}
|
|
|
|
uint cellIndex = GetClusterCellIndex(posInput.positionWS);
|
|
|
|
// Fetch the light count for the specified light category
|
|
uint numLights;
|
|
if (_ClusterLightCategoryDebug < LIGHTCATEGORY_COUNT)
|
|
{
|
|
uint lightStart, lightEnd;
|
|
GetLightCountAndStartCluster(posInput.positionWS, _ClusterLightCategoryDebug, lightStart, lightEnd, cellIndex);
|
|
numLights = lightEnd - lightStart;
|
|
}
|
|
else
|
|
{
|
|
numLights = GetTotalLightClusterCellCount(cellIndex);
|
|
}
|
|
|
|
// If this pixel has no lights, let the color to gray
|
|
if(numLights == 0)
|
|
{
|
|
_DebutLightClusterTexture[COORD_TEXTURE2D_X(currentPixelCoordinate)] = float4(0.1, 0.1, 0.1, 1.0f);
|
|
return;
|
|
}
|
|
|
|
// Get the heatmap color from numLights.
|
|
float3 cellColor = numLights >= _LightPerCellCount || numLights >= DEBUG_COLORS_COUNT ? float3(0.7, 0.0, 0.0) // red
|
|
: kDebugColorGradient[numLights].xyz;
|
|
|
|
// Return the color
|
|
_DebutLightClusterTexture[COORD_TEXTURE2D_X(currentPixelCoordinate)] = float4(cellColor, 1.0);
|
|
}
|