Update LightClusterGrid_shared.slh

This commit is contained in:
Sam Gondelman 2018-10-29 17:38:28 -07:00 committed by SamGondelman
parent dc9405775f
commit e534e09801
12 changed files with 35 additions and 33 deletions

View file

@ -121,7 +121,7 @@ vec4 unpackDeferredPosition(float depthValue, vec2 texcoord) {
float check2 = check * float(texcoord.x > 0.5); float check2 = check * float(texcoord.x > 0.5);
texcoord.x -= check2 * 0.5; texcoord.x -= check2 * 0.5;
int side = int(check2); int side = int(check2);
texcoord.x *= mix(1.0, 2.0, check); texcoord.x *= 1.0 + check;
return vec4(evalEyePositionFromZdb(side, depthValue, texcoord), 1.0); return vec4(evalEyePositionFromZdb(side, depthValue, texcoord), 1.0);
} }
@ -139,7 +139,7 @@ vec4 unpackDeferredPositionFromZeye(vec2 texcoord) {
float check2 = check * float(texcoord.x > 0.5); float check2 = check * float(texcoord.x > 0.5);
texcoord.x -= check2 * 0.5; texcoord.x -= check2 * 0.5;
int side = int(check2); int side = int(check2);
texcoord.x *= mix(1.0, 2.0, check); texcoord.x *= 1.0 + check;
return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0); return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0);
} }

View file

@ -30,7 +30,7 @@ vec4 unpackPositionFromZeye(vec2 texcoord) {
float check2 = check * float(texcoord.x > 0.5); float check2 = check * float(texcoord.x > 0.5);
texcoord.x -= check2 * 0.5; texcoord.x -= check2 * 0.5;
int side = int(check2); int side = int(check2);
texcoord.x *= mix(1.0, 2.0, check); texcoord.x *= 1.0 + check;
return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0); return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0);
} }

View file

@ -83,7 +83,7 @@ int clusterGrid_getClusterLightId(int index, int offset) {
return element; return element;
*/ */
int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))]; int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))];
return int(mix(element, element >> 16, int((elementIndex & 0x00000001) == 1))) & 0x0000FFFF; return (element >> (16 * int((elementIndex & 0x00000001) == 1))) & 0x0000FFFF;
} }

View file

@ -7,11 +7,9 @@
#ifdef __cplusplus #ifdef __cplusplus
# define _MIN glm::min # define _MIN glm::min
# define _MIX(x, y, a) glm::mix((float)x, (float)y, (float)a) # define _ABS(x) (int)fabsf(x)
# define _ABS(x) (int)fabsf()
#else #else
# define _MIN min # define _MIN min
# define _MIX mix
# define _ABS abs # define _ABS abs
#endif #endif
@ -151,7 +149,7 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) {
int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { int frustumGrid_eyeToClusterDirH(vec3 eyeDir) {
if (eyeDir.z >= 0.0f) { if (eyeDir.z >= 0.0f) {
return int(_MIX(-1, frustumGrid.dims.x, int(eyeDir.x > 0.0f))); return int(eyeDir.x > 0.0f) * (frustumGrid.dims.x + 1) - 1;
} }
float eyeDepth = -eyeDir.z; float eyeDepth = -eyeDir.z;
@ -165,7 +163,7 @@ int frustumGrid_eyeToClusterDirH(vec3 eyeDir) {
int frustumGrid_eyeToClusterDirV(vec3 eyeDir) { int frustumGrid_eyeToClusterDirV(vec3 eyeDir) {
if (eyeDir.z >= 0.0f) { if (eyeDir.z >= 0.0f) {
return int(_MIX(-1, frustumGrid.dims.y, int(eyeDir.y > 0.0f))); return int(eyeDir.y > 0.0f) * (frustumGrid.dims.y + 1) - 1;
} }
float eyeDepth = -eyeDir.z; float eyeDepth = -eyeDir.z;

View file

@ -40,10 +40,12 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
diffuse *= lightEnergy * isDiffuseEnabled(); diffuse *= lightEnergy * isDiffuseEnabled();
specular *= lightEnergy * isSpecularEnabled(); specular *= lightEnergy * isSpecularEnabled();
if (isShowLightContour() > 0.0) {
// Show edges // Show edges
float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0);
float edgeCoord = exp2(-8.0 * edge * edge); float edgeCoord = exp2(-8.0 * edge * edge);
diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(isShowLightContour() > 0.0 && edge < 1.0)); diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0));
}
} }
<@endfunc@> <@endfunc@>

View file

@ -41,13 +41,15 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
diffuse *= lightEnergy * isDiffuseEnabled(); diffuse *= lightEnergy * isDiffuseEnabled();
specular *= lightEnergy * isSpecularEnabled(); specular *= lightEnergy * isSpecularEnabled();
if (isShowLightContour() > 0.0) {
// Show edges // Show edges
float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance);
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume));
float edgeDist = min(edgeDistR, edgeDistS); float edgeDist = min(edgeDistR, edgeDistS);
float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); float edge = abs(2.0 * (edgeDist * 10.0) - 1.0);
float edgeCoord = exp2(-8.0 * edge * edge); float edgeCoord = exp2(-8.0 * edge * edge);
diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(isShowLightContour() > 0.0 && edge < 1.0)); diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0));
}
} }
<@endfunc@> <@endfunc@>

View file

@ -53,9 +53,8 @@ void main(void) {
// Add or subtract the orthogonal vector based on a different vertex ID // Add or subtract the orthogonal vector based on a different vertex ID
// calculation // calculation
float check = float(gl_VertexID < 2); distanceFromCenter = mix(1.0, -1.0, float(gl_VertexID < 2));
distanceFromCenter = mix(1.0, -1.0, check); eye.xyz += distanceFromCenter * orthogonal;
eye.xyz += mix(orthogonal, -orthogonal, check);
// Finally, put the eyespace vertex into clip space // Finally, put the eyespace vertex into clip space
<$transformEyeToClipPos(cam, eye, gl_Position)$> <$transformEyeToClipPos(cam, eye, gl_Position)$>

View file

@ -69,5 +69,5 @@ void main(void) {
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
<$transformWorldToClipPos(cam, worldPos, gl_Position)$> <$transformWorldToClipPos(cam, worldPos, gl_Position)$>
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), mix(0.1, 0.9, float(numLights > 0))); varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.1 + 0.8 * float(numLights > 0));
} }

View file

@ -93,7 +93,8 @@ void main(void) {
{ {
bool check = dot(fragToTap,fragToTap) < keepTapRadius; bool check = dot(fragToTap,fragToTap) < keepTapRadius;
keep = keep || check; keep = keep || check;
keepedMip = int(mix(keepedMip, evalMipFromRadius(tap.z * float(doFetchMips())), int(check))); int checki = int(check);
keepedMip = checki * evalMipFromRadius(tap.z * float(doFetchMips())) + (1 - checki) * keepedMip;
} }
vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize); vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize);

View file

@ -89,7 +89,7 @@ void main(void) {
vec2 texcoordPos; vec2 texcoordPos;
ivec4 stereoSide; ivec4 stereoSide;
ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide); ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide);
vec2 stereoSideClip = vec2(stereoSide.x, mix(1.0, 0.5, float(isStereo()))); vec2 stereoSideClip = vec2(stereoSide.x, 1.0 - 0.5 * float(isStereo()));
// Texcoord to fetch in the deferred texture are the exact UVs comming from vertex shader // Texcoord to fetch in the deferred texture are the exact UVs comming from vertex shader
// sideToFrameTexcoord(stereoSideClip, texcoordPos); // sideToFrameTexcoord(stereoSideClip, texcoordPos);
@ -124,7 +124,7 @@ void main(void) {
// Calculate dF/du and dF/dv // Calculate dF/du and dF/dv
vec2 viewportScale = perspectiveScale * getInvWidthHeight(); vec2 viewportScale = perspectiveScale * getInvWidthHeight();
vec2 du = vec2(viewportScale.x * mix(1.0, 0.5, float(float(stereoSide.w) > 0.0)), 0.0); vec2 du = vec2(viewportScale.x * (1.0 - 0.5 * float(stereoSide.w > 0)), 0.0);
vec2 dv = vec2( 0.0f, viewportScale.y); vec2 dv = vec2( 0.0f, viewportScale.y);
vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du)); vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du));

View file

@ -125,13 +125,13 @@ float taa_fetchDepth(vec2 uv) {
vec2 taa_getImageSize() { vec2 taa_getImageSize() {
vec2 imageSize = getWidthHeight(0); vec2 imageSize = getWidthHeight(0);
imageSize.x *= mix(1.0, 2.0, float(isStereo())); imageSize.x *= 1.0 + float(isStereo());
return imageSize; return imageSize;
} }
vec2 taa_getTexelSize() { vec2 taa_getTexelSize() {
vec2 texelSize = getInvWidthHeight(); vec2 texelSize = getInvWidthHeight();
texelSize.x *= mix(1.0, 0.5, float(isStereo())); texelSize.x *= 1.0 - 0.5 * float(isStereo());
return texelSize; return texelSize;
} }
@ -216,14 +216,14 @@ vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) {
float check2 = float(eyeUV.x > 0.5); float check2 = float(eyeUV.x > 0.5);
eyeUV.x -= check * check2 * 0.5; eyeUV.x -= check * check2 * 0.5;
stereoSide = int(check * check2); stereoSide = int(check * check2);
eyeUV.x *= mix(1.0, 2.0, check); eyeUV.x *= 1.0 + check;
return eyeUV; return eyeUV;
} }
vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) { vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) {
vec2 fragUV = eyeUV; vec2 fragUV = eyeUV;
float check = float(isStereo()); float check = float(isStereo());
fragUV.x *= mix(1.0, 0.5, check); fragUV.x *= 1.0 - 0.5 * check;
fragUV.x += check * float(stereoSide) * 0.5; fragUV.x += check * float(stereoSide) * 0.5;
return fragUV; return fragUV;
} }

View file

@ -19,6 +19,6 @@ void main(void) {
float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5); float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5);
outFragColor = mix(vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a), outFragColor = mix(vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a),
vec4(mix(vec3(0.0), varColor.xyz, var), mix(0.0, 1.0, var)), vec4(mix(vec3(0.0), varColor.xyz, var), var),
float(varColor.a == 0.0)); float(varColor.a == 0.0));
} }