From e03792c2d5620ca07ac50717062df846927027c0 Mon Sep 17 00:00:00 2001 From: Patrick Schönberger Date: Wed, 10 Feb 2021 11:52:27 +0100 Subject: render shadowmap and irradiance --- shaders/fbo_frag.glsl | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'shaders/fbo_frag.glsl') diff --git a/shaders/fbo_frag.glsl b/shaders/fbo_frag.glsl index f6f12cd..e199245 100644 --- a/shaders/fbo_frag.glsl +++ b/shaders/fbo_frag.glsl @@ -3,31 +3,35 @@ out vec4 FragColor; in vec2 TexCoords; -uniform sampler2D screenTexture; -uniform int applySSSSS; -uniform int N; +uniform sampler2D shadowmapTexture; +uniform sampler2D irradianceTexture; +uniform int screenWidth; +uniform int screenHeight; +uniform int renderState; +uniform vec2 samplePositions[13]; +uniform vec3 sampleWeights[13]; void main() { - if (applySSSSS == 1) { - float x = 1.0/1600.0; - float y = 1.0/900.0; - - float maxDist = N*N + N*N; - - vec4 color = vec4(0, 0, 0, 1); - for (int i = -N; i <= N; i++) { - for (int j = -N; j <= N; j++) { - float dist = i*i + j*j; - vec4 newC = texture(screenTexture, TexCoords + vec2(i*x, j*y)) / (2*N*N); - float factor = 1 - (dist / maxDist); - factor = pow(factor, 2); - color += newC * factor; - } - } - FragColor = color; + if (renderState == 0) { + FragColor = texture(shadowmapTexture, TexCoords); } - else { - FragColor = texture(screenTexture, TexCoords); + // stencil buffer + else if (renderState == 1 || texture(irradianceTexture, TexCoords).rgb == vec3(0, 0, 0)) { + FragColor = texture(irradianceTexture, TexCoords); + } + else if (renderState == 2) { + FragColor = texture(shadowmapTexture, TexCoords) * texture(irradianceTexture, TexCoords); + } + else if (renderState == 3) { + vec4 result = vec4(0, 0, 0, 1); + for (int i = 0; i < 13; i++) { + float oneX = 1.0/screenWidth; + float oneY = 1.0/screenHeight; + vec4 sample = texture(irradianceTexture, TexCoords + samplePositions[i] * vec2(oneX, oneY)); + vec4 weight = vec4(sampleWeights[i], 1); + result += sample * weight; + } + FragColor = result; } } -- cgit v1.2.3