Blender V4.3
overlay_particle.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DRW_render.hh"
10
12
13#include "DNA_particle_types.h"
14
15#include "BKE_pointcache.h"
16
17#include "ED_particle.hh"
18
19#include "overlay_private.hh"
20
21/* -------------------------------------------------------------------- */
24
26{
27 OVERLAY_PassList *psl = vedata->psl;
28 OVERLAY_PrivateData *pd = vedata->stl->pd;
29 const DRWContextState *draw_ctx = DRW_context_state_get();
30 ParticleEditSettings *pset = PE_settings(draw_ctx->scene);
31 GPUShader *sh;
32 DRWShadingGroup *grp;
33
36
39
42 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
44 DRW_shgroup_uniform_bool_copy(grp, "useGreasePencil", false);
45 DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.weight_ramp);
46
49 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
50 DRW_shgroup_uniform_bool_copy(grp, "useWeight", false);
51 DRW_shgroup_uniform_bool_copy(grp, "useGreasePencil", false);
52 DRW_shgroup_uniform_bool_copy(grp, "doStrokeEndpoints", false);
53}
54
56{
57 OVERLAY_PrivateData *pd = vedata->stl->pd;
58 const DRWContextState *draw_ctx = DRW_context_state_get();
59 Scene *scene_orig = (Scene *)DEG_get_original_id(&draw_ctx->scene->id);
60
61 /* Usually the edit structure is created by Particle Edit Mode Toggle
62 * operator, but sometimes it's invoked after tagging hair as outdated
63 * (for example, when toggling edit mode). That makes it impossible to
64 * create edit structure for until after next dependency graph evaluation.
65 *
66 * Ideally, the edit structure will be created here already via some
67 * dependency graph callback or so, but currently trying to make it nicer
68 * only causes bad level calls and breaks design from the past.
69 */
70 Object *ob_orig = DEG_get_original_object(ob);
71 PTCacheEdit *edit = PE_create_current(draw_ctx->depsgraph, scene_orig, ob_orig);
72 if (edit == nullptr) {
73 /* Happens when trying to edit particles in EMITTER mode without
74 * having them cached.
75 */
76 return;
77 }
78 /* NOTE: We need to pass evaluated particle system, which we need
79 * to find first.
80 */
81 ParticleSystem *psys = static_cast<ParticleSystem *>(ob->particlesystem.first);
82 LISTBASE_FOREACH (ParticleSystem *, psys_orig, &ob_orig->particlesystem) {
83 if (PE_get_current_from_psys(psys_orig) == edit) {
84 break;
85 }
86 psys = psys->next;
87 }
88 if (psys == nullptr) {
89 printf("Error getting evaluated particle system for edit.\n");
90 return;
91 }
92
93 blender::gpu::Batch *geom;
94 {
97 }
98
100 geom = DRW_cache_particles_get_edit_inner_points(ob, psys, edit);
101 DRW_shgroup_call(pd->edit_particle_point_grp, geom, nullptr);
102 }
103
105 geom = DRW_cache_particles_get_edit_tip_points(ob, psys, edit);
106 DRW_shgroup_call(pd->edit_particle_point_grp, geom, nullptr);
107 }
108}
109
111{
112 OVERLAY_PassList *psl = vedata->psl;
113 OVERLAY_FramebufferList *fbl = vedata->fbl;
114
115 if (DRW_state_is_fbo()) {
117 }
118
120}
121
123
124/* -------------------------------------------------------------------- */
127
129{
130 OVERLAY_PassList *psl = vedata->psl;
131 OVERLAY_PrivateData *pd = vedata->stl->pd;
132 const DRWContextState *draw_ctx = DRW_context_state_get();
133 ParticleEditSettings *pset = PE_settings(draw_ctx->scene);
134 GPUShader *sh;
135 DRWShadingGroup *grp;
136
139
142
145 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
146 DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.ramp);
147
150 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
151 DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.ramp);
152}
153
155{
156 OVERLAY_PrivateData *pd = vedata->stl->pd;
157
160 continue;
161 }
162
163 ParticleSettings *part = psys->part;
164 int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
165
166 if (part->type == PART_HAIR) {
167 /* Hairs should have been rendered by the render engine. */
168 continue;
169 }
170
171 if (!ELEM(draw_as, PART_DRAW_NOT, PART_DRAW_OB, PART_DRAW_GR)) {
172 blender::gpu::Batch *geom = DRW_cache_particles_get_dots(ob, psys);
173 blender::gpu::Batch *shape = nullptr;
174 DRWShadingGroup *grp;
175
176 /* TODO(fclem): Here would be a good place for preemptive culling. */
177
178 /* NOTE(fclem): Is color even useful in our modern context? */
180 float color[4] = {0.6f, 0.6f, 0.6f, part->draw_size};
181 if (ma != nullptr) {
182 copy_v3_v3(color, &ma->r);
183 }
184
185 switch (draw_as) {
186 default:
187 case PART_DRAW_DOT:
189 DRW_shgroup_uniform_vec4_copy(grp, "ucolor", color);
190 DRW_shgroup_call(grp, geom, nullptr);
191 break;
192 case PART_DRAW_AXIS:
193 case PART_DRAW_CIRC:
194 case PART_DRAW_CROSS:
196 DRW_shgroup_uniform_vec4_copy(grp, "ucolor", color);
197 shape = DRW_cache_particles_get_prim(draw_as);
198 DRW_shgroup_call_instances_with_attrs(grp, nullptr, shape, geom);
199 break;
200 }
201 }
202 }
203}
204
206{
207 OVERLAY_PassList *psl = vedata->psl;
208
210}
211
struct Material * BKE_object_material_get_eval(struct Object *ob, short act)
#define LISTBASE_FOREACH(type, var, list)
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define ELEM(...)
ID * DEG_get_original_id(ID *id)
Object * DEG_get_original_object(Object *object)
@ PART_HAIR
@ PART_DRAW_CIRC
@ PART_DRAW_CROSS
@ PART_DRAW_AXIS
@ PART_DRAW_NOT
@ PART_DRAW_GR
@ PART_DRAW_OB
@ PART_DRAW_REND
@ PART_DRAW_DOT
@ PE_BRUSH_WEIGHT
@ SCE_SELECT_POINT
@ SCE_SELECT_END
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
#define DRW_shgroup_call(shgroup, geom, ob)
PTCacheEdit * PE_get_current_from_psys(ParticleSystem *psys)
ParticleEditSettings * PE_settings(Scene *scene)
PTCacheEdit * PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
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
struct GPUShader GPUShader
#define printf
blender::gpu::Batch * DRW_cache_particles_get_prim(int type)
blender::gpu::Batch * DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
blender::gpu::Batch * DRW_cache_particles_get_edit_strands(Object *object, ParticleSystem *psys, PTCacheEdit *edit, bool use_weight)
blender::gpu::Batch * DRW_cache_particles_get_edit_tip_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
blender::gpu::Batch * DRW_cache_particles_get_edit_inner_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
DRW_Global G_draw
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
const DRWContextState * DRW_context_state_get()
bool DRW_state_is_fbo()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
void DRW_shgroup_call_instances_with_attrs(DRWShadingGroup *shgroup, const Object *ob, blender::gpu::Batch *geom, blender::gpu::Batch *inst_attributes)
DRWShadingGroup * DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
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_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
static ulong state[N]
void OVERLAY_particle_draw(OVERLAY_Data *vedata)
void OVERLAY_edit_particle_cache_init(OVERLAY_Data *vedata)
void OVERLAY_particle_cache_init(OVERLAY_Data *vedata)
void OVERLAY_edit_particle_cache_populate(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_particle_cache_populate(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_edit_particle_draw(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_edit_particle_point()
GPUShader * OVERLAY_shader_particle_shape()
GPUShader * OVERLAY_shader_edit_particle_strand()
GPUShader * OVERLAY_shader_particle_dot()
Depsgraph * depsgraph
void * first
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
GPUFrameBuffer * overlay_default_fb
DRWPass * edit_particle_ps
struct OVERLAY_PrivateData::@071226320146267115016374221223052020132003062370 edit_particle
DRWShadingGroup * edit_particle_point_grp
DRWShadingGroup * edit_particle_strand_grp
DRWShadingGroup * particle_dots_grp
DRWShadingGroup * particle_shapes_grp
OVERLAY_PrivateData * pd
ListBase particlesystem
struct ParticleSystem * next