0.00
60.0 fps

ACES vs exp Tonemapping

ACES (left) vs exp Tonemapping (right)

Log in to post a comment.

#version 300 es
precision highp float;

uniform float iTime;
uniform vec2  iResolution;

uniform float _Red;    //value=.04, min=0, max=1, step=0.01
uniform float _Green;    //value=.11, min=0, max=1, step=0.01
uniform float _Blue;    //value=.09, min=0, max=1, step=0.01
uniform float _Power;    //value=1, min=1, max=3, step=0.01
uniform float _SCurve;   //value=0.78, min=0, max=1, step=0.01
out vec4 fragColor;


// Based on http://www.oscars.org/science-technology/sci-tech-projects/aces
vec3 aces_tonemap(vec3 color){	
	mat3 m1 = mat3(
        0.59719, 0.07600, 0.02840,
        0.35458, 0.90834, 0.13383,
        0.04823, 0.01566, 0.83777
	);
	mat3 m2 = mat3(
        1.60475, -0.10208, -0.00327,
        -0.53108,  1.10813, -0.07276,
        -0.07367, -0.00605,  1.07602
	);
	vec3 v = m1 * color;    
	vec3 a = v * (v + 0.0245786) - 0.000090537;
	vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;
	return clamp(m2 * (a / b), 0.0, 1.0);	
}

vec3 expToneMap(vec3 c){
    float s = exp(-dot(c, vec3(_Red, _Green, _Blue)));
	c = vec3(1.) - exp(-c);
    c = pow(c, vec3(_Power));
	c = mix(c, smoothstep(0., 1., c), _SCurve);
	return mix(mix(vec3(1.),c, s), c, s);

}

void main()
{
	vec2 position = (gl_FragCoord.xy/iResolution.xy)* 2.0 - 1.0;
    vec2 p = position;
    p.x += iTime * 0.2;

	vec3 color = pow(sin(p.x * 4.0 + vec3(0.0, 1.0, 2.0) * 3.1415 * 2.0 / 3.0) * 0.5 + 0.5, vec3(2.0)) * (exp(abs(p.y) * 4.0) - 1.0);

	if(position.y < 0.0){
        if(position.x < 0.){
		    color = aces_tonemap(color);  
        }else{
            color = expToneMap (color);
        }
	}
	color = pow(color, vec3(1. / 2.2));

	fragColor = vec4(color,1.0);
}