Blender V5.3
gpu_shader_common_color_ramp.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
5#pragma once
6
8
9[[node]]
11 float fac, float edge, float4 color1, float4 color2, float4 &outcol, float &outalpha)
12{
13 outcol = (fac > edge) ? color2 : color1;
14 outalpha = outcol.a;
15}
16
17[[node]]
19 float fac, float2 mulbias, float4 color1, float4 color2, float4 &outcol, float &outalpha)
20{
21 fac = clamp(fac * mulbias.x + mulbias.y, 0.0f, 1.0f);
22 outcol = mix(color1, color2, fac);
23 outalpha = outcol.a;
24}
25
26[[node]]
28 float fac, float2 mulbias, float4 color1, float4 color2, float4 &outcol, float &outalpha)
29{
30 fac = clamp(fac * mulbias.x + mulbias.y, 0.0f, 1.0f);
31 fac = fac * fac * (3.0f - 2.0f * fac);
32 outcol = mix(color1, color2, fac);
33 outalpha = outcol.a;
34}
35
36/* Color maps are stored in texture samplers, so ensure that the coordinate evaluates the sampler
37 * at the center of the pixels, because samplers are evaluated using linear interpolation. Given
38 * the coordinate in the [0, 1] range. */
39float compute_color_map_coordinate(float coordinate)
40{
41 /* Color maps have a fixed width of 257. We offset by the equivalent of half a pixel and scale
42 * down such that the normalized coordinate 1.0 corresponds to the center of the last pixel. */
43 constexpr float sampler_resolution = 257.0f;
44 constexpr float sampler_offset = 0.5f / sampler_resolution;
45 constexpr float sampler_scale = 1.0f - (1.0f / sampler_resolution);
46 return coordinate * sampler_scale + sampler_offset;
47}
48
49[[node]]
50void valtorgb(float fac, sampler1DArray colormap, float layer, float4 &outcol, float &outalpha)
51{
52 outcol = texture(colormap, float2(compute_color_map_coordinate(fac), layer));
53 outalpha = outcol.a;
54}
55
56[[node]]
58 float fac, sampler1DArray colormap, float layer, float4 &outcol, float &outalpha)
59{
60 fac = clamp(fac, 0.0f, 1.0f);
61 outcol = texelFetch(colormap, int2(fac * (textureSize(colormap, 0).x - 1), layer), 0);
62 outalpha = outcol.a;
63}
void valtorgb(float fac, sampler1DArray colormap, float layer, float4 &outcol, float &outalpha)
void valtorgb_opti_linear(float fac, float2 mulbias, float4 color1, float4 color2, float4 &outcol, float &outalpha)
void valtorgb_opti_ease(float fac, float2 mulbias, float4 color1, float4 color2, float4 &outcol, float &outalpha)
void valtorgb_nearest(float fac, sampler1DArray colormap, float layer, float4 &outcol, float &outalpha)
float compute_color_map_coordinate(float coordinate)
void valtorgb_opti_constant(float fac, float edge, float4 color1, float4 color2, float4 &outcol, float &outalpha)
#define layer
constexpr T clamp(T, U, U) RET
SamplerBase< float, 1, false, true > sampler1DArray
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
TEX_TEMPLATE SizeVec textureSize(T, int) RET
#define mix
float x
float y