Blender V5.3
eevee_surf_depth.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#pragma once
9
15#include "eevee_velocity.bsl.hh"
16
18{
19 float4 out_color;
20 out_color.rgb = sd.emission;
21 out_color.a = saturate(1.0f - average(sd.transmittance));
22
23 /* Reset for the next closure tree. */
24 closure_weights_reset(kg, sd, 0.0f);
25
26 return out_color;
27}
28
29namespace eevee {
30
31/* WORKAROUND(fclem): This is not supposed to be needed.
32 * But Metal still writes to the velocity buffer if the frag output is defined. And conditions are
33 * not yet supported on in/out. */
34template<bool with_velocity> struct SurfaceDepthFragOut {};
35
40
46
47template<bool with_velocity>
48[[fragment]]
51 [[resource_table]] const Uniform &uni,
52 [[resource_table]] const Sampling &sampling,
53 [[resource_table]] const UtilityTexture & /*util_tx*/,
54 [[resource_table]] const draw::View &views,
55 [[resource_table]] [[condition(use_velocity)]] const GeometryVelocity &geo_vel,
56 [[frag_coord]] const float4 frag_co,
57 [[in]] const VertOutCommon &interp,
58 [[in]] [[condition(is_curves)]] const VertOutCurves &curves_interp,
59 [[in]] [[condition(is_pointcloud)]] const VertOutPointcloud &ptcloud_interp,
60 [[in]] [[condition(is_gsplat)]] const VertOutGSplat &gsplat_interp,
61 [[in]] [[condition(use_velocity)]] const VertOutVelocity &motion,
62 [[in]] [[condition(use_clip_plane)]] const VertOutClipPlane &clip_interp,
64 [[bary_coord]] [[condition(use_barycentric)]] const float3 bary_co,
65 [[front_facing]] const bool front_face)
66{
67 if (pipe.use_transparency) [[static_branch]] {
68 const ViewMatrices view = views.get(0);
69
70 float3 barycentric_co = float3(0.0f);
71 if (pipe.use_barycentric) [[static_branch]] {
72 barycentric_co = bary_co;
73 }
74
75 ShadingData sd = init_globals(pipe, uni, interp, view, front_face, frag_co);
76 if (pipe.is_mesh) [[static_branch]] {
77 init_globals_mesh(interp, sd, barycentric_co);
78 }
79 else if (pipe.is_curves) [[static_branch]] {
80 init_globals_curves(interp, curves_interp, sd, view);
81 }
82 else if (pipe.is_pointcloud) [[static_branch]] {
83 init_globals_pointcloud(ptcloud_interp, sd);
84 }
85
86 nodetree_surface(kg, sd, 0.0f);
87
88 if (pipe.is_gsplat) [[static_branch]] {
90 }
91
92 float noise_offset = sampling.rng_1D_get(SAMPLING_TRANSPARENCY);
93
95 uni.pipeline_buf.alpha_hash_scale, noise_offset, sd.P);
96
97 float transparency = average(sd.transmittance);
98 if (transparency > threshold) {
100 return;
101 }
102 }
103
104 if (pipe.use_clip_plane) [[static_branch]] {
105 /* Do not use hardware clip planes as they modify the rasterization (some GPUs add vertices).
106 * This would in turn create a discrepancy between the pre-pass depth and the G-buffer depth
107 * which exhibits missing pixels data. */
108 if (clip_interp.clip_distance > 0.0f) {
110 return;
111 }
112 }
113
114 if constexpr (with_velocity) {
115 if (pipe.use_velocity) [[static_branch]] {
116 float3 P_prv = interp.P + motion.prev;
117 float3 P_nxt = interp.P + motion.next;
118 const ViewMatrices view = views.get(0);
119 frag_out.velocity = velocity::pack(
120 geo_vel.camera.surface_velocity_local(view, P_prv, interp.P, P_nxt));
121 }
122 }
123
124 /* Always written, but may be optimized out by frame-buffer/subpass setup. */
125 frag_out.normal.rgb = normalize(interp.N) * 0.5f + 0.5f;
126 frag_out.object_id = interp.resource_id_raw & uint(0xFFFF);
127}
128
131 const Uniform &,
132 const Sampling &,
133 const UtilityTexture &,
134 const draw::View &,
135 const GeometryVelocity &,
136 const float4,
137 const VertOutCommon &,
138 const VertOutCurves &,
139 const VertOutPointcloud &,
140 const VertOutGSplat &,
141 const VertOutVelocity &,
142 const VertOutClipPlane &,
144 const float3,
145 const bool);
148 const Uniform &,
149 const Sampling &,
150 const UtilityTexture &,
151 const draw::View &,
152 const GeometryVelocity &,
153 const float4,
154 const VertOutCommon &,
155 const VertOutCurves &,
156 const VertOutPointcloud &,
157 const VertOutGSplat &,
158 const VertOutVelocity &,
159 const VertOutClipPlane &,
161 const float3,
162 const bool);
163
164} // namespace eevee
#define PREPASS_FRAG_OUT_VELOCITY
#define PREPASS_FRAG_OUT_NORMAL
#define PREPASS_FRAG_OUT_OB_ID
Closure nodetree_surface(KernelGlobals &, ShadingData &, float)
void closure_weights_reset(KernelGlobals &kg, ShadingData &sd, float closure_rand)
float4 closure_to_rgba_depth(KernelGlobals &kg, ShadingData &sd, Closure)
#define front_facing
#define bary_coord
#define frag_coord
#define resource_table
#define static_branch
#define fragment
#define condition(cond)
#define frag_color(slot)
void gpu_discard_fragment()
VecBase< float, D > normalize(VecOp< float, D >) RET
float average(float2 a)
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
float alpha_threshold(float hash_scale, float hash_offset, float3 P)
float4 pack(float4 data)
ShadingData init_globals(const eevee::PipelineConstants &pipe, const eevee::Uniform &uni, const VertOutCommon &interp, const ViewMatrices view, bool front_face, float4 fragment_co)
float3 gsplat_amend_transmittance(const VertOutGSplat &gsplat_interp, float3 transmittance)
void init_globals_mesh(const VertOutCommon &interp, ShadingData &sd, float3 barycentric_co)
void init_globals_pointcloud(const VertOutPointcloud &ptcloud_interp, ShadingData &sd)
void init_globals_curves(const VertOutCommon &interp, const VertOutCurves &curve_interp, ShadingData &sd, const ViewMatrices view)
void surf_depth(KernelGlobals &kg, PipelineConstants &pipe, const Uniform &uni, const Sampling &sampling, const UtilityTexture &, const draw::View &views, const GeometryVelocity &geo_vel, const float4 frag_co, const VertOutCommon &interp, const VertOutCurves &curves_interp, const VertOutPointcloud &ptcloud_interp, const VertOutGSplat &gsplat_interp, const VertOutVelocity &motion, const VertOutClipPlane &clip_interp, SurfaceDepthFragOut< with_velocity > &frag_out, const float3 bary_co, const bool front_face)
#define saturate(a)
Definition smaa.cc:319
packed_float3 transmittance
packed_float3 emission