-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
394 additions
and
67 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#version 330 core | ||
|
||
in float FragDepth; | ||
in float VertexDepth; | ||
|
||
out float FragValue; | ||
|
||
void main() { | ||
FragValue = FragDepth; | ||
FragValue = VertexDepth; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#version 330 core | ||
|
||
in vec3 Normal; | ||
|
||
out vec3 NormalOut; | ||
|
||
void main() { | ||
NormalOut = normalize(Normal); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#version 330 core | ||
in vec2 TexCoords; | ||
|
||
uniform sampler2D depthTexture; // View-space depth texture | ||
uniform sampler2D normalTexture; // View-space normal texture | ||
|
||
uniform mat4 projection; | ||
uniform vec3 samples[128]; // SSAO Kernel | ||
|
||
out float SSAO; | ||
|
||
void main() { | ||
vec3 fragViewPos = texture(depthTexture, TexCoords).xyz; // View-space position | ||
float fragViewDepth = -fragViewPos.z; | ||
vec3 normal = normalize(texture(normalTexture, TexCoords).xyz); | ||
|
||
float occlusion = 0.0; | ||
float radius = 0.5; // Sample radius | ||
float bias = 0.01; | ||
|
||
for (int i = 0; i < 128; ++i) { | ||
vec3 randomVec = vec3(samples[i].y, samples[i].z, samples[i].x); | ||
vec3 tangent = normalize(normalize(randomVec) - normal * dot(randomVec, normal)); | ||
vec3 bitangent = cross(normal, tangent); | ||
mat3 TBN = mat3(tangent, bitangent, normal); // Create tangent-space matrix | ||
|
||
vec3 samplePos = TBN * samples[i]; // Transform to view space | ||
samplePos = fragViewPos + samplePos * radius; // Move sample position | ||
|
||
vec4 offset = vec4(samplePos, 1.0); | ||
offset = projection * offset; | ||
offset.xyz /= offset.w; | ||
offset.xyz = offset.xyz * 0.5 + 0.5; | ||
|
||
float offsetDepth = -samplePos.z; | ||
float newlySampledDepth = -texture(depthTexture, offset.xy).z; | ||
|
||
if(newlySampledDepth + bias < offsetDepth) | ||
{ | ||
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(newlySampledDepth - fragViewDepth)); | ||
occlusion += rangeCheck; | ||
} | ||
} | ||
|
||
occlusion = 1.0 - (occlusion / 128.0); // Normalize occlusion value | ||
SSAO = 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 330 core | ||
in vec3 Normal; | ||
|
||
out vec3 OutNormal; | ||
|
||
void main() { | ||
OutNormal = normalize(Normal); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 330 core | ||
in vec3 FragPos; | ||
|
||
out vec3 OutFragPos; | ||
|
||
void main() { | ||
OutFragPos = FragPos; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 330 core | ||
|
||
layout(location = 0) in vec3 aPos; // Vertex position | ||
|
||
uniform mat4 projectionViewMatrix; // Model matrix | ||
uniform mat4 modelMatrix; // Projection matrix | ||
|
||
out float VertexDepth; // Output the depth value to the fragment shader | ||
|
||
void main() { | ||
vec4 viewSpacePosition = projectionViewMatrix * modelMatrix * vec4(aPos, 1.0); | ||
gl_Position = viewSpacePosition; | ||
VertexDepth = viewSpacePosition.z; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#version 330 core | ||
|
||
layout(location = 1) in vec3 normal; // Vertex normal | ||
|
||
uniform mat4 modelMatrix; // Model matrix | ||
uniform mat4 projectionViewMatrix; // View matrix | ||
|
||
out vec3 Normal; // Normal in world space | ||
|
||
void main() { | ||
vec3 fragPos = vec3(modelMatrix * vec4(position, 1.0)); | ||
Normal = normalize(mat3(transpose(inverse(modelMatrix))) * normal); | ||
|
||
gl_Position = projectionViewMatrix * vec4(fragPos, 1.0); | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#version 330 core | ||
layout(location = 0) in vec3 aPos; | ||
layout(location = 1) in vec3 aNormal; | ||
|
||
uniform mat4 model; | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
out vec3 Normal; // View-space normal | ||
|
||
void main() { | ||
vec4 worldPos = model * vec4(aPos, 1.0); | ||
vec4 viewPos = view * worldPos; | ||
Normal = mat3(transpose(inverse(view))) * aNormal; // Transform normal to view space | ||
gl_Position = projection * viewPos; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#version 330 core | ||
layout(location = 0) in vec3 aPos; | ||
layout(location = 1) in vec3 aNormal; | ||
|
||
uniform mat4 model; | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
out vec3 FragPos; | ||
|
||
void main() { | ||
vec4 worldPos = model * vec4(aPos, 1.0); | ||
vec4 viewPos = view * worldPos; | ||
|
||
FragPos = viewPos.xyz; | ||
gl_Position = projection * viewPos; | ||
} |
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
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
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
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
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
Oops, something went wrong.