-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Camera movement + implemented deferred rendering and SSAO
- Loading branch information
Showing
14 changed files
with
532 additions
and
37 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
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,42 @@ | ||
#version 330 core | ||
|
||
#define PI 3.1415926535897932384626433832795 | ||
|
||
in vec2 frag_uv; | ||
|
||
out vec4 frag_color; | ||
|
||
uniform sampler2D albedo_tex; | ||
uniform sampler2D position_tex; | ||
uniform sampler2D normal_tex; | ||
uniform sampler2D ssao_tex; | ||
|
||
uniform vec3 sky_color; | ||
uniform float z_far; | ||
|
||
uniform mat4 view; | ||
|
||
const vec3 world_light_dir = normalize(vec3(-0.7, 1.5, 0.5)); | ||
|
||
void main() { | ||
vec3 albedo = texture(albedo_tex, frag_uv).rgb; | ||
vec3 position = texture(position_tex, frag_uv).xyz; | ||
vec3 normal = texture(normal_tex, frag_uv).xyz; | ||
float ambient_occlusion = texture(ssao_tex, frag_uv).r; | ||
|
||
vec3 lighting = albedo * ambient_occlusion * 0.3f; | ||
vec3 light_dir = normalize(mat3(view) * world_light_dir); | ||
|
||
vec3 diffuse = max(dot(normal, light_dir), 0.0f) * albedo * ambient_occlusion; | ||
lighting += diffuse; | ||
|
||
if (normal.x == 0.0f && normal.y == 0.0f && normal.z == 0.0f) { | ||
// Sky | ||
lighting = albedo; | ||
} | ||
|
||
// Fog | ||
float depth = min(1.0f, length(position) / z_far); | ||
float fog = depth * depth; | ||
frag_color = vec4(mix(lighting, sky_color, fog), 1.0); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#version 330 core | ||
|
||
in vec2 frag_uv; | ||
|
||
out float frag_color; | ||
|
||
const int NUM_SAMPLES = 64; | ||
|
||
uniform sampler2D position_tex; | ||
uniform sampler2D normal_tex; | ||
uniform sampler2D noise_tex; | ||
|
||
uniform mat4 projection; | ||
uniform vec2 noise_scale; | ||
uniform vec3 samples[NUM_SAMPLES]; | ||
|
||
const float radius = 0.5; | ||
const float bias = 0.025; | ||
const float magnitude = 1.1; | ||
const float constrast = 1.1; | ||
|
||
void main() { | ||
vec3 frag_pos = texture(position_tex, frag_uv).xyz; | ||
vec3 normal = normalize(texture(normal_tex, frag_uv).xyz); | ||
vec3 random_vec = normalize(texture(noise_tex, frag_uv * noise_scale).xyz); | ||
|
||
vec3 tangent = normalize(random_vec - normal * dot(random_vec, normal)); | ||
vec3 bitangent = cross(normal, tangent); | ||
mat3 tbn = mat3(tangent, bitangent, normal); | ||
|
||
float occlusion = 0.0; | ||
for (int i = 0; i < NUM_SAMPLES; ++i) { | ||
vec3 sample_pos = tbn * samples[i]; | ||
sample_pos = frag_pos + sample_pos * radius; | ||
|
||
vec4 offset = projection * vec4(sample_pos, 1.0); | ||
offset.xy /= offset.w; | ||
offset.xy = offset.xy * 0.5 + 0.5; | ||
|
||
float sample_depth = texture(position_tex, offset.xy).z; | ||
float range_check = smoothstep(0.0, 1.0, radius / abs(frag_pos.z - sample_depth)); | ||
occlusion += (sample_depth >= sample_pos.z + bias ? 1.0 : 0.0) * range_check; | ||
} | ||
|
||
occlusion = 1.0 - occlusion / NUM_SAMPLES; | ||
occlusion = pow(occlusion, magnitude); | ||
frag_color = constrast * (occlusion - 0.5) + 0.5; | ||
} |
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,19 @@ | ||
#version 330 core | ||
|
||
in vec2 frag_uv; | ||
|
||
out float frag_color; | ||
|
||
uniform sampler2D ssao_tex; | ||
|
||
void main() { | ||
vec2 texel_size = 1.0 / vec2(textureSize(ssao_tex, 0)); | ||
float result = 0.0; | ||
for (int x = -2; x < 2; ++x) { | ||
for (int y = -2; y < 2; ++y) { | ||
vec2 offset = vec2(float(x), float(y)) * texel_size; | ||
result += texture(ssao_tex, frag_uv + offset).r; | ||
} | ||
} | ||
frag_color = result / (4.0 * 4.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 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.