Converts linear light in [0, 1] to sRGB encoding, the inverse of srgb_to_linear. Values outside [0, 1] are not clamped; clamp first when the result goes into 8 bits.
#import "Math";
assert(abs(linear_to_srgb(0.21404114) - 0.5) < 0.00001);
assert(abs(linear_to_srgb(srgb_to_linear(0.3)) - 0.3) < 0.00001);linear_to_srgb :: (x: float) -> float
Parameters
- x: float
Returns
- float
linear_to_srgb :: (c: Vector3) -> Vector3
Converts the red, green and blue channels of c.
Parameters
- c: Vector3
Returns
#import "Math";
encoded := linear_to_srgb(xyz(0.214, 0, 1));
assert(abs(encoded.x - 0.5) < 0.001 && encoded.y == 0);linear_to_srgb :: (c: Vector4) -> Vector4
Converts the red, green and blue channels of c and leaves alpha as it is.
Parameters
- c: Vector4
Returns
#import "Math";
encoded := linear_to_srgb(xyzw(0.214, 0, 1, 0.3));
assert(abs(encoded.x - 0.5) < 0.001 && encoded.w == 0.3);