From e534e09801ec664784959711b73779f1d4b53311 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Mon, 29 Oct 2018 17:38:28 -0700 Subject: [PATCH] Update LightClusterGrid_shared.slh --- .../render-utils/src/DeferredBufferRead.slh | 4 ++-- libraries/render-utils/src/Haze.slf | 2 +- libraries/render-utils/src/LightClusterGrid.slh | 2 +- .../render-utils/src/LightClusterGrid_shared.slh | 10 ++++------ libraries/render-utils/src/LightPoint.slh | 10 ++++++---- libraries/render-utils/src/LightSpot.slh | 16 +++++++++------- libraries/render-utils/src/glowLine.slv | 5 ++--- .../src/lightClusters_drawClusterContent.slv | 2 +- .../render-utils/src/ssao_debugOcclusion.slf | 3 ++- .../src/surfaceGeometry_makeCurvature.slf | 4 ++-- libraries/render-utils/src/taa.slh | 8 ++++---- libraries/render/src/render/drawItemBounds.slf | 2 +- 12 files changed, 35 insertions(+), 33 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index a6a6a6b1ac..868b93ff91 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -121,7 +121,7 @@ vec4 unpackDeferredPosition(float depthValue, vec2 texcoord) { float check2 = check * float(texcoord.x > 0.5); texcoord.x -= check2 * 0.5; 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); } @@ -139,7 +139,7 @@ vec4 unpackDeferredPositionFromZeye(vec2 texcoord) { float check2 = check * float(texcoord.x > 0.5); texcoord.x -= check2 * 0.5; 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); } diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf index b64d4172c6..170e69eb2d 100644 --- a/libraries/render-utils/src/Haze.slf +++ b/libraries/render-utils/src/Haze.slf @@ -30,7 +30,7 @@ vec4 unpackPositionFromZeye(vec2 texcoord) { float check2 = check * float(texcoord.x > 0.5); texcoord.x -= check2 * 0.5; 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); } diff --git a/libraries/render-utils/src/LightClusterGrid.slh b/libraries/render-utils/src/LightClusterGrid.slh index df8ba001f5..cd944489ec 100644 --- a/libraries/render-utils/src/LightClusterGrid.slh +++ b/libraries/render-utils/src/LightClusterGrid.slh @@ -83,7 +83,7 @@ int clusterGrid_getClusterLightId(int index, int offset) { return element; */ 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; } diff --git a/libraries/render-utils/src/LightClusterGrid_shared.slh b/libraries/render-utils/src/LightClusterGrid_shared.slh index 476ca6284f..cf58ce56ff 100644 --- a/libraries/render-utils/src/LightClusterGrid_shared.slh +++ b/libraries/render-utils/src/LightClusterGrid_shared.slh @@ -7,11 +7,9 @@ #ifdef __cplusplus # define _MIN glm::min -# define _MIX(x, y, a) glm::mix((float)x, (float)y, (float)a) -# define _ABS(x) (int)fabsf() +# define _ABS(x) (int)fabsf(x) #else # define _MIN min -# define _MIX mix # define _ABS abs #endif @@ -151,7 +149,7 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) { int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { 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; @@ -165,7 +163,7 @@ int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { int frustumGrid_eyeToClusterDirV(vec3 eyeDir) { 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; @@ -193,4 +191,4 @@ vec4 frustumGrid_worldToEye(vec4 worldPos) { // <@if 1@> // Trigger Scribe include - // <@endif@> End C++ compatible \ No newline at end of file + // <@endif@> End C++ compatible diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index 7c59cf85ef..6100627105 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -40,10 +40,12 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, diffuse *= lightEnergy * isDiffuseEnabled(); specular *= lightEnergy * isSpecularEnabled(); - // Show edges - float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); - float edgeCoord = exp2(-8.0 * edge * edge); - diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(isShowLightContour() > 0.0 && edge < 1.0)); + if (isShowLightContour() > 0.0) { + // Show edges + float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); + float edgeCoord = exp2(-8.0 * edge * edge); + diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); + } } <@endfunc@> diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 799021c459..7fea9856d8 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -41,13 +41,15 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, diffuse *= lightEnergy * isDiffuseEnabled(); specular *= lightEnergy * isSpecularEnabled(); - // Show edges - float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); - float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); - float edgeDist = min(edgeDistR, edgeDistS); - float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); - float edgeCoord = exp2(-8.0 * edge * edge); - diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(isShowLightContour() > 0.0 && edge < 1.0)); + if (isShowLightContour() > 0.0) { + // Show edges + float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); + float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); + float edgeDist = min(edgeDistR, edgeDistS); + float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); + float edgeCoord = exp2(-8.0 * edge * edge); + diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); + } } <@endfunc@> diff --git a/libraries/render-utils/src/glowLine.slv b/libraries/render-utils/src/glowLine.slv index 609082878b..ecb1152d52 100644 --- a/libraries/render-utils/src/glowLine.slv +++ b/libraries/render-utils/src/glowLine.slv @@ -53,9 +53,8 @@ void main(void) { // Add or subtract the orthogonal vector based on a different vertex ID // calculation - float check = float(gl_VertexID < 2); - distanceFromCenter = mix(1.0, -1.0, check); - eye.xyz += mix(orthogonal, -orthogonal, check); + distanceFromCenter = mix(1.0, -1.0, float(gl_VertexID < 2)); + eye.xyz += distanceFromCenter * orthogonal; // Finally, put the eyespace vertex into clip space <$transformEyeToClipPos(cam, eye, gl_Position)$> diff --git a/libraries/render-utils/src/lightClusters_drawClusterContent.slv b/libraries/render-utils/src/lightClusters_drawClusterContent.slv index 51718e6d8f..c30252da41 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterContent.slv +++ b/libraries/render-utils/src/lightClusters_drawClusterContent.slv @@ -69,5 +69,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$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)); } \ No newline at end of file diff --git a/libraries/render-utils/src/ssao_debugOcclusion.slf b/libraries/render-utils/src/ssao_debugOcclusion.slf index 43c3d15ece..612e5b862b 100644 --- a/libraries/render-utils/src/ssao_debugOcclusion.slf +++ b/libraries/render-utils/src/ssao_debugOcclusion.slf @@ -93,7 +93,8 @@ void main(void) { { bool check = dot(fragToTap,fragToTap) < keepTapRadius; 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); diff --git a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf index 433b3e97dc..dd9b98b5e5 100644 --- a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf +++ b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf @@ -89,7 +89,7 @@ void main(void) { vec2 texcoordPos; ivec4 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 // sideToFrameTexcoord(stereoSideClip, texcoordPos); @@ -124,7 +124,7 @@ void main(void) { // Calculate dF/du and dF/dv 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); vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du)); diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 827bcec644..ed9162516e 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -125,13 +125,13 @@ float taa_fetchDepth(vec2 uv) { vec2 taa_getImageSize() { vec2 imageSize = getWidthHeight(0); - imageSize.x *= mix(1.0, 2.0, float(isStereo())); + imageSize.x *= 1.0 + float(isStereo()); return imageSize; } vec2 taa_getTexelSize() { vec2 texelSize = getInvWidthHeight(); - texelSize.x *= mix(1.0, 0.5, float(isStereo())); + texelSize.x *= 1.0 - 0.5 * float(isStereo()); return texelSize; } @@ -216,14 +216,14 @@ vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) { float check2 = float(eyeUV.x > 0.5); eyeUV.x -= check * check2 * 0.5; stereoSide = int(check * check2); - eyeUV.x *= mix(1.0, 2.0, check); + eyeUV.x *= 1.0 + check; return eyeUV; } vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) { vec2 fragUV = eyeUV; 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; return fragUV; } diff --git a/libraries/render/src/render/drawItemBounds.slf b/libraries/render/src/render/drawItemBounds.slf index ab78f93064..0fed67beb6 100644 --- a/libraries/render/src/render/drawItemBounds.slf +++ b/libraries/render/src/render/drawItemBounds.slf @@ -19,6 +19,6 @@ void main(void) { float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5); 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)); }