#ifdef STEP_RAYTRACE uniform sampler2D depthBuffer; uniform sampler2D normalBuffer; uniform sampler2D specroughBuffer; layout(location = 0) out vec4 hitData; layout(location = 1) out vec4 pdfData; void main() { ivec2 fullres_texel = ivec2(gl_FragCoord.xy) * 2; float depth = texelFetch(depthBuffer, fullres_texel, 0).r; /* Early discard */ if (depth == 1.0) discard; hitData = vec4(0.2); pdfData = vec4(0.5); } #else /* STEP_RESOLVE */ uniform sampler2D depthBuffer; uniform sampler2D normalBuffer; uniform sampler2D specroughBuffer; uniform sampler2D hitBuffer; uniform sampler2D pdfBuffer; uniform int probe_count; out vec4 fragColor; void fallback_cubemap(vec3 N, vec3 V, vec3 W, float roughness, float roughnessSquared, inout vec4 spec_accum) { /* Specular probes */ vec3 spec_dir = get_specular_dominant_dir(N, V, roughnessSquared); /* Starts at 1 because 0 is world probe */ for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) { CubeData cd = probes_data[i]; float fade = probe_attenuation_cube(cd, W); if (fade > 0.0) { vec3 spec = probe_evaluate_cube(float(i), cd, W, spec_dir, roughness); accumulate_light(spec, fade, spec_accum); } } /* World Specular */ if (spec_accum.a < 0.999) { vec3 spec = probe_evaluate_world_spec(spec_dir, roughness); accumulate_light(spec, 1.0, spec_accum); } } void main() { ivec2 halfres_texel = ivec2(gl_FragCoord.xy / 2.0); ivec2 fullres_texel = ivec2(gl_FragCoord.xy); vec2 uvs = gl_FragCoord.xy / vec2(textureSize(depthBuffer, 0)); float depth = textureLod(depthBuffer, uvs, 0.0).r; /* Early discard */ if (depth == 1.0) discard; vec3 worldPosition = get_world_space_from_depth(uvs, depth); vec3 V = cameraVec; vec3 N = mat3(ViewMatrixInverse) * normal_decode(texelFetch(normalBuffer, fullres_texel, 0).rg, V); vec4 speccol_roughness = texelFetch(specroughBuffer, fullres_texel, 0).rgba; float roughness = speccol_roughness.a; float roughnessSquared = roughness * roughness; vec4 spec_accum = vec4(0.0); /* Resolve SSR and compute contribution */ /* If SSR contribution is not 1.0, blend with cubemaps */ if (spec_accum.a < 1.0) { fallback_cubemap(N, V, worldPosition, roughness, roughnessSquared, spec_accum); } fragColor = vec4(spec_accum.rgb * speccol_roughness.rgb, 1.0); } #endif