Blender V5.3
workbench_composite.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
15#include "workbench_defines.hh"
18
20
27
46
47[[vertex]] void vert([[vertex_id]] const int &vert_id, [[position]] float4 &out_pos)
48{
49 fullscreen_vertex(vert_id, out_pos);
50}
51
52struct FragOut {
54};
55
58 [[resource_table]] draw::View &views,
59 [[out]] FragOut &frag_out)
60{
61 float2 uv = frag_coord.xy / float2(textureSize(srt.depth_tx, 0).xy);
62
63 float depth = texture(srt.depth_tx, uv).r;
64 if (depth == 1.0f) {
65 /* Skip the background. */
67 return;
68 }
69
70 ViewMatrices view = views.get(0);
71
72 /* Normal and Incident vector are in view-space. Lighting is evaluated in view-space. */
73 float3 P = view.point_screen_to_view(float3(uv, 0.5f));
75 float3 N = workbench::normal_decode(texture(srt.normal_tx, uv));
76 float4 mat_data = texture(srt.material_tx, uv);
77
78 float3 base_color = mat_data.rgb;
79 float4 color = float4(1.0f);
80
81 if (srt.consts.lighting_mode == WORKBENCH_LIGHTING_MATCAP) [[static_branch]] {
82 /* When using matcaps, mat_data.a is the back-face sign. */
83 N = (mat_data.a > 0.0f) ? N : -N;
84 color.rgb = workbench::get_matcap_lighting(srt.world, srt.matcap_tx, base_color, N, V);
85 }
86 else if (srt.consts.lighting_mode == WORKBENCH_LIGHTING_STUDIO) [[static_branch]] {
87 float roughness = 0.0f, metallic = 0.0f;
88 workbench::float_pair_decode(mat_data.a, roughness, metallic);
89 color.rgb = workbench::get_world_lighting(srt.world, base_color, roughness, metallic, N, V);
90 }
91 else if (srt.consts.lighting_mode == WORKBENCH_LIGHTING_FLAT) [[static_branch]] {
92 color.rgb = base_color;
93 }
94
95 float cavity = 0.0f, edges = 0.0f, curvature = 0.0f;
96 if (srt.consts.use_cavity) [[static_branch]] {
98 srt.cavity, srt.world, view, srt.depth_tx, srt.normal_tx, uv, cavity, edges);
99 }
100
101 if (srt.consts.use_curvature) [[static_branch]] {
102 workbench::curvature_compute(srt.world, srt.object_id_tx, srt.normal_tx, uv, curvature);
103 }
104 color.rgb *= clamp((1.0f - cavity) * (1.0f + edges) * (1.0f + curvature), 0.0f, 4.0f);
105
106 if (srt.consts.use_shadow) [[static_branch]] {
107 bool shadow = texture(srt.stencil_tx, uv).r != 0;
108 color.rgb *= workbench::get_shadow(srt.world, N, shadow);
109 }
110
111 frag_out.color = color;
112}
113
114/* clang-format off */
115PipelineGraphic opaque_studio_cavity_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = true, .use_curvature = true, .use_shadow = true });
116PipelineGraphic opaque_studio_cavity_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = true, .use_curvature = true, .use_shadow = false});
117PipelineGraphic opaque_studio_cavity_no_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = true, .use_curvature = false, .use_shadow = true });
118PipelineGraphic opaque_studio_cavity_no_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = true, .use_curvature = false, .use_shadow = false});
119PipelineGraphic opaque_studio_no_cavity_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = false, .use_curvature = true, .use_shadow = true });
120PipelineGraphic opaque_studio_no_cavity_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = false, .use_curvature = true, .use_shadow = false});
121PipelineGraphic opaque_studio_no_cavity_no_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = false, .use_curvature = false, .use_shadow = true });
122PipelineGraphic opaque_studio_no_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_STUDIO, .use_cavity = false, .use_curvature = false, .use_shadow = false});
123PipelineGraphic opaque_matcap_cavity_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = true, .use_curvature = true, .use_shadow = true });
124PipelineGraphic opaque_matcap_cavity_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = true, .use_curvature = true, .use_shadow = false});
125PipelineGraphic opaque_matcap_cavity_no_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = true, .use_curvature = false, .use_shadow = true });
126PipelineGraphic opaque_matcap_cavity_no_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = true, .use_curvature = false, .use_shadow = false});
127PipelineGraphic opaque_matcap_no_cavity_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = false, .use_curvature = true, .use_shadow = true });
128PipelineGraphic opaque_matcap_no_cavity_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = false, .use_curvature = true, .use_shadow = false});
129PipelineGraphic opaque_matcap_no_cavity_no_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = false, .use_curvature = false, .use_shadow = true });
130PipelineGraphic opaque_matcap_no_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_MATCAP, .use_cavity = false, .use_curvature = false, .use_shadow = false});
131PipelineGraphic opaque_flat_cavity_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = true, .use_curvature = true, .use_shadow = true });
132PipelineGraphic opaque_flat_cavity_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = true, .use_curvature = true, .use_shadow = false});
133PipelineGraphic opaque_flat_cavity_no_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = true, .use_curvature = false, .use_shadow = true });
134PipelineGraphic opaque_flat_cavity_no_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = true, .use_curvature = false, .use_shadow = false});
135PipelineGraphic opaque_flat_no_cavity_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = false, .use_curvature = true, .use_shadow = true });
136PipelineGraphic opaque_flat_no_cavity_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = false, .use_curvature = true, .use_shadow = false});
137PipelineGraphic opaque_flat_no_cavity_no_curvature_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = false, .use_curvature = false, .use_shadow = true });
138PipelineGraphic opaque_flat_no_cavity_no_curvature_no_shadow( vert, frag, Constants{.lighting_mode = WORKBENCH_LIGHTING_FLAT, .use_cavity = false, .use_curvature = false, .use_shadow = false});
139/* clang-format on */
140
141} // namespace workbench::resolve
#define position
#define frag_coord
#define compilation_constant
#define resource_table
#define sampler(slot)
#define static_branch
#define fragment
#define vertex_id
#define condition(cond)
#define vertex
#define frag_color(slot)
void gpu_discard_fragment()
constexpr T clamp(T, U, U) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
SamplerBase< float, 2, false, true > sampler2DArray
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
SamplerBase< uint, 2 > usampler2D
void fullscreen_vertex(int vertex_id, float4 &out_position)
#define N
PipelineGraphic opaque_studio_no_cavity_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=false,.use_curvature=true,.use_shadow=true })
PipelineGraphic opaque_studio_cavity_no_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=true,.use_curvature=false,.use_shadow=true })
PipelineGraphic opaque_flat_no_cavity_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=false,.use_curvature=true,.use_shadow=true })
PipelineGraphic opaque_studio_cavity_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=true,.use_curvature=true,.use_shadow=true })
PipelineGraphic opaque_studio_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=true,.use_curvature=false,.use_shadow=false})
PipelineGraphic opaque_flat_cavity_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=true,.use_curvature=true,.use_shadow=false})
PipelineGraphic opaque_matcap_cavity_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=true,.use_curvature=true,.use_shadow=true })
PipelineGraphic opaque_matcap_no_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=false,.use_curvature=false,.use_shadow=false})
void frag(const float4 &frag_coord, Resources &srt, draw::View &views, FragOut &frag_out)
void vert(const int &vert_id, float4 &out_pos)
PipelineGraphic opaque_studio_no_cavity_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=false,.use_curvature=true,.use_shadow=false})
PipelineGraphic opaque_flat_no_cavity_no_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=false,.use_curvature=false,.use_shadow=true })
PipelineGraphic opaque_matcap_no_cavity_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=false,.use_curvature=true,.use_shadow=true })
PipelineGraphic opaque_studio_no_cavity_no_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=false,.use_curvature=false,.use_shadow=true })
PipelineGraphic opaque_flat_no_cavity_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=false,.use_curvature=true,.use_shadow=false})
PipelineGraphic opaque_matcap_no_cavity_no_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=false,.use_curvature=false,.use_shadow=true })
PipelineGraphic opaque_matcap_cavity_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=true,.use_curvature=true,.use_shadow=false})
PipelineGraphic opaque_studio_cavity_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=true,.use_curvature=true,.use_shadow=false})
PipelineGraphic opaque_matcap_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=true,.use_curvature=false,.use_shadow=false})
PipelineGraphic opaque_matcap_no_cavity_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=false,.use_curvature=true,.use_shadow=false})
PipelineGraphic opaque_flat_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=true,.use_curvature=false,.use_shadow=false})
PipelineGraphic opaque_flat_cavity_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=true,.use_curvature=true,.use_shadow=true })
PipelineGraphic opaque_studio_no_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_STUDIO,.use_cavity=false,.use_curvature=false,.use_shadow=false})
PipelineGraphic opaque_matcap_cavity_no_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_MATCAP,.use_cavity=true,.use_curvature=false,.use_shadow=true })
PipelineGraphic opaque_flat_cavity_no_curvature_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=true,.use_curvature=false,.use_shadow=true })
PipelineGraphic opaque_flat_no_cavity_no_curvature_no_shadow(vert, frag, Constants{.lighting_mode=WORKBENCH_LIGHTING_FLAT,.use_cavity=false,.use_curvature=false,.use_shadow=false})
float3 get_matcap_lighting(const workbench::World &world, sampler2D diffuse_matcap, sampler2D specular_matcap, float3 base_color, float3 N, float3 I)
void float_pair_decode(float data, float &v1, float &v2)
float3 normal_decode(float4 enc)
float get_shadow(const workbench::World &world, float3 N, bool force_shadow)
void cavity_compute(const workbench::Cavity &cavity, const workbench::World &world, ViewMatrices view, sampler2DDepth depth_tx, sampler2D normal_tx, float2 screenco, float &cavities, float &edges)
void curvature_compute(const workbench::World &world, usampler2D object_id_tx, sampler2D normal_tx, float2 uv, float &curvature)
float3 get_world_lighting(const workbench::World &world, float3 base_color, float roughness, float metallic, float3 N, float3 I)
float3 view_incident_vector(float3 vP) const
float3 point_screen_to_view(float3 ssP) const
CCL_NAMESPACE_BEGIN struct Window V
#define WB_MATCAP_SLOT