Blender V5.3
eevee_geom_curves.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "draw_curves.bsl.hh"
8#include "draw_model.bsl.hh"
9#include "eevee_attributes_curves_lib.bsl.hh" /* IWYU pragma: export */
11#include "eevee_pipeline.bsl.hh"
15#include "eevee_velocity.bsl.hh"
16
17#if defined(GPU_NVIDIA) && defined(GPU_OPENGL)
18/* WORKAROUND: Fix legacy driver compiler issue (see #148472). */
19# define const
20#endif
21
22namespace eevee {
23
26 [[resource_table]] const PipelineConstants &pipe,
28 [[resource_table]] const Uniform &uni,
29 [[instance_index]] const int inst_index,
30 [[resource_table]] const draw::View &views,
31 [[resource_table]] const draw::Model &models,
32 [[resource_table]] const draw::Infos &infos,
33 [[resource_table]] const draw::Resource &res_id,
34 [[resource_table, condition(is_shadow_pipe)]] GeomShadow &shadow,
35 [[resource_table, condition(use_clip_plane)]] const ClipPlane &clip_srt,
36 [[resource_table, condition(use_velocity)]] const GeometryVelocity &geo_vel,
38 [[out]] VertOutCurves &curve_interp,
39 [[out, condition(is_shadow_pipe)]] VertOutShadow &shadow_iface,
40 [[out, condition(is_shadow_pipe)]] VertOutShadowClipping &shadow_clip,
41 [[out, condition(use_clip_plane)]] VertOutClipPlane &clip_interp,
42 [[out, condition(use_velocity)]] VertOutVelocity &motion,
43 [[vertex_id]] const int vert_id,
44 [[position]] float4 &out_position,
45 [[viewport_index, condition(is_shadow_pipe &&use_multi_viewport)]] int &out_viewport)
46{
47 draw::ID id = res_id.get(inst_index);
48 uint view_id = 0;
49 uint resource_id = id.resource_id<1>();
50 if (pipe.is_shadow_pipe) [[static_branch]] {
51 view_id = id.view_id<64>();
52 resource_id = id.resource_id<64>();
53 }
54
55 const ViewMatrices view = views.get(view_id);
56 const ObjectMatrices obj = models.get(resource_id);
57
58 if (pipe.is_shadow_pipe) [[static_branch]] {
59 shadow_iface.shadow_view_id = int(view_id);
60 if (pipe.use_multi_viewport) [[static_branch]] {
61 out_viewport = int(shadow.render_view_buf[view_id].viewport_index);
62 }
63 }
64
65 init_interface(interp, id.raw_id);
66
67 const draw::curves::Point ls_pt = curves.point_get(uint(vert_id));
68 const draw::curves::Point ws_pt = curves.object_to_world(ls_pt, obj.model);
69
70 const float3 V = view.world_incident_vector(ws_pt.P);
71
72 const draw::curves::ShapePoint pt = curves.shape_point_get(ws_pt, V);
73 interp.P = pt.P;
74 /* Correct normal is derived in fragment shader. */
75 interp.N = pt.curve_N;
76
77 curve_interp.binormal = pt.curve_B;
78 curve_interp.tangent = pt.curve_T;
79 /* Final radius is used for correct normal interpolation. */
80 curve_interp.radius = ws_pt.radius;
81 /* Scaled by radius for correct interpolation. */
82 curve_interp.time_width = ws_pt.azimuthal_offset * ws_pt.radius;
83 /* Note: Used for attribute loading. */
84 curve_interp.point_id = float(ws_pt.point_id);
85 curve_interp.strand_id = ws_pt.curve_id;
86
87 if (pipe.use_velocity) [[static_branch]] {
88 /* Due to the screen space nature of the vertex positioning, we compute only the motion of
89 * curve strand, not its cylinder. Otherwise we would add the rotation velocity. */
90 int vert_idx = ws_pt.point_id;
91 float3 prv, nxt;
92 float3 pos = ls_pt.P;
93 geo_vel.local_position_deltas(pos, vert_idx, prv, nxt, resource_id);
94 /* FIXME(fclem): Evaluating before displacement avoid displacement being treated as motion but
95 * ignores motion from animated displacement. Supporting animated displacement motion vectors
96 * would require evaluating the node-tree multiple time with different node-tree UBOs evaluated
97 * at different times, but also with different attributes (maybe we could assume static
98 * attribute at least). */
99 geo_vel.vertex_velocity(prv, pos, nxt, motion.prev, motion.next, resource_id, obj.model);
100 }
101
102 ObjectInfos ob_infos = infos.get(resource_id);
103 /* Compute Original Coordinate (ORCO). */
104 float3 lP_root = curves.get_curve_root_pos(ws_pt.point_id, ws_pt.curve_segment);
105 float3 lP_orco = lP_root * ob_infos.orco_mul + ob_infos.orco_add;
106
107 ShadingData sd = init_globals(pipe, uni, interp, view, true, float4(0));
108 init_globals_curves(interp, curve_interp, sd, view);
109
111 ws_pt.point_id,
112 ws_pt.curve_segment,
113 curves.drw_curves.is_point_attribute,
114 lP_orco});
115
116 interp.P += nodetree_displacement(kg, sd);
117
118 if (pipe.is_shadow_pipe) [[static_branch]] {
119 /* Since curves always face the view, camera and shadow orientation don't match.
120 * Apply a bias to avoid self-shadow issues. */
121 interp.P -= V * ws_pt.radius;
122 }
123
124 if (pipe.use_clip_plane) [[static_branch]] {
125 clip_interp.clip_distance = dot(clip_srt.clip_plane.plane, float4(interp.P, 1.0f));
126 }
127
128 float3 vs_P = view.point_world_to_view(interp.P);
129
130 if (pipe.is_shadow_pipe) [[static_branch]] {
131 ShadowRenderView view = shadow.render_view_buf[view_id];
132 shadow_clip.position = shadow_position_vector_get(vs_P, view);
133 shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
134 }
135
136 out_position = reverse_z::transform(view.point_view_to_homogenous(vs_P));
137}
138
139} // namespace eevee
140
141#if defined(GPU_NVIDIA) && defined(GPU_OPENGL)
142/* WORKAROUND: Fix legacy driver compiler issue (see #148472). */
143# undef const
144#endif
void attrib_load(WorldPoint)
float3 nodetree_displacement(KernelGlobals &, ShadingData &)
float3 shadow_position_vector_get(float3 view_position, ShadowRenderView view)
float3 shadow_clip_vector_get(float3 view_position, float clip_distance_inv)
#define instance_index
#define viewport_index
#define position
#define resource_table
#define static_branch
#define vertex_id
#define clip_control
#define condition(cond)
#define vertex
float dot(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
ShadingData init_globals(const eevee::PipelineConstants &pipe, const eevee::Uniform &uni, const VertOutCommon &interp, const ViewMatrices view, bool front_face, float4 fragment_co)
void geom_curves(KernelGlobals &kg, const PipelineConstants &pipe, const draw::Curves &curves, const Uniform &uni, const int inst_index, const draw::View &views, const draw::Model &models, const draw::Infos &infos, const draw::Resource &res_id, GeomShadow &shadow, const ClipPlane &clip_srt, const GeometryVelocity &geo_vel, VertOutCommon &interp, VertOutCurves &curve_interp, VertOutShadow &shadow_iface, VertOutShadowClipping &shadow_clip, VertOutClipPlane &clip_interp, VertOutVelocity &motion, const int vert_id, float4 &out_position, int &out_viewport)
void init_interface(VertOutCommon &interp, uint resource_id_raw)
void init_globals_curves(const VertOutCommon &interp, const VertOutCurves &curve_interp, ShadingData &sd, const ViewMatrices view)
float4 transform(float4 hs_position)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
packed_float3 orco_add
packed_float3 orco_mul
float3 point_world_to_view(float3 P) const
float4 point_view_to_homogenous(float3 vP) const
float3 world_incident_vector(float3 P) const
CCL_NAMESPACE_BEGIN struct Window V