render: SSAO

This commit is contained in:
2022-02-05 19:25:44 +08:00
parent 05a85ac27f
commit 92b0ace7a2
9 changed files with 289 additions and 26 deletions

View File

@@ -6,6 +6,8 @@ uniform vec3 viewPos;
uniform vec3 sun;
uniform vec4 fogColor;
uniform sampler2D ssaoAmbient; // Ambient strength from SSAO pass
// G-Buffers
uniform sampler2D gPos;
uniform sampler2D gNorm;
@@ -40,12 +42,12 @@ void loadGBuffer() {
fragNormal = fragGNormal.xyz;
if (fragNormal == vec3(0.0f, 0.0f, 0.0f))
discard;
fragPosLightspaceZ = fragGNormal.w;
gl_FragDepth = fragGNormal.w * 0.5 + 0.5;
vec4 fragGPos = texture(gPos, fragPosScreen);
fragPos = vec4(fragGPos.xyz + viewPos, 1.0f);
fragPosLightspaceZ = fragGPos.w;
fragColor = texture(gColor, fragPosScreen);
fragPosLightspace = lightspace * fragPos;
@@ -56,7 +58,7 @@ void main() {
loadGBuffer();
light = ambient;
light = ambient * texture(ssaoAmbient, fragPosScreen).r;
lightSun();