Blender V5.3
gpu_shader_colorspace.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9namespace builtin {
10
11struct ColorSpace {
12 [[push_constant]] const bool srgbTarget;
13
30 {
35 if (!srgbTarget) {
36 /* Input should already be in sRGB. */
37 return srgb_color;
38 }
39 /* Note that this is simply counteracting the hardware Linear > sRGB conversion. */
40 float3 c = max(srgb_color.rgb, float3(0.0f));
41 float3 c1 = c * (1.0f / 12.92f);
42 float3 c2 = pow((c + 0.055f) * (1.0f / 1.055f), float3(2.4f));
43 float4 linear_color;
44 linear_color.rgb = mix(c1, c2, step(float3(0.04045f), c));
45 linear_color.a = srgb_color.a;
46 return linear_color;
47 }
48
49 /* Input is Blender Scene Linear. Output is Rec.709 sRGB. */
50 static float4 scene_linear_to_rec709_srgb(float3x3 scene_linear_to_rec709,
51 float4 scene_linear_color)
52 {
53 float3 rec709_linear = scene_linear_to_rec709 * scene_linear_color.rgb;
54
55 /* TODO(fclem): For wide gamut (extended sRGB), we need to encode negative values in a certain
56 * way here. */
57
58 /* Linear to sRGB transform. */
59 float3 c = max(rec709_linear, float3(0.0f));
60 float3 c1 = c * 12.92f;
61 float3 c2 = 1.055f * pow(c, float3(1.0f / 2.4f)) - 0.055f;
62 float4 srgb_color;
63 srgb_color.rgb = mix(c1, c2, step(float3(0.0031308f), c));
64 srgb_color.a = scene_linear_color.a;
65 return srgb_color;
66 }
67};
68
69} // namespace builtin
btScalar max
#define push_constant
#define pow
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define mix
float4 rec709_srgb_to_output_space(float4 srgb_color) const
static float4 scene_linear_to_rec709_srgb(float3x3 scene_linear_to_rec709, float4 scene_linear_color)