Last active
June 27, 2022 07:15
-
-
Save CptPotato/27f11b7fe8c4222719a2cee7e7a0ccbb to your computer and use it in GitHub Desktop.
exposure based hsv color picker (shader toy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec3 exposure_offset(vec3 col, float e) { | |
const float RANGE = 4.0; // dynamic exposure range, exponential | |
const float EBLACK = pow(2.0, -RANGE); // min exposure offset | |
const float EWHITE = pow(2.0, RANGE); // max exposure offset | |
const float BLACK = EBLACK / (1.0 + EBLACK); // tonemapped remap values | |
const float WHITE = EWHITE / (1.0 + EWHITE); | |
const float BWNORM = 1.0 / (WHITE - BLACK); | |
e = pow(2.0, e * RANGE); // exposure | |
vec3 c = col / (1.0 - col); // de-tonemap | |
c *= e; // exposure offset | |
c = c / (1.0 + c); // re-tonemap | |
c = mix(c, (c - BLACK) * BWNORM, col * 2.0); // remap | |
return clamp(c, vec3(0.0), vec3(1.0)); | |
} | |
vec3 hsv2rgb(float hue, float sat, float val) | |
{ | |
vec3 rgb = clamp(abs(mod(hue * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0); | |
return val * mix(vec3(1.0), rgb, sat); | |
} | |
// exposure based hsv | |
vec3 ehsv2rgb(float hue, float sat, float val) { | |
vec3 base_col = hsv2rgb(hue, sat, 0.5); | |
return exposure_offset(base_col, val * 2.0 - 1.0); | |
} | |
float mouse_circle(vec2 px, vec2 c, float radius) { | |
return clamp(radius + 0.5 - distance(c, px), 0.0, 1.0); | |
} | |
float interleaved_gradient_noise(vec2 uv) { | |
const vec3 magic = vec3(0.06711056, 0.00583715, 52.9829189); | |
return fract(magic.z * fract(dot(uv, magic.xy))); | |
} | |
void mainImage(out vec4 fragColor, in vec2 fragCoord) | |
{ | |
vec2 uv = fragCoord / iResolution.xy; | |
vec2 muv = iMouse.xy / iResolution.xy; | |
float hue = iTime * 0.01; | |
vec3 col = ehsv2rgb(hue, uv.x, uv.y); | |
vec2 cpos = iMouse.z <= 0.0 ? vec2(50.0, iResolution.y * (0.5 + (muv.y < 0.5 ? 0.4 : -0.4))) : iMouse.xy; | |
float radius = iResolution.y / 25.0; | |
float c0 = mouse_circle(fragCoord, cpos, radius + 2.0); | |
float c1 = mouse_circle(fragCoord, cpos, radius); | |
vec3 mcol = ehsv2rgb(hue, muv.x, mix(0.6, muv.y, c1)); | |
col = mix(col, mcol, c0); | |
float noise = interleaved_gradient_noise(fragCoord); | |
col += (noise - 0.5) * (2.0 / 255.0); | |
fragColor = vec4(col, 1.0); | |
} |
Author
CptPotato
commented
Jun 27, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment