Skip to content

Instantly share code, notes, and snippets.

@HungryProton
Created September 16, 2020 10:55
Show Gist options
  • Save HungryProton/ad7c5cb1c663c24429b02c7966efcec0 to your computer and use it in GitHub Desktop.
Save HungryProton/ad7c5cb1c663c24429b02c7966efcec0 to your computer and use it in GitHub Desktop.
convert from rgb to srgb and the other way around in godot shaders
float lts(float L) {
if (abs(L) < 0.0031308) {
return 12.92 * L;
}
return 1.055 * pow(L, (1.0 / 2.4)) - 0.055;
}
vec3 rgb_to_srgb(vec3 color) {
return vec3(lts(color.r), lts(color.g), lts(color.b));
}
float stl(float S) {
if (abs(S) < 0.04045) {
return S / 12.92;
}
return pow((S + 0.055) / 1.055, 2.4);
}
vec3 srgb_to_rgb(vec3 color) {
return vec3(stl(color.r), stl(color.g), stl(color.b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment