feature: more proper color correction

This commit is contained in:
FMS-Cat
2021-03-30 23:19:06 +09:00
parent d9d5eddc8b
commit 31b0354f4a

View File

@@ -7,6 +7,7 @@ const float BARREL_OFFSET = 0.05;
const float BARREL_AMP = 0.05; const float BARREL_AMP = 0.05;
const float HUGE = 9E16; const float HUGE = 9E16;
const float PI = 3.14159265; const float PI = 3.14159265;
const vec3 LUMA = vec3( 0.2126, 0.7152, 0.0722 );
#define saturate(i) clamp(i,0.,1.) #define saturate(i) clamp(i,0.,1.)
#define linearstep(a,b,x) saturate(((x)-(a))/((b)-(a))) #define linearstep(a,b,x) saturate(((x)-(a))/((b)-(a)))
@@ -42,6 +43,46 @@ vec3 barrel( float amp, vec2 uv ) {
return texture( sampler0, vec2( p.x, p.y ) ).xyz; return texture( sampler0, vec2( p.x, p.y ) ).xyz;
} }
vec3 aces( vec3 rgb ) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return saturate( ( rgb * ( a * rgb + b ) ) / ( rgb * ( c * rgb + d ) + e ) );
}
vec3 liftGammaGain( vec3 rgb ) {
const vec4 lift = vec4( -0.07, 0.02, 0.03, 0.01 );
const vec4 gamma = vec4( 0.0, -0.02, 0.07, 0.02 );
const vec4 gain = vec4( 1.20, 0.95, 0.92, 1.0 );
// const vec4 lift = vec4( 0.02, -0.01, 0.09, 0.0 );
// const vec4 gamma = vec4( -0.05, 0.02, -0.08, 0.0 );
// const vec4 gain = vec4( 1.06, 0.96, 1.10, 1.0 );
vec4 liftt = 1.0 - pow( 1.0 - lift, log2( gain + 1.0 ) );
vec4 gammat = gamma.rgba - vec4( 0.0, 0.0, 0.0, dot( LUMA, gamma.rgb ) );
vec4 gammatTemp = 1.0 + 4.0 * abs( gammat );
gammat = mix( gammatTemp, 1.0 / gammatTemp, step( 0.0, gammat ) );
vec3 col = rgb;
float luma = dot( LUMA, col );
col = pow( col, gammat.rgb );
col *= pow( gain.rgb, gammat.rgb );
col = max( mix( 2.0 * liftt.rgb, vec3( 1.0 ), col ), 0.0 );
luma = pow( luma, gammat.a );
luma *= pow( gain.a, gammat.a );
luma = max( mix( 2.0 * liftt.a, 1.0, luma ), 0.0 );
col += luma - dot( LUMA, col );
return saturate( col );
}
void main() { void main() {
vec2 uv = vUv; vec2 uv = vUv;
vec2 p = ( uv * resolution * 2.0 - resolution ) / resolution.y; vec2 p = ( uv * resolution * 2.0 - resolution ) / resolution.y;
@@ -66,10 +107,9 @@ void main() {
prng( seed ); prng( seed );
prng( seed ); prng( seed );
col += ( pow( prng( seed ), 2.2 ) - 0.25 ) * 0.002; col += ( pow( prng( seed ), 2.2 ) - 0.25 ) * 0.002;
col = aces( saturate( col ) );
col = pow( saturate( col ), vec3( 0.4545 ) ); col = pow( saturate( col ), vec3( 0.4545 ) );
col.x = linearstep( 0.0, 1.2, col.x + 0.2 * uv.y ); col = liftGammaGain( col );
col.z = linearstep( -0.1, 1.0, col.z );
col = colorMap( col );
fragColor = vec4( col, 1.0 ); fragColor = vec4( col, 1.0 );
} }