Blender V5.3
draw_colormanagement.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "gpu_shader_compat.hh"
12
13float linearrgb_to_srgb(float c)
14{
15 if (c < 0.0031308f) {
16 return (c < 0.0f) ? 0.0f : c * 12.92f;
17 }
18 return 1.055f * pow(c, 1.0f / 2.4f) - 0.055f;
19}
20
22{
23 /* By convention image textures return scene linear colors, but
24 * overlays still assume srgb. */
25 float4 col = texture(tex, co);
26 /* Un-pre-multiply if stored multiplied, since straight alpha is expected by shaders. */
27 if (premultiplied && !(col.a == 0.0f || col.a == 1.0f)) {
28 col.rgb = col.rgb / col.a;
29 }
30 return col;
31}
32
33float4 texture_read_as_srgb(sampler2D tex, bool premultiplied, float2 co)
34{
35 float4 col = texture_read_as_linearrgb(tex, premultiplied, co);
36 col.r = linearrgb_to_srgb(col.r);
37 col.g = linearrgb_to_srgb(col.g);
38 col.b = linearrgb_to_srgb(col.b);
39 return col;
40}
float4 texture_read_as_srgb(sampler2D tex, bool premultiplied, float2 co)
float4 texture_read_as_linearrgb(sampler2D tex, bool premultiplied, float2 co)
float linearrgb_to_srgb(float c)
#define pow
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
SamplerBase< float, 2 > sampler2D