Skip to content

Commit

Permalink
Fixed SSAO
Browse files Browse the repository at this point in the history
  • Loading branch information
St0wy committed Jul 20, 2023
1 parent 83b3395 commit 43c5736
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions shaders/ssao/ssao.frag
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main()
vec3 normal = texture(gNormalRoughness, TexCoords).rgb;

vec2 noiseScale = screenSize / RANDOM_TEXTURE_SIZE;
vec3 randomVec = texture(texNoise, TexCoords * noiseScale).xyz;
vec3 randomVec = normalize(texture(texNoise, TexCoords * noiseScale).xyz);

vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
vec3 bitangent = cross(normal, tangent);
Expand All @@ -39,7 +39,7 @@ void main()
{
// From tangent space to view space
vec3 samplePos = TBN * samples[i];
samplePos = fragPos.xyz + samplePos * RADIUS;
samplePos = fragPos + samplePos * RADIUS;

vec4 offset = vec4(samplePos, 1.0);
// from view to clip-space
Expand All @@ -49,7 +49,8 @@ void main()
// transform to range 0.0 - 1.0
offset.xyz = offset.xyz * 0.5 + 0.5;

float sampleDepth = texture(gPositionAmbientOcclusion, TexCoords).z;
float sampleDepth = texture(gPositionAmbientOcclusion, offset.xy).z;

float rangeCheck = smoothstep(0.0, 1.0, RADIUS / abs(fragPos.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + BIAS ? 1.0 : 0.0) * rangeCheck;
}
Expand Down

0 comments on commit 43c5736

Please sign in to comment.