X-Git-Url: https://gitweb.ps.run/subsurface_scattering/blobdiff_plain/451e872ddbe6db8bd8d6aa54ca0bf744dc5405e5..cedffd5cf24c1a3ed64161475c806c55135406be:/shaders/fbo_frag.glsl diff --git a/shaders/fbo_frag.glsl b/shaders/fbo_frag.glsl index f6f12cd..7463fc8 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) { + 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++) { + vec2 sampleCoords = TexCoords + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight); + vec4 sample = texture(irradianceTexture, sampleCoords) + * texture(shadowmapTexture, sampleCoords); + vec4 weight = vec4(sampleWeights[i], 1); + result += sample * weight; + } + FragColor = result; } }