Blender V5.3
eevee_geom_mesh.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_model.bsl.hh"
8#include "eevee_attributes_mesh_lib.bsl.hh" /* IWYU pragma: export */
10#include "eevee_pipeline.bsl.hh"
13#include "eevee_velocity.bsl.hh"
14
15namespace eevee {
16
21
24 [[resource_table]] const PipelineConstants &pipe,
25 [[resource_table]] const Uniform &uni,
26 [[instance_index]] const int inst_index,
27 [[resource_table]] const draw::View &views,
28 [[resource_table]] const draw::Model &models,
29 [[resource_table]] const draw::Infos &infos,
30 [[resource_table]] const draw::Resource &res_id,
31 [[resource_table, condition(is_shadow_pipe)]] const GeomShadow &shadow,
32 [[resource_table, condition(use_clip_plane)]] const ClipPlane &clip_srt,
33 [[resource_table, condition(use_velocity)]] const GeometryVelocity &geo_vel,
34 [[in]] const GeomMeshVertIn &vert_in,
36 [[out, condition(is_shadow_pipe)]] VertOutShadow &shadow_iface,
37 [[out, condition(is_shadow_pipe)]] VertOutShadowClipping &shadow_clip,
38 [[out, condition(use_clip_plane)]] VertOutClipPlane &clip_interp,
39 [[out, condition(use_velocity)]] VertOutVelocity &motion,
40 [[vertex_id]] const int vert_id,
41 [[position]] float4 &out_position,
42 [[viewport_index, condition(is_shadow_pipe &&use_multi_viewport)]] int &out_viewport)
43{
44 draw::ID id = res_id.get(inst_index);
45 uint view_id = 0;
46 uint resource_id = id.resource_id<1>();
47 if (pipe.is_shadow_pipe) [[static_branch]] {
48 view_id = id.view_id<64>();
49 resource_id = id.resource_id<64>();
50 }
51
52 const ViewMatrices view = views.get(view_id);
53 const ObjectMatrices obj = models.get(resource_id);
54
55 if (pipe.is_shadow_pipe) [[static_branch]] {
56 shadow_iface.shadow_view_id = int(view_id);
57 if (pipe.use_multi_viewport) [[static_branch]] {
58 out_viewport = int(shadow.render_view_buf[view_id].viewport_index);
59 }
60 }
61
62 init_interface(interp, id.raw_id);
63
64 interp.P = obj.point_object_to_world(vert_in.pos);
65 interp.N = normalize(obj.normal_object_to_world(vert_in.nor));
66 if (pipe.use_velocity) [[static_branch]] {
67 float3 prv, nxt;
68 geo_vel.local_position_deltas(vert_in.pos, vert_id, prv, nxt, resource_id);
69 /* FIXME(fclem): Evaluating before displacement avoid displacement being treated as motion but
70 * ignores motion from animated displacement. Supporting animated displacement motion vectors
71 * would require evaluating the nodetree multiple time with different nodetree UBOs evaluated
72 * at different times, but also with different attributes (maybe we could assume static
73 * attribute at least). */
74 geo_vel.vertex_velocity(
75 prv, vert_in.pos, nxt, motion.prev, motion.next, resource_id, obj.model);
76 }
77
78 ObjectInfos ob_infos = infos.get(resource_id);
79 /* Compute Original Coordinate (ORCO). */
80 float3 lP_orco = vert_in.pos * ob_infos.orco_mul + ob_infos.orco_add;
81
82 ShadingData sd = init_globals(pipe, uni, interp, view, true, float4(0));
84
85 attrib_load(MeshVertex{vert_in.pos, to_float3x3(obj.model_inverse), lP_orco});
86
87 interp.P += nodetree_displacement(kg, sd);
88
89 if (pipe.use_clip_plane) [[static_branch]] {
90 clip_interp.clip_distance = dot(clip_srt.clip_plane.plane, float4(interp.P, 1.0f));
91 }
92
93 float3 vs_P = view.point_world_to_view(interp.P);
94
95 if (pipe.is_shadow_pipe) [[static_branch]] {
96 ShadowRenderView view = shadow.render_view_buf[view_id];
97 shadow_clip.position = shadow_position_vector_get(vs_P, view);
98 shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
99 }
100
101 out_position = reverse_z::transform(view.point_view_to_homogenous(vs_P));
102}
103
104} // namespace eevee
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 attribute(slot)
#define static_branch
#define vertex_id
#define clip_control
#define condition(cond)
#define vertex
VecBase< float, D > normalize(VecOp< float, D >) RET
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_mesh(KernelGlobals &kg, const PipelineConstants &pipe, const Uniform &uni, const int inst_index, const draw::View &views, const draw::Model &models, const draw::Infos &infos, const draw::Resource &res_id, const GeomShadow &shadow, const ClipPlane &clip_srt, const GeometryVelocity &geo_vel, const GeomMeshVertIn &vert_in, VertOutCommon &interp, VertOutShadow &shadow_iface, VertOutShadowClipping &shadow_clip, VertOutClipPlane &clip_interp, VertOutVelocity &motion, const int vert_id, float4 &out_position, int &out_viewport)
void init_globals_mesh(const VertOutCommon &interp, ShadingData &sd, float3 barycentric_co)
void init_interface(VertOutCommon &interp, uint resource_id_raw)
float4 transform(float4 hs_position)
packed_float3 orco_add
packed_float3 orco_mul
float3 point_object_to_world(float3 lP) const
float3 point_world_to_view(float3 P) const
float4 point_view_to_homogenous(float3 vP) const