From b90e0cfd898dc1315b8c76c15acd82a251975a3c Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 12 Aug 2016 19:18:05 -0700 Subject: [PATCH] Fixing the stereo issue --- libraries/render-utils/src/ssao.slh | 24 +++++++------ .../render-utils/src/ssao_debugOcclusion.slf | 36 ++++++------------- .../render-utils/src/ssao_makeOcclusion.slf | 19 +++++++--- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/libraries/render-utils/src/ssao.slh b/libraries/render-utils/src/ssao.slh index fe4b77577f..c9b27bc2c8 100644 --- a/libraries/render-utils/src/ssao.slh +++ b/libraries/render-utils/src/ssao.slh @@ -218,7 +218,7 @@ vec3 getTapLocationClamped(int sampleNumber, float spinAngle, float outerRadius, tap.xy = tapPos - pixelPos; tap.z = length(tap.xy); tap.z = 0; - } + } return tap; } @@ -244,20 +244,23 @@ int evalMipFromRadius(float radius) { } -vec3 fetchTapUnfiltered(ivec3 side, ivec2 ssC, vec3 tap, vec2 imageSize) { +vec3 fetchTapUnfiltered(ivec4 side, ivec2 ssC, vec3 tap, vec2 imageSize) { ivec2 ssP = ivec2(tap.xy) + ssC; ivec2 ssPFull = ivec2(ssP.x + side.y, ssP.y); + vec2 tapUV = (vec2(ssP) + vec2(0.5)) / imageSize; + vec2 fetchUV = vec2(tapUV.x + side.w * 0.5 * (side.x - tapUV.x), tapUV.y); + vec3 P; - P.xy = tapUV; - P.z = -texture(pyramidMap, tapUV).x; + P.xy = tapUV; + P.z = -texture(pyramidMap, fetchUV).x; return P; } -vec3 fetchTap(ivec3 side, ivec2 ssC, vec3 tap, vec2 imageSize) { +vec3 fetchTap(ivec4 side, ivec2 ssC, vec3 tap, vec2 imageSize) { int mipLevel = evalMipFromRadius(tap.z * doFetchMips()); ivec2 ssP = ivec2(tap.xy) + ssC; @@ -270,13 +273,14 @@ vec3 fetchTap(ivec3 side, ivec2 ssC, vec3 tap, vec2 imageSize) { ivec2 mipP = clamp(ssPFull >> mipLevel, ivec2(0), mipSize - ivec2(1)); - // vec2 tapUV = (vec2(ssP) + vec2(0.5)) / imageSize; - vec2 tapUV = (vec2(mipP) + vec2(0.5)) / vec2(mipSize); + vec2 tapUV = (vec2(ssP) + vec2(0.5)) / imageSize; + vec2 fetchUV = vec2(tapUV.x + side.w * 0.5 * (side.x - tapUV.x), tapUV.y); + // vec2 tapUV = (vec2(mipP) + vec2(0.5)) / vec2(mipSize); vec3 P; - P.xy = tapUV; - P.z = -texelFetch(pyramidMap, mipP, mipLevel).x; - // P.z = -textureLod(pyramidMap, tapUV, float(mipLevel)).x; + P.xy = tapUV; + // P.z = -texelFetch(pyramidMap, mipP, mipLevel).x; + P.z = -textureLod(pyramidMap, fetchUV, float(mipLevel)).x; return P; } diff --git a/libraries/render-utils/src/ssao_debugOcclusion.slf b/libraries/render-utils/src/ssao_debugOcclusion.slf index 077b7e68b9..50c66c62e3 100644 --- a/libraries/render-utils/src/ssao_debugOcclusion.slf +++ b/libraries/render-utils/src/ssao_debugOcclusion.slf @@ -36,13 +36,13 @@ out vec4 outFragColor; void main(void) { vec2 imageSize = getSideImageSize(getResolutionLevel()); - - // In debug adjust the correct frag pixel based on base resolution - vec2 fragCoord = gl_FragCoord.xy; - if (getResolutionLevel() > 0) { - fragCoord /= float (1 << getResolutionLevel()); - } - + + // In debug adjust the correct frag pixel based on base resolution + vec2 fragCoord = gl_FragCoord.xy; + if (getResolutionLevel() > 0) { + fragCoord /= float (1 << getResolutionLevel()); + } + // Pixel Debugged vec2 cursorUV = getDebugCursorTexcoord(); vec2 cursorPixelPos = cursorUV * imageSize; @@ -73,7 +73,7 @@ void main(void) { // Let's make noise //float randomPatternRotationAngle = getAngleDithering(ssC); - vec3 wCp = (getViewInverse() * vec4(Cp, 1.0)).xyz; + vec3 wCp = (getViewInverse() * vec4(Cp, 1.0)).xyz; float randomPatternRotationAngle = getAngleDitheringWorldPos(wCp); @@ -93,9 +93,9 @@ void main(void) { keepedMip = evalMipFromRadius(tap.z * doFetchMips()); } - vec3 tapUVZ = fetchTap(side.xyz, ssC, tap, imageSize); - - vec3 Q = evalEyePositionFromZeye(side.x, tapUVZ.z, tapUVZ.xy); + vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize); + + vec3 Q = evalEyePositionFromZeye(side.x, tapUVZ.z, tapUVZ.xy); sum += float(tap.z > 0.0) * evalAO(Cp, Cn, Q); } @@ -116,20 +116,6 @@ void main(void) { outFragColor = vec4(packOcclusionDepth(A, CSZToDephtKey(Cp.z)), 1.0); - // KEEP IT for Debugging - // Debug Normal: outFragColor = vec4((Cn + vec3(1.0))* 0.5, 1.0); - // Debug Radius outFragColor = vec4(vec3(ssDiskRadius / 100.0), 1.0); - // Debug MaxMiplevel outFragColor = vec4(1.0 - vec3(float(clamp(findMSB(int(ssDiskRadius)) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL))/ float(MAX_MIP_LEVEL)), 1.0); - // Debug OffsetPosition - // float ssR; - // vec2 unitOffset = tapLocation(int(getNumSamples() - 1), 0, ssR); - // vec3 Q = getOffsetPosition(side, ssC, unitOffset, ssR * ssDiskRadius); - //outFragColor = vec4(vec3(Q.x / 10.0, Q.y / 2.0, -Q.z/ 3.0), 1.0); - // vec3 v = normalize(Q - Cp); - //outFragColor = vec4((v + vec3(1.0))* 0.5, 1.0); - // outFragColor = vec4((Cn + vec3(1.0))* 0.5, 1.0); - //outFragColor = vec4(vec3(ssDiskRadius / 100.0), 1.0); - if ((dot(fragToCursor,fragToCursor) < (100.0 * keepTapRadius * keepTapRadius) )) { // outFragColor = vec4(vec3(A), 1.0); outFragColor = vec4(vec3(A), 1.0); diff --git a/libraries/render-utils/src/ssao_makeOcclusion.slf b/libraries/render-utils/src/ssao_makeOcclusion.slf index 4e90160d23..91d94294af 100644 --- a/libraries/render-utils/src/ssao_makeOcclusion.slf +++ b/libraries/render-utils/src/ssao_makeOcclusion.slf @@ -23,7 +23,7 @@ void main(void) { vec2 imageSize = getSideImageSize(getResolutionLevel()); // Pixel being shaded - vec2 fragCoord = gl_FragCoord.xy; + vec2 fragCoord = gl_FragCoord.xy; ivec2 ssC = ivec2(fragCoord.xy); // Fetch the z under the pixel (stereo or not) @@ -44,8 +44,8 @@ void main(void) { float ssDiskRadius = evalDiskRadius(Cp.z, imageSize); // Let's make noise - // float randomPatternRotationAngle = getAngleDithering(ssC); - vec3 wCp = (getViewInverse() * vec4(Cp, 1.0)).xyz; + //float randomPatternRotationAngle = getAngleDithering(ssC); + vec3 wCp = (getViewInverse() * vec4(Cp, 1.0)).xyz; float randomPatternRotationAngle = getAngleDitheringWorldPos(wCp); // Accumulate the Obscurance for each samples @@ -53,9 +53,9 @@ void main(void) { for (int i = 0; i < getNumSamples(); ++i) { vec3 tap = getTapLocationClamped(i, randomPatternRotationAngle, ssDiskRadius, ssC, imageSize); - vec3 tapUVZ = fetchTap(side.xyz, ssC, tap, imageSize); + vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize); - vec3 Q = evalEyePositionFromZeye(side.x, tapUVZ.z, tapUVZ.xy); + vec3 Q = evalEyePositionFromZeye(side.x, tapUVZ.z, tapUVZ.xy); sum += float(tap.z > 0.0) * evalAO(Cp, Cn, Q); } @@ -74,4 +74,13 @@ void main(void) { !> outFragColor = vec4(packOcclusionDepth(A, CSZToDephtKey(Cp.z)), 1.0); + + /* { + vec3 tap = getTapLocationClamped(2, randomPatternRotationAngle, ssDiskRadius, ssC, imageSize); + vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize); + vec2 fetchUV = vec2(tapUVZ.x + side.w * 0.5 * (side.x - tapUVZ.x), tapUVZ.y); + vec3 Q = evalEyePositionFromZeye(side.x, tapUVZ.z, tapUVZ.xy); + outFragColor = vec4(fetchUV, 0.0, 1.0); + }*/ + }