<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // // Created by Sam Gateau on 1/1/16. // Copyright 2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // <@include ssao.slh@> <$declareAmbientOcclusion()$> <$declareFetchDepthPyramidMap()$> <$declareSamplingDisk()$> <$declareEvalObscurance()$> <$declarePackOcclusionDepth()$> <@include gpu/Color.slh@> <$declareColorWheel()$> struct DebugParams{ vec4 pixelInfo; }; uniform debugAmbientOcclusionBuffer { DebugParams debugParams; }; vec2 getDebugCursorTexcoord(){ return debugParams.pixelInfo.xy; } 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()); } // Pixel Debugged vec2 cursorUV = getDebugCursorTexcoord(); vec2 cursorPixelPos = cursorUV * imageSize; ivec2 ssC = ivec2(cursorPixelPos); // Fetch the z under the pixel (stereo or not) float Zeye = getZEye(ssC, 0); // Stereo side info ivec4 side = getStereoSideInfo(ssC.x, getResolutionLevel()); // From now on, ssC is the pixel pos in the side ssC.x -= side.y; vec2 fragPos = (vec2(ssC) + vec2(0.5)) / imageSize; // The position and normal of the pixel fragment in Eye space vec3 Cp = evalEyePositionFromZeye(side.x, Zeye, fragPos); vec3 Cn = evalEyeNormal(Cp); // Choose the screen-space sample radius float ssDiskRadius = evalDiskRadius(Cp.z, imageSize); vec2 fragToCursor = cursorPixelPos - fragCoord.xy; if (dot(fragToCursor,fragToCursor) > ssDiskRadius * ssDiskRadius) { discard; } // Let's make noise //float randomPatternRotationAngle = getAngleDithering(ssC); vec3 wCp = (getViewInverse() * vec4(Cp, 1.0)).xyz; float randomPatternRotationAngle = getAngleDitheringWorldPos(wCp); // Accumulate the Obscurance for each samples float sum = 0.0; float keepTapRadius = 1.0; int keepedMip = -1; bool keep = false; for (int i = 0; i < getNumSamples(); ++i) { vec3 tap = getTapLocationClamped(i, randomPatternRotationAngle, ssDiskRadius, cursorPixelPos, imageSize); // The occluding point in camera space vec2 fragToTap = vec2(ssC) + tap.xy - fragCoord.xy; if (dot(fragToTap,fragToTap) < keepTapRadius) { keep = true; keepedMip = evalMipFromRadius(tap.z * doFetchMips()); } 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); } float A = max(0.0, 1.0 - sum * getObscuranceScaling() * 5.0 * getInvNumSamples()); outFragColor = vec4(packOcclusionDepth(A, CSZToDephtKey(Cp.z)), 1.0); if ((dot(fragToCursor,fragToCursor) < (100.0 * keepTapRadius * keepTapRadius) )) { // outFragColor = vec4(vec3(A), 1.0); outFragColor = vec4(vec3(A), 1.0); return; } if (!keep) { outFragColor = vec4(0.1); } else { outFragColor.rgb = colorWheel(float(keepedMip)/float(MAX_MIP_LEVEL)); } }