Blender V5.3
gpu_shader_image.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
9
10namespace builtin::image {
11
27
32
37
38struct VertOut {
40};
41
42[[vertex]] void image_vert([[resource_table]] const Image &srt,
43 [[in]] const VertIn &v_in,
44 [[out]] VertOut &v_out,
45 [[position]] float4 &out_pos)
46{
47 out_pos = srt.ModelViewProjectionMatrix * float4(v_in.pos, 1.0f);
48 v_out.uv = v_in.texCoord;
49}
50
52 [[resource_table]] const ImageRect &rect,
53 [[vertex_id]] const int vert_id,
54 [[out]] VertOut &v_out,
55 [[position]] float4 &out_pos)
56{
57 float3 co = float3(0);
58 if (vert_id == 0) {
59 co.xy = rect.rect_geom.xw;
60 v_out.uv = rect.rect_icon.xw;
61 }
62 else if (vert_id == 1) {
63 co.xy = rect.rect_geom.xy;
64 v_out.uv = rect.rect_icon.xy;
65 }
66 else if (vert_id == 2) {
67 co.xy = rect.rect_geom.zw;
68 v_out.uv = rect.rect_icon.zw;
69 }
70 else {
71 co.xy = rect.rect_geom.zy;
72 v_out.uv = rect.rect_icon.zy;
73 }
74
75 out_pos = srt.ModelViewProjectionMatrix * float4(co, 1.0f);
76}
77
78struct FragOut {
80};
81
82[[fragment]] void image_frag([[resource_table]] const Image &srt,
84 [[in]] const VertOut &v_out,
85 [[out]] FragOut &frag_out)
86{
87 float4 col = texture(srt.image, v_out.uv);
88
89 if (srt.use_desaturation) [[static_branch]] {
90 col.rgb = mix(col.rgb, float3(average(col.rgb)), srt.factor);
91 }
92
93 if (srt.use_shuffle) [[static_branch]] {
94 col = float4(col.r * srt.shuffle.r + col.g * srt.shuffle.g + col.b * srt.shuffle.b +
95 col.a * srt.shuffle.a);
96 }
97
98 if (srt.use_color) [[static_branch]] {
99 col *= srt.color;
100 }
101
102 if (srt.use_linear_input) [[static_branch]] {
103 col = ColorSpace::scene_linear_to_rec709_srgb(srt.gpu_scene_linear_to_rec709, col);
104 }
105 col = colorspace.rec709_srgb_to_output_space(col);
106
107 frag_out.color = col;
108}
109
112 [[push_constant]] const bool overlay;
114
116
117 /* Sampler slots should match OCIO's. */
120};
121
123 [[in]] const VertIn &v_in,
124 [[out]] VertOut &v_out,
125 [[position]] float4 &out_pos)
126{
127 out_pos = srt.ModelViewProjectionMatrix * float4(v_in.pos, 1.0f);
128 v_out.uv = v_in.texCoord;
129}
130
132 [[in]] const VertOut &v_out,
133 [[out]] FragOut &frag_out)
134{
135 float4 image_col = texture(srt.image_texture, v_out.uv);
136 float4 overlay_col = texture(srt.overlays_texture, v_out.uv);
137
138 if (srt.overlay) {
139 if (srt.use_hdr_display) {
140 /* When using HDR, interpolate towards clamped color to improve display of
141 * alpha-blended overlays. */
142 image_col = mix(image_col, saturate(image_col), overlay_col.a);
143 }
144 image_col *= 1.0f - overlay_col.a;
145 image_col += overlay_col;
146 }
147
148 if (srt.display_transform) {
149 float3x3 identity = float3x3(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1));
150 image_col = ColorSpace::scene_linear_to_rec709_srgb(identity, image_col);
151 }
152
153 frag_out.color = image_col;
154}
155
160
166
171
172 static StereoSettings unpack(int packed_settings)
173 {
174 return {.display_mode = DisplayMode(packed_settings & ((1 << 3) - 1)),
175 .interlace_mode = InterlaceMode((packed_settings >> 3) & ((1 << 3) - 1)),
176 .interlace_swap = bool(packed_settings >> 6)};
177 }
178
179 bool interlace(int2 texel)
180 {
181 switch (interlace_mode) {
183 return ((texel.x + texel.y) & 1) != 0;
185 return (texel.y & 1) != 0;
187 return (texel.x & 1) != 0;
188 }
189 return false;
190 }
191};
192
201
203 [[in]] const VertIn &v_in,
204 [[position]] float4 &out_pos)
205{
206 out_pos = srt.ModelViewProjectionMatrix * float4(v_in.pos, 1.0f);
207}
208
213
215 [[frag_coord]] const float4 frag_co,
216 [[out]] FragOutStereo &frag_out)
217{
218 int2 texel = int2(frag_co.xy);
219
220 StereoSettings settings = StereoSettings::unpack(srt.stereoDisplaySettings);
221
222 if (settings.display_mode == S3D_DISPLAY_INTERLACE &&
223 (settings.interlace(texel) == settings.interlace_swap))
224 {
226 }
227
228 frag_out.color_overlay = texelFetch(srt.overlayTexture, texel, 0);
229 frag_out.color_image = texelFetch(srt.imageTexture, texel, 0);
230}
231
232} // namespace builtin::image
233
237 .use_linear_input = false,
238 .use_color = false,
239 .use_desaturation = false,
240 .use_shuffle = false,
241 });
245 .use_linear_input = true,
246 .use_color = false,
247 .use_desaturation = false,
248 .use_shuffle = false,
249 });
253 .use_linear_input = false,
254 .use_color = true,
255 .use_desaturation = false,
256 .use_shuffle = false,
257 });
261 .use_linear_input = true,
262 .use_color = true,
263 .use_desaturation = false,
264 .use_shuffle = false,
265 });
269 .use_linear_input = false,
270 .use_color = true,
271 .use_desaturation = false,
272 .use_shuffle = true,
273 });
277 .use_linear_input = false,
278 .use_color = true,
279 .use_desaturation = true,
280 .use_shuffle = false,
281 });
285 .use_linear_input = false,
286 .use_color = true,
287 .use_desaturation = false,
288 .use_shuffle = false,
289 });
290
#define position
#define frag_coord
#define smooth
#define push_constant
#define compilation_constant
#define resource_table
#define sampler(slot)
#define attribute(slot)
#define static_branch
#define fragment
#define vertex_id
#define condition(cond)
#define vertex
#define frag_color(slot)
void gpu_discard_fragment()
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
SamplerBase< float, 2 > sampler2D
PipelineGraphic gpu_shader_2D_image_desaturate_color(builtin::image::image_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=false,.use_color=true,.use_desaturation=true,.use_shuffle=false, })
PipelineGraphic gpu_shader_3D_image_scene_linear(builtin::image::image_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=true,.use_color=false,.use_desaturation=false,.use_shuffle=false, })
PipelineGraphic gpu_shader_3D_image_color_scene_linear(builtin::image::image_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=true,.use_color=true,.use_desaturation=false,.use_shuffle=false, })
PipelineGraphic gpu_shader_2D_image_overlays_stereo_merge(builtin::image::image_overlay_merge_stereo_vert, builtin::image::image_overlay_merge_stereo_frag)
PipelineGraphic gpu_shader_3D_image_color(builtin::image::image_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=false,.use_color=true,.use_desaturation=false,.use_shuffle=false, })
PipelineGraphic gpu_shader_3D_image(builtin::image::image_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=false,.use_color=false,.use_desaturation=false,.use_shuffle=false, })
PipelineGraphic gpu_shader_2D_image_shuffle_color(builtin::image::image_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=false,.use_color=true,.use_desaturation=false,.use_shuffle=true, })
PipelineGraphic gpu_shader_2D_image_overlays_merge(builtin::image::image_overlay_vert, builtin::image::image_overlay_merge_frag)
PipelineGraphic gpu_shader_2D_image_rect_color(builtin::image::image_rect_vert, builtin::image::image_frag, builtin::image::Image{ .use_linear_input=false,.use_color=true,.use_desaturation=false,.use_shuffle=false, })
float average(float2 a)
MatBase< float, 4, 4 > float4x4
void image_overlay_merge_frag(const ImageOverlayMerge &srt, const VertOut &v_out, FragOut &frag_out)
void image_overlay_merge_stereo_frag(const ImageStereoMerge &srt, const float4 frag_co, FragOutStereo &frag_out)
void image_frag(const Image &srt, const ColorSpace &colorspace, const VertOut &v_out, FragOut &frag_out)
void image_overlay_merge_stereo_vert(const ImageStereoMerge &srt, const VertIn &v_in, float4 &out_pos)
void image_overlay_vert(const ImageOverlayMerge &srt, const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void image_rect_vert(const Image &srt, const ImageRect &rect, const int vert_id, VertOut &v_out, float4 &out_pos)
void image_vert(const Image &srt, const VertIn &v_in, VertOut &v_out, float4 &out_pos)
#define mix
#define saturate(a)
Definition smaa.cc:319
static float4 scene_linear_to_rec709_srgb(float3x3 scene_linear_to_rec709, float4 scene_linear_color)
const float3x3 gpu_scene_linear_to_rec709
const float4x4 ModelViewProjectionMatrix
static StereoSettings unpack(int packed_settings)