Developping the Light Clusters, adding visualization

This commit is contained in:
samcake 2016-09-08 19:12:11 -07:00
parent fa27376bd0
commit 9bcaca0577

View file

@ -33,6 +33,18 @@ uniform frustrumGridBuffer {
FrustrumGrid frustrumGrid;
};
float getProjectionNear(mat4 projection) {
float planeC = projection[2][3] + projection[2][2];
float planeD = projection[3][2];
return planeD / planeC;
}
float getProjectionFar(mat4 projection) {
//float planeA = projection[0][3] - projection[0][2];
//float planeB = projection[1][3] - projection[1][2];
float planeC = projection[2][3] - projection[2][2];
float planeD = /*projection[3][3]*/ - projection[3][2];
return planeD / planeC;
}
//uniform ivec4 inClusterLocation;
out vec4 varColor;
@ -66,14 +78,24 @@ void main(void) {
vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]];
// pos.z -= 10.0f;
vec3 cpos = vec3(1, 0, 1);
// float z = frustrumGrid.nearFarRange.y * (1 - pos.z) + frustrumGrid.nearFarRange.z * (pos.z);
vec3 gridScale = vec3(0.5, 0.5, 1.0) / vec3(frustrumGrid.dims.xyz);
vec4 eyePos = frustrumGrid.eyeToGridProjInv * (pos);
vec3 cvpos = cpos + pos.xyz;
vec3 clusterStart = vec3(-1.0 + cvpos.x * gridScale.x, -1.0 + cvpos.y * gridScale.y, cvpos.z * gridScale.z);
float z = getProjectionNear(frustrumGrid.eyeToGridProj) * (1 - clusterStart.z) + getProjectionFar(frustrumGrid.eyeToGridProj) * (clusterStart.z);
vec4 eyePos = frustrumGrid.eyeToGridProjInv * (vec4(clusterStart.xy, 1.0, 1.0) * z);
eyePos.xyz *= eyePos.w;
vec4 worldPos = frustrumGrid.eyeToWorldMat * vec4(eyePos.xyz, 1.0);
/*
int cellIsEmpty = sign(inClusterLocation.w);
ivec4 cellLocation = ivec4(inClusterLocation.xyz, (inClusterLocation.w < 0 ? -inClusterLocation.w : inClusterLocation.w));