Skip to content

Instantly share code, notes, and snippets.

@behreajj
Last active May 22, 2021 12:29
Show Gist options
  • Save behreajj/dc185ec497bde0cf19a53cb95d4e5c73 to your computer and use it in GitHub Desktop.
Save behreajj/dc185ec497bde0cf19a53cb95d4e5c73 to your computer and use it in GitHub Desktop.
Linear Standard RGB Conversions
color sRgbTolRgb(color standard) {
float sr = standard[0];
float sg = standard[1];
float sb = standard[2];
return color(
select(pow((sr + 0.055) / 1.055, 2.4), sr / 12.92, sr <= 0.04045),
select(pow((sg + 0.055) / 1.055, 2.4), sg / 12.92, sg <= 0.04045),
select(pow((sb + 0.055) / 1.055, 2.4), sb / 12.92, sb <= 0.04045));
}
color lRgbTosRgb(color linear) {
float lr = linear[0];
float lg = linear[1];
float lb = linear[2];
return color(
select(pow(lr, 1.0 / 2.4) * 1.055 - 0.055, lr * 12.92, lr <= 0.0031308),
select(pow(lg, 1.0 / 2.4) * 1.055 - 0.055, lg * 12.92, lg <= 0.0031308),
select(pow(lb, 1.0 / 2.4) * 1.055 - 0.055, lb * 12.92, lb <= 0.0031308));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment