Blender V5.3
overlay_xray_fade.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#pragma once
14
15#include "gpu_shader_compat.hh"
18
20
21struct TexelData {
22 float depth;
24};
25
26struct Resources {
31
32 [[push_constant]] const float opacity;
33
35 {
36 return {
37 .depth = textureLod(depth_tx, uv, 0.0f).r,
38 .xray_depth = textureLod(xray_depth_tx, uv, 0.0f).r,
39 };
40 }
41
43 {
44 return {
45 .depth = textureLod(depth_in_front_tx, uv, 0.0f).r,
46 .xray_depth = textureLod(xray_depth_in_front_tx, uv, 0.0f).r,
47 };
48 }
49};
50
51struct VertOut {
53};
54
55[[vertex]] void vert_main([[vertex_id]] const int &vert_id,
56 [[out]] VertOut &v_out,
58{
59 fullscreen_vertex(vert_id, position, v_out.uv);
60}
61
62struct FragOut {
64};
65
67 [[in]] const VertOut &v_in,
68 [[out]] FragOut &frag_out)
69{
70 TexelData data_in_front = srt.sample_texel_in_front(v_in.uv);
71
72 if (data_in_front.xray_depth != 1.0f) {
73 if (data_in_front.depth < data_in_front.xray_depth) {
74 frag_out.color = float4(srt.opacity);
75 return;
76 }
77
79 return;
80 }
81
82 TexelData data = srt.sample_texel(v_in.uv);
83
84 /* Merge in-front depth. */
85 if (data_in_front.depth != 1.0f) {
86 data.depth = 0.0f;
87 }
88
89 if (data.depth < data.xray_depth) {
90 frag_out.color = float4(srt.opacity);
91 return;
92 }
93
95}
96
98
99} // namespace overlay::xray_fade
#define position
#define smooth
#define push_constant
#define resource_table
#define sampler(slot)
#define fragment
#define vertex_id
#define vertex
#define frag_color(slot)
void gpu_discard_fragment()
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
void fullscreen_vertex(int vertex_id, float4 &out_position)
PipelineGraphic pipeline(vert_main, frag_main)
void frag_main(Resources &srt, const VertOut &v_in, FragOut &frag_out)
void vert_main(const int &vert_id, VertOut &v_out, float4 &position)
TexelData sample_texel_in_front(float2 uv)
const sampler2DDepth xray_depth_in_front_tx