X-Git-Url: https://gitweb.ps.run/subsurface_scattering/blobdiff_plain/451e872ddbe6db8bd8d6aa54ca0bf744dc5405e5..refs/heads/main:/shaders/fbo_frag.glsl diff --git a/shaders/fbo_frag.glsl b/shaders/fbo_frag.glsl index f6f12cd..8ffc0ce 100644 --- a/shaders/fbo_frag.glsl +++ b/shaders/fbo_frag.glsl @@ -3,31 +3,26 @@ 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; - } - else { - FragColor = texture(screenTexture, TexCoords); + // sample calculated irradiance + // using Gaussian kernel to approximate light spread + vec4 result = vec4(0, 0, 0, 1); + for (int i = 0; i < 13; i++) { + vec2 sampleCoords = TexCoords + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight); + //vec4 sample = texture(irradianceTexture, sampleCoords) + // * texture(shadowmapTexture, sampleCoords); + vec4 sample = texture(irradianceTexture, sampleCoords); + vec4 weight = vec4(sampleWeights[i], 1); + result += sample * weight; } + FragColor = result; }