-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvpl_processor.comp
72 lines (52 loc) · 2.17 KB
/
vpl_processor.comp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#version 430
#extension GL_ARB_shading_language_include : require
#include </data/shaders/common/floatpacking.glsl>
uniform sampler2D rsmDiffuseSampler;
uniform sampler2D rsmNormalSampler;
uniform sampler2D rsmDepthSampler;
uniform mat4 biasedLightViewProjectionInverseMatrix;
uniform float lightIntensity;
uniform bool shuffleLights;
const int totalVplCount = 1024;
layout (local_size_x = 64) in;
struct VPL {
vec3 position;
vec3 normal;
vec3 color;
};
layout (packed, binding = 0) buffer vplBuffer_
{
VPL vplBuffer[];
};
layout (std140, binding = 1) buffer packedVplBuffer_
{
vec4 packedVplBuffer[];
};
layout (packed, binding = 1) uniform shuffledIndicesBuffer_
{
int shuffledIndicesBuffer[totalVplCount];
};
const uint rsmSamples1d = uint(ceil(sqrt(totalVplCount)));
void main()
{
uint resultIndex = gl_WorkGroupID.x * gl_WorkGroupSize.x + gl_LocalInvocationID.x;
uint totalWorkCount = gl_NumWorkGroups.x * gl_WorkGroupSize.x;
uvec2 lightsOnAxis = uvec2(rsmSamples1d, totalWorkCount / rsmSamples1d);
ivec2 samplerSize = textureSize(rsmDiffuseSampler, 0);
uvec2 texCoords = uvec2(resultIndex % lightsOnAxis.x, resultIndex / lightsOnAxis.x) * samplerSize / lightsOnAxis;
vec2 texCoordsf = vec2(texCoords) / samplerSize;
vec3 diffuse = texelFetch(rsmDiffuseSampler, ivec2(texCoords), 0).rgb;
vec3 normal = texelFetch(rsmNormalSampler, ivec2(texCoords), 0).rgb * 2.0 - 1.0;
float depth = texelFetch(rsmDepthSampler, ivec2(texCoords), 0).r;
vec4 worldcoords = biasedLightViewProjectionInverseMatrix * vec4(texCoordsf, depth, 1.0);
worldcoords.xyz /= worldcoords.w;
vec3 lightColor = diffuse * lightIntensity;
if (shuffleLights)
resultIndex = shuffledIndicesBuffer[resultIndex];
float packedNormal = pack3SNToFloat(vec3(normal));
// make sure everyone's accessing the same values
// final_gathering.comp could also read the packedNormal directly and unpack it, but that's quite slow for some reason
vec3 unpackedNormal = unpack3SNFromFloat(packedNormal);
vplBuffer[resultIndex] = VPL(worldcoords.xyz, unpackedNormal, lightColor);
packedVplBuffer[resultIndex] = vec4(worldcoords.xyz, packedNormal);
}