Skip to content

Commit

Permalink
Added primitive SSAO.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundo-villa committed Nov 24, 2023
1 parent 78cac7a commit dd43dc0
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 1,229 deletions.
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
Expand Down
24 changes: 20 additions & 4 deletions assets/engine/shaders/ssao.comp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ vec3 min_diff(vec3 p, vec3 a, vec3 b) {
return (length_squared(ap) < length_squared(bp)) ? ap : bp;
}

float blue_noise_hash(vec2 p ) {
return fract(sin(dot(p, vec2(11.9898, 78.233))) * 43758.5453);
}

float blue_noise(vec2 U) {
float v = hash(U + vec2(-1, 0))
+ hash(U + vec2(1, 0))
+ hash(U + vec2(0, 1))
+ hash(U + vec2(0, -1));
return hash(U) - v/4. + .5;
}

layout(local_size_x=32, local_size_y=32) in;
void main() {
if (gl_GlobalInvocationID.x >= imageSize(result).x || gl_GlobalInvocationID.y >= imageSize(result).y) { return; }
Expand All @@ -136,7 +148,7 @@ void main() {

mat3 tbn = mat3(t, b, n);

float32_t oclussion = 0;
float32_t occlusion = 0;

for (uint32_t i = 0; i < SAMPLE_COUNT; ++i) {
vec3 s = tbn * normalize(HEMISPHERE_POSITIONS[i]); // sample in view space
Expand All @@ -145,10 +157,14 @@ void main() {
vec3 sampled_position = get_view_position(get_uv_from_view_position(s));

float32_t tweak = smoothstep(0.0, 1.0, R / abs(p.z - sampled_position.z));
oclussion += (sampled_position.z <= s.z ? 1.0 : 0.0) * tweak;
occlusion += (sampled_position.z <= s.z ? 1.0 : 0.0) * tweak;
}

oclussion = 1.0 - (oclussion / float(SAMPLE_COUNT));
// oclussion *= 2.0f;

occlusion = 1.0 - (occlusion / float(SAMPLE_COUNT));

occlusion = pow(occlusion, 4.0);

imageStore(result, ivec2(gl_GlobalInvocationID.xy), vec4(vec3(oclussion), 1.0));
imageStore(result, ivec2(gl_GlobalInvocationID.xy), vec4(vec3(occlusion), 1.0));
}
Loading

0 comments on commit dd43dc0

Please sign in to comment.