Blender
V5.3
source
blender
gpu
shaders
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
7
#include "
gpu_shader_compat.hh
"
8
9
namespace
builtin
{
10
11
struct
ColorSpace
{
12
[[
push_constant
]]
const
bool
srgbTarget
;
13
29
float4
rec709_srgb_to_output_space
(
float4
srgb_color)
const
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
max
btScalar max
Definition
btHeightfieldTerrainShape.h:79
gpu_shader_compat.hh
push_constant
#define push_constant
Definition
gpu_shader_cxx_attribute.hh:126
pow
#define pow
Definition
gpu_shader_cxx_builtin.hh:116
step
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
builtin
Definition
gpu_shader_annotation.bsl.hh:11
mix
#define mix
Definition
radial_tiling_shared.hh:83
builtin::ColorSpace
Definition
gpu_shader_colorspace.bsl.hh:11
builtin::ColorSpace::rec709_srgb_to_output_space
float4 rec709_srgb_to_output_space(float4 srgb_color) const
Definition
gpu_shader_colorspace.bsl.hh:29
builtin::ColorSpace::srgbTarget
const bool srgbTarget
Definition
gpu_shader_colorspace.bsl.hh:12
builtin::ColorSpace::scene_linear_to_rec709_srgb
static float4 scene_linear_to_rec709_srgb(float3x3 scene_linear_to_rec709, float4 scene_linear_color)
Definition
gpu_shader_colorspace.bsl.hh:50
float3
Definition
sky_math.h:135
float3x3
Definition
types_float3x3.h:21
float4
Definition
sky_math.h:224
Generated on
for Blender by
doxygen
1.18.0