Blender V5.3
gpu_shader_icon.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
10
11namespace builtin::icon {
12
23
29
30struct VertIn {
32};
33
38[[vertex]] void main_vert([[resource_table]] const Resource &srt,
39 [[instance_index]] const int inst_id,
40 [[position]] float4 &out_pos,
41 [[in]] const VertIn &v_in,
42 [[out]] VertOut &v_out)
43{
44 float4 rect = srt.multi_icon_data.calls_data[inst_id * 3];
45 float4 tex = srt.multi_icon_data.calls_data[inst_id * 3 + 1];
46 v_out.color = srt.multi_icon_data.calls_data[inst_id * 3 + 2];
47
48 /* Use pos to select the right swizzle (instead of gl_VertexID)
49 * in order to workaround an OSX driver bug. */
50 if (all(equal(v_in.pos, float2(0.0f, 0.0f)))) {
51 rect.xy = rect.xz;
52 tex.xy = tex.xz;
53 }
54 else if (all(equal(v_in.pos, float2(0.0f, 1.0f)))) {
55 rect.xy = rect.xw;
56 tex.xy = tex.xw;
57 }
58 else if (all(equal(v_in.pos, float2(1.0f, 1.0f)))) {
59 rect.xy = rect.yw;
60 tex.xy = tex.yw;
61 }
62 else {
63 rect.xy = rect.yz;
64 tex.xy = tex.yz;
65 }
66
67 out_pos = float4(rect.xy, 0.0f, 1.0f);
68 v_out.uv = tex.xy;
69}
70
71struct FragOut {
73};
74
82[[fragment]] void main_frag([[resource_table]] const Resource &srt,
83 [[in]] const VertOut &v_out,
84 [[out]] FragOut &frag_out)
85{
86 /* Sample texture with LOD BIAS. Used instead of custom LOD bias in GPU_SAMPLER_CUSTOM_ICON. */
87 frag_out.color = texture(srt.image, v_out.uv, -0.5f) * v_out.color;
88}
89
90} // namespace builtin::icon
91
#define uniform(slot)
#define instance_index
#define position
#define flat
#define smooth
#define push_constant
#define resource_table
#define sampler(slot)
#define attribute(slot)
#define fragment
#define vertex
#define frag_color(slot)
bool all(VecOp< bool, D >) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
SamplerBase< float, 2 > sampler2D
PipelineGraphic gpu_shader_icon(builtin::icon::main_vert, builtin::icon::main_frag)
MatBase< float, 4, 4 > float4x4
void main_frag(const Resource &srt, const VertOut &v_out, FragOut &frag_out)
void main_vert(const Resource &srt, const int inst_id, float4 &out_pos, const VertIn &v_in, VertOut &v_out)
MultiIconCallData & multi_icon_data