Blender V4.3
overlay_viewer_attribute.cc
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#include "DRW_render.hh"
10
11#include "DNA_mesh_types.h"
13
14#include "BLI_math_vector.hh"
15#include "BLI_span.hh"
16
17#include "GPU_batch.hh"
18
19#include "BKE_attribute.hh"
20#include "BKE_curves.hh"
21#include "BKE_customdata.hh"
22#include "BKE_duplilist.hh"
23#include "BKE_geometry_set.hh"
24
25#include "draw_cache_extract.hh"
26#include "draw_cache_impl.hh"
27#include "overlay_private.hh"
28
52
55 const DupliObject &dupli_object,
56 const float opacity)
57{
58 using namespace blender;
59 using namespace blender::bke;
60 using namespace blender::draw;
61
62 const GeometrySet &base_geometry = *dupli_object.preview_base_geometry;
63 const InstancesComponent &instances = *base_geometry.get_component<InstancesComponent>();
64 const AttributeAccessor instance_attributes = *instances.attributes();
65 const VArray attribute = *instance_attributes.lookup<ColorGeometry4f>(".viewer");
66 if (!attribute) {
67 return;
68 }
70 color.a *= opacity;
71 switch (object.type) {
72 case OB_MESH: {
73 {
75 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
76 blender::gpu::Batch *batch = DRW_cache_mesh_surface_get(&object);
77 DRW_shgroup_call(sub_grp, batch, &object);
78 }
79 if (blender::gpu::Batch *batch = DRW_cache_mesh_loose_edges_get(&object)) {
81 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
82 DRW_shgroup_call(sub_grp, batch, &object);
83 }
84 break;
85 }
86 case OB_POINTCLOUD: {
88 &object, pd.viewer_attribute_pointcloud_grp, nullptr);
89 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
90 break;
91 }
92 case OB_CURVES_LEGACY: {
94 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
95 blender::gpu::Batch *batch = DRW_cache_curve_edge_wire_get(&object);
96 DRW_shgroup_call_obmat(sub_grp, batch, object.object_to_world().ptr());
97 break;
98 }
99 case OB_CURVES: {
100 /* Not supported yet because instances of this type are currently drawn as legacy curves.
101 */
102 break;
103 }
104 }
105}
106
112
115 const float opacity)
116{
117 using namespace blender;
118 using namespace blender::bke;
119 using namespace blender::draw;
120
121 switch (object.type) {
122 case OB_MESH: {
123 Mesh *mesh = static_cast<Mesh *>(object.data);
124 if (const std::optional<bke::AttributeMetaData> meta_data =
125 mesh->attributes().lookup_meta_data(".viewer"))
126 {
127 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
128 blender::gpu::Batch *batch = DRW_cache_mesh_surface_viewer_attribute_get(&object);
131 }
132 }
133 break;
134 }
135 case OB_POINTCLOUD: {
136 PointCloud *pointcloud = static_cast<PointCloud *>(object.data);
137 if (const std::optional<bke::AttributeMetaData> meta_data =
138 pointcloud->attributes().lookup_meta_data(".viewer"))
139 {
140 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
141 gpu::VertBuf **vertbuf = DRW_pointcloud_evaluated_attribute(pointcloud, ".viewer");
143 &object, pd.viewer_attribute_pointcloud_grp, nullptr);
144 DRW_shgroup_uniform_float_copy(grp, "opacity", opacity);
145 DRW_shgroup_buffer_texture_ref(grp, "attribute_tx", vertbuf);
146 }
147 }
148 break;
149 }
150 case OB_CURVES_LEGACY: {
151 Curve *curve = static_cast<Curve *>(object.data);
152 if (curve->curve_eval) {
153 const bke::CurvesGeometry &curves = curve->curve_eval->geometry.wrap();
154 if (const std::optional<bke::AttributeMetaData> meta_data =
155 curves.attributes().lookup_meta_data(".viewer"))
156 {
157 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
158 blender::gpu::Batch *batch = DRW_cache_curve_edge_wire_viewer_attribute_get(&object);
161 pd.viewer_attribute_curve_grp, batch, object.object_to_world().ptr());
162 }
163 }
164 }
165 break;
166 }
167 case OB_CURVES: {
168 Curves *curves_id = static_cast<Curves *>(object.data);
169 const bke::CurvesGeometry &curves = curves_id->geometry.wrap();
170 if (const std::optional<bke::AttributeMetaData> meta_data =
171 curves.attributes().lookup_meta_data(".viewer"))
172 {
173 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
174 bool is_point_domain;
176 curves_id, ".viewer", &is_point_domain);
178 &object, pd.viewer_attribute_curves_grp, nullptr);
180 DRW_shgroup_uniform_bool_copy(grp, "is_point_domain", is_point_domain);
181 DRW_shgroup_buffer_texture(grp, "color_tx", *texture);
182 }
183 }
184 break;
185 }
186 }
187}
188
190{
191 OVERLAY_PrivateData *pd = vedata->stl->pd;
192 const float opacity = vedata->stl->pd->overlay.viewer_attribute_opacity;
193 DupliObject *dupli_object = DRW_object_get_dupli(object);
194
195 if (dupli_object->preview_instance_index >= 0) {
196 const auto &instances =
198 if (const std::optional<blender::bke::AttributeMetaData> meta_data =
199 instances.attributes()->lookup_meta_data(".viewer"))
200 {
201 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
202 populate_cache_for_instance(*object, *pd, *dupli_object, opacity);
203 return;
204 }
205 }
206 }
207 populate_cache_for_geometry(*object, *pd, opacity);
208}
209
211{
212 OVERLAY_PassList *psl = vedata->psl;
214}
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
#define CD_TYPE_AS_MASK(_type)
#define CD_MASK_PROP_ALL
#define CD_MASK_PROP_QUATERNION
#define CD_MASK_PROP_FLOAT4X4
@ OB_MESH
@ OB_POINTCLOUD
@ OB_CURVES_LEGACY
@ OB_CURVES
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_call_obmat(shgroup, geom, obmat)
#define DRW_shgroup_call(shgroup, geom, ob)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color attribute
struct GPUShader GPUShader
AttributeSet attributes
std::optional< AttributeAccessor > attributes() const final
local_group_size(16, 16) .push_constant(Type texture
blender::gpu::Batch * DRW_cache_curve_edge_wire_viewer_attribute_get(Object *ob)
blender::gpu::Batch * DRW_cache_curve_edge_wire_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_surface_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_loose_edges_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_surface_viewer_attribute_get(Object *ob)
DupliObject * DRW_object_get_dupli(const Object *)
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
void DRW_shgroup_buffer_texture(DRWShadingGroup *shgroup, const char *name, blender::gpu::VertBuf *vertex_buffer)
DRWShadingGroup * DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
void DRW_shgroup_buffer_texture_ref(DRWShadingGroup *shgroup, const char *name, blender::gpu::VertBuf **vertex_buffer)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
void DRW_draw_pass(DRWPass *pass)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
struct @157336070235062372277311340362362342103123126032::@262166344314164341202215145112231240022370055142 batch
static ulong state[N]
gpu::VertBuf ** DRW_curves_texture_for_evaluated_attribute(Curves *curves, const char *name, bool *r_is_point_domain)
DRWShadingGroup * DRW_shgroup_curves_create_sub(Object *object, DRWShadingGroup *shgrp, GPUMaterial *gpu_material)
DRWShadingGroup * DRW_shgroup_pointcloud_create_sub(Object *object, DRWShadingGroup *shgrp_parent, GPUMaterial *gpu_material)
gpu::VertBuf ** DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const char *name)
GPUShader * OVERLAY_shader_uniform_color()
GPUShader * OVERLAY_shader_uniform_color_pointcloud()
GPUShader * OVERLAY_shader_viewer_attribute_curve()
GPUShader * OVERLAY_shader_viewer_attribute_pointcloud()
GPUShader * OVERLAY_shader_viewer_attribute_curves()
GPUShader * OVERLAY_shader_viewer_attribute_mesh()
static bool attribute_type_supports_viewer_overlay(const eCustomDataType data_type)
static void populate_cache_for_geometry(Object &object, OVERLAY_PrivateData &pd, const float opacity)
void OVERLAY_viewer_attribute_draw(OVERLAY_Data *vedata)
void OVERLAY_viewer_attribute_cache_populate(OVERLAY_Data *vedata, Object *object)
static void populate_cache_for_instance(Object &object, OVERLAY_PrivateData &pd, const DupliObject &dupli_object, const float opacity)
void OVERLAY_viewer_attribute_cache_init(OVERLAY_Data *vedata)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
Definition BLI_color.hh:337
const struct Curves * curve_eval
CurvesGeometry geometry
const blender::bke::GeometrySet * preview_base_geometry
int preview_instance_index
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
DRWShadingGroup * viewer_attribute_instance_grp
DRWShadingGroup * viewer_attribute_pointcloud_grp
DRWShadingGroup * viewer_attribute_curve_grp
DRWShadingGroup * viewer_attribute_instance_pointcloud_grp
DRWShadingGroup * viewer_attribute_mesh_grp
DRWShadingGroup * viewer_attribute_curves_grp
OVERLAY_PrivateData * pd
float viewer_attribute_opacity
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
PointerRNA * ptr
Definition wm_files.cc:4126