Skip to main content

EXTRACT_FRAG

Constant EXTRACT_FRAG 

Source
pub const EXTRACT_FRAG: &str = r#"
#version 330 core

in  vec2 v_uv;
out vec4 frag_color;

uniform sampler2D u_scene;
uniform sampler2D u_emission;
uniform float     u_threshold;
uniform float     u_knee;
uniform float     u_emission_weight;

const vec3 LUMA = vec3(0.2126, 0.7152, 0.0722);

float soft_threshold(float lum) {
    float lo = u_threshold - u_knee;
    float hi = u_threshold + u_knee;
    if (lum <= lo) return 0.0;
    if (lum >= hi) return 1.0;
    float t = (lum - lo) / (2.0 * u_knee + 0.0001);
    return t * t * (3.0 - 2.0 * t);
}

void main() {
    vec3 scene = texture(u_scene, v_uv).rgb;
    vec3 emiss = texture(u_emission, v_uv).rgb * u_emission_weight;
    vec3 combined = scene + emiss;

    float lum    = dot(combined, LUMA);
    float weight = soft_threshold(lum);

    frag_color = vec4(combined * weight, 1.0);
}
"#;
Expand description

GLSL fragment shader source for the bright-extract pass. Expects: u_scene: sampler2D — full scene color u_emission: sampler2D — emission texture (optional) u_threshold: float u_knee: float u_emission_weight: float