Modified light outline shader to use some factorized code

This commit is contained in:
Olivier Prat 2018-01-15 12:18:22 +01:00
parent 6af6b5fe41
commit a3e50689cb
3 changed files with 29 additions and 48 deletions

View file

@ -86,4 +86,31 @@ int clusterGrid_getClusterLightId(int index, int offset) {
return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF; return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF;
} }
<@func fetchClusterInfo(fragWorldPos)@>
// From frag world pos find the cluster
vec4 clusterEyePos = frustumGrid_worldToEye(<$fragWorldPos$>);
ivec3 clusterPos = frustumGrid_eyeToClusterPos(clusterEyePos.xyz);
ivec3 cluster = clusterGrid_getCluster(frustumGrid_clusterToIndex(clusterPos));
int numLights = cluster.x + cluster.y;
if (numLights <= 0) {
discard;
}
ivec3 dims = frustumGrid.dims.xyz;
if (clusterPos.x < 0 || clusterPos.x >= dims.x) {
discard;
}
if (clusterPos.y < 0 || clusterPos.y >= dims.y) {
discard;
}
if (clusterPos.z < 0 || clusterPos.z > dims.z) {
discard;
}
<@endfunc@>
<@endif@> <@endif@>

View file

@ -20,32 +20,6 @@
<@include LightClusterGrid.slh@> <@include LightClusterGrid.slh@>
<@func fetchClusterInfo(fragWorldPos)@>
// From frag world pos find the cluster
vec4 clusterEyePos = frustumGrid_worldToEye(<$fragWorldPos$>);
ivec3 clusterPos = frustumGrid_eyeToClusterPos(clusterEyePos.xyz);
ivec3 cluster = clusterGrid_getCluster(frustumGrid_clusterToIndex(clusterPos));
int numLights = cluster.x + cluster.y;
if (numLights <= 0) {
discard;
}
ivec3 dims = frustumGrid.dims.xyz;
if (clusterPos.x < 0 || clusterPos.x >= dims.x) {
discard;
}
if (clusterPos.y < 0 || clusterPos.y >= dims.y) {
discard;
}
if (clusterPos.z < 0 || clusterPos.z > dims.z) {
discard;
}
<@endfunc@>
vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fragNormal, vec3 fragEyeDir, vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fragNormal, vec3 fragEyeDir,
vec4 midNormalCurvature, vec4 lowNormalCurvature, vec4 midNormalCurvature, vec4 lowNormalCurvature,
float fragRoughness, float fragScattering, float fragMetallic, vec3 fragFresnel, vec3 fragAlbedo) { float fragRoughness, float fragScattering, float fragMetallic, vec3 fragFresnel, vec3 fragAlbedo) {

View file

@ -54,34 +54,14 @@ void main(void) {
mat4 invViewMat = getViewInverse(); mat4 invViewMat = getViewInverse();
vec4 fragPos = invViewMat * fragPosition; vec4 fragPos = invViewMat * fragPosition;
// From frag world pos find the cluster <$fetchClusterInfo(fragPos)$>;
vec4 clusterEyePos = frustumGrid_worldToEye(fragPos);
ivec3 clusterPos = frustumGrid_eyeToClusterPos(clusterEyePos.xyz);
ivec3 cluster = clusterGrid_getCluster(frustumGrid_clusterToIndex(clusterPos));
int numLights = cluster.x + cluster.y;
if (numLights <= 0) {
discard;
}
int lightClusterOffset = cluster.z;
ivec3 dims = frustumGrid.dims.xyz;
if (clusterPos.x < 0 || clusterPos.x >= dims.x) {
discard;
}
if (clusterPos.y < 0 || clusterPos.y >= dims.y) {
discard;
}
if (clusterPos.z < 0 || clusterPos.z > dims.z) {
discard;
}
// Frag to eye vec // Frag to eye vec
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0); vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
vec3 fragEyeDir = normalize(fragEyeVector.xyz); vec3 fragEyeDir = normalize(fragEyeVector.xyz);
int numLightTouching = 0; int numLightTouching = 0;
int lightClusterOffset = cluster.z;
for (int i = 0; i < cluster.x; i++) { for (int i = 0; i < cluster.x; i++) {
// Need the light now // Need the light now
int theLightIndex = clusterGrid_getClusterLightId(i, lightClusterOffset); int theLightIndex = clusterGrid_getClusterLightId(i, lightClusterOffset);