Last active
December 27, 2023 20:53
-
-
Save alaingalvan/296a2e5938d58c09829e38a1b14c8020 to your computer and use it in GitHub Desktop.
GPU Pro 3 sample of bent cones screen space ambient occlusion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() | |
{ | |
vec3 positionX = backproject(depthTexture(pixelCoordinateI), inverseViewProjectionMatrix); | |
vec3 normalX = normalTexture(pixelCoordinateI); | |
// get ONB to transform samples | |
mat3 orthoNormalBasis = computeONB(normalX); | |
// select samples for pixel out of pattern | |
int patternOffset = getPatternOffset(pixelCoordinateI); | |
float ao = 0.0; | |
int validAODirectionCount = 0; | |
vec3 bentNormal = vec3(0.0); | |
float unocclutedDirections = 0.0; | |
for (int index = 0; index < sampleCount; ++index) | |
{ | |
vec3 sampleDirection = orthoNormalBasis * getSampleDirection(index, patternOffset); | |
bool isOutlier = false; | |
// use float instead of bool and | |
// apply a fall off function to get smooth AO | |
float visibility = 1.0; | |
// this function tests for occlusion in SS | |
// depending on the actual technique | |
// and sample distribution | |
// the implementation of this function varies | |
checkSSVisibilityWithRayMarchingSmooth( | |
sampleDirection, maxOccluderDistance, | |
depthTexture, inverseViewProjectionMatrix, | |
positionX, normalX, | |
rayMarchingSteps, rayMarchingStartOffset | |
visibility, isOutlier); | |
// we have insufficient information in SS | |
// here we simply ignore samples | |
// which can't be handled properly | |
if (!isOutlier) | |
{ | |
validAODirectionCount++; | |
ao += visibility; | |
} | |
// for bent normals, we assume, | |
// that outlier occluders are NOT real occluders! | |
// sum up unoccluded directions | |
// direction may be partially visibile | |
// => only counts accordingly | |
bentNormal += normalize(sampleDirection) * visibility; | |
unoccludedDirections += visibility; | |
} | |
ao /= float(validAODirectionCount); | |
bentNormal /= unoccludedDirections; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment