Blender V5.3
eevee_geom_gsplat.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8#include "draw_model.bsl.hh"
9#include "draw_view.bsl.hh"
10#include "eevee_attributes_pointcloud_lib.bsl.hh" /* IWYU pragma: export */
12#include "eevee_pipeline.bsl.hh"
15#include "eevee_velocity.bsl.hh"
16
17namespace eevee {
18
20 [[resource_table]] const PipelineConstants &pipe,
22 [[resource_table]] const Uniform &uni,
23 [[instance_index]] const int inst_index,
24 [[resource_table]] const draw::View &views,
25 [[resource_table]] const draw::Model &models,
26 [[resource_table]] const draw::Infos &infos,
27 [[resource_table]] const draw::Resource &res_id,
28 [[resource_table, condition(is_shadow_pipe)]] GeomShadow &shadow,
29 [[resource_table, condition(use_clip_plane)]] const ClipPlane &clip_srt,
30 [[resource_table, condition(use_velocity)]] const GeometryVelocity &geo_vel,
32 [[out]] VertOutGSplat &gsplat_interp,
33 [[out, condition(is_shadow_pipe)]] VertOutShadow &shadow_iface,
34 [[out, condition(is_shadow_pipe)]] VertOutShadowClipping &shadow_clip,
35 [[out, condition(use_clip_plane)]] VertOutClipPlane &clip_interp,
36 [[out, condition(use_velocity)]] VertOutVelocity &motion,
37 [[vertex_id]] const int vert_id,
38 [[position]] float4 &out_position,
39 /* Note: Removed manually if not needed. Otherwise, can generate geometry shader fallback. */
40 [[viewport_index]] int &out_viewport)
41{
42 draw::ID id = res_id.get(inst_index);
43 uint view_id = 0;
44 uint resource_id = id.resource_id<1>();
45 if (pipe.is_shadow_pipe) [[static_branch]] {
46 view_id = id.view_id<64>();
47 resource_id = id.resource_id<64>();
48 }
49
50 const ViewMatrices view = views.get(view_id);
51 const ObjectMatrices obj = models.get(resource_id);
52 const ObjectInfos ob_infos = infos.get(resource_id);
53
54 if (pipe.is_shadow_pipe) [[static_branch]] {
55 shadow_iface.shadow_view_id = int(view_id);
56 out_viewport = int(shadow.render_view_buf[view_id].viewport_index);
57 }
58
59 init_interface(interp, id.raw_id);
60
61 draw::gsplat::SplatShape gs = shape.get_splat(uint(vert_id), obj, view);
62 if (gs.is_culled()) {
63 out_position = float4(NAN_FLT);
64 return;
65 }
66
67 /* Gaussian splats typically do an alpha cut off. The original paper used 1/255
68 * as a threshold, which persists in the fitted data. */
69 float opacity = shape.get_opacity(gs.id);
70 if (opacity < (1.0f / 255.0f)) {
71 out_position = float4(NAN_FLT);
72 return;
73 }
74
75 /* Output interface data. */
76 gsplat_interp.billboard_co = gs.shape_offset;
77 gsplat_interp.opacity = opacity;
78 interp.P = gs.wP;
79 interp.N = gs.wN;
80
81 if (pipe.is_shadow_pipe) [[static_branch]] {
82 /* GSplat billboards always face the view, so camera and shadow orientation don't match.
83 * Apply a bias to avoid self-shadow issues. */
84 interp.P -= view.world_incident_vector(interp.P) * 1e-3f;
85 }
86
87 if (pipe.use_velocity) [[static_branch]] {
88 float3 lP = gs.mean;
89 float3 prv, nxt;
90 geo_vel.local_position_deltas(lP, int(gs.id), prv, nxt, resource_id);
91 /* FIXME(fclem): Evaluating before displacement avoid displacement being treated as motion but
92 * ignores motion from animated displacement. Supporting animated displacement motion vectors
93 * would require evaluating the nodetree multiple time with different nodetree UBOs evaluated
94 * at different times, but also with different attributes (maybe we could assume static
95 * attribute at least). */
96 geo_vel.vertex_velocity(prv, lP, nxt, motion.prev, motion.next, resource_id, obj.model);
97 }
98
99 /* Compute Original Coordinate (ORCO). */
100 float3 lP_orco = gs.mean * ob_infos.orco_mul + ob_infos.orco_add;
101
102 [[maybe_unused]] ShadingData sd = init_globals(pipe, uni, interp, view, true, float4(0));
103
104 attrib_load(PointCloudPoint{gs.mean, int(gs.id), lP_orco});
105
106 /* NOTE(not_mark) What does displacement even mean on a gsplat :S */
107 /* interp.P += nodetree_displacement(kg, sd); */
108
109 if (pipe.use_clip_plane) [[static_branch]] {
110 clip_interp.clip_distance = dot(clip_srt.clip_plane.plane, float4(interp.P, 1.0f));
111 }
112
113 if (pipe.is_shadow_pipe) [[static_branch]] {
114 float3 vs_P = view.point_world_to_view(interp.P);
115 ShadowRenderView view = shadow.render_view_buf[view_id];
116 shadow_clip.position = shadow_position_vector_get(vs_P, view);
117 shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
118 }
119
120 out_position = reverse_z::transform(gs.hP);
121}
122
123} // namespace eevee
#define NAN_FLT
void attrib_load(WorldPoint)
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_gsplat(const PipelineConstants &pipe, const draw::gsplat::ShapeResource &shape, 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, VertOutGSplat &gsplat_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)
float4 transform(float4 hs_position)
packed_float3 orco_add
packed_float3 orco_mul
float3 point_world_to_view(float3 P) const
float3 world_incident_vector(float3 P) const