MCPcopy Create free account
hub / github.com/Apress/Ray-Tracing-Gems-II / convert_sRGB

Function convert_sRGB

Chapter_20/program.cpp:45–58  ·  view source on GitHub ↗

NOTE: This function only applies gamma.

Source from the content-addressed store, hash-verified

43
44// NOTE: This function only applies gamma.
45uint32_t convert_sRGB(vec3 color) {
46 float r = color.x, g = color.y, b = color.z;
47 r = min(max(r, 0.0), 1.0);
48 g = min(max(g, 0.0), 1.0);
49 b = min(max(b, 0.0), 1.0);
50 // TODO: Is this correct? Validate
51 r = powf(r, 1.0f/2.2f);
52 g = powf(g, 1.0f/2.2f);
53 b = powf(b, 1.0f/2.2f);
54 uint8_t rb = floor(r * 255.0f);
55 uint8_t gb = floor(g * 255.0f);
56 uint8_t bb = floor(b * 255.0f);
57 return 0xFF000000|(bb<<16)|(gb<<8)|rb;
58}
59
60inline vec3 camera_direction(float2 uv, int w, int h, float fov_horizontal_degrees) {
61 float aspect = float(h) / float(w);

Callers 2

renderFunction · 0.85
render_mis_weightsFunction · 0.85

Calls 2

maxFunction · 0.85
minFunction · 0.70

Tested by

no test coverage detected