-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCS_DebugLightCount.compute
More file actions
45 lines (37 loc) · 1.4 KB
/
CS_DebugLightCount.compute
File metadata and controls
45 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
#pragma target 5.0
#include "Cgs_ClusterCommon.cginc"
Texture2D SourceTex;
Texture2D DepthTexture;
Texture2D LightCountHeatMapTex;
SamplerState sampler_linear_repeat;
StructuredBuffer<uint2> PointLightGrid_Cluster;
RWTexture2D<float4> RWDebugTexture;
[numthreads(32, 32, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
int2 texCoord = id.xy;
float fDepth = DepthTexture.Load(uint3(texCoord, 0)).x;
float4 fColor = SourceTex.Load(uint3(texCoord, 0));
uint lightCount = 0;
if (fDepth > 0)
{
float4 viewPos = ScreenToView(float4(texCoord, fDepth, 1));
viewPos.z *= -1;
// Compute the 3D cluster index.
uint3 clusterIndex3D = ComputeClusterIndex3D(texCoord, viewPos.z);
// Convert to 1D cluster index.
uint clusterIndex1D = ComputeClusterIndex1D(clusterIndex3D);
lightCount += PointLightGrid_Cluster[clusterIndex1D].y;
}
RWDebugTexture[texCoord] = fColor * 0.2;
if (lightCount > 0)
{
float normalizedLightCount = lightCount / 50.0f;
float4 lightCountColor = LightCountHeatMapTex.SampleLevel(sampler_linear_repeat, float2(normalizedLightCount, 0), 0);// tex2D(LightCountHeatMapTex, float2(normalizedLightCount, 0));
float3 color = lightCountColor.rgb;
//float4 color = tex2D(LightCountHeatMapTex, float2(normalizedLightCount, 0));
RWDebugTexture[texCoord] += float4(color.rgb, 0.9f);
}
}