Blender  V3.3
overlay_particle.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. */
3 
8 #include "DRW_render.h"
9 
10 #include "DEG_depsgraph_query.h"
11 
12 #include "DNA_particle_types.h"
13 
14 #include "BKE_pointcache.h"
15 
16 #include "ED_particle.h"
17 
18 #include "overlay_private.h"
19 
20 /* -------------------------------------------------------------------- */
25 {
26  OVERLAY_PassList *psl = vedata->psl;
27  OVERLAY_PrivateData *pd = vedata->stl->pd;
28  const DRWContextState *draw_ctx = DRW_context_state_get();
29  ParticleEditSettings *pset = PE_settings(draw_ctx->scene);
30  GPUShader *sh;
31  DRWShadingGroup *grp;
32 
35 
38 
41  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
44 
47  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
48 }
49 
51 {
52  OVERLAY_PrivateData *pd = vedata->stl->pd;
53  const DRWContextState *draw_ctx = DRW_context_state_get();
54  Scene *scene_orig = (Scene *)DEG_get_original_id(&draw_ctx->scene->id);
55 
56  /* Usually the edit structure is created by Particle Edit Mode Toggle
57  * operator, but sometimes it's invoked after tagging hair as outdated
58  * (for example, when toggling edit mode). That makes it impossible to
59  * create edit structure for until after next dependency graph evaluation.
60  *
61  * Ideally, the edit structure will be created here already via some
62  * dependency graph callback or so, but currently trying to make it nicer
63  * only causes bad level calls and breaks design from the past.
64  */
65  Object *ob_orig = DEG_get_original_object(ob);
66  PTCacheEdit *edit = PE_create_current(draw_ctx->depsgraph, scene_orig, ob_orig);
67  if (edit == NULL) {
68  /* Happens when trying to edit particles in EMITTER mode without
69  * having them cached.
70  */
71  return;
72  }
73  /* NOTE: We need to pass evaluated particle system, which we need
74  * to find first.
75  */
77  LISTBASE_FOREACH (ParticleSystem *, psys_orig, &ob_orig->particlesystem) {
78  if (PE_get_current_from_psys(psys_orig) == edit) {
79  break;
80  }
81  psys = psys->next;
82  }
83  if (psys == NULL) {
84  printf("Error getting evaluated particle system for edit.\n");
85  return;
86  }
87 
88  struct GPUBatch *geom;
89  {
92  }
93 
95  geom = DRW_cache_particles_get_edit_inner_points(ob, psys, edit);
97  }
98 
100  geom = DRW_cache_particles_get_edit_tip_points(ob, psys, edit);
102  }
103 }
104 
106 {
107  OVERLAY_PassList *psl = vedata->psl;
108  OVERLAY_FramebufferList *fbl = vedata->fbl;
109 
110  if (DRW_state_is_fbo()) {
112  }
113 
115 }
116 
119 /* -------------------------------------------------------------------- */
124 {
125  OVERLAY_PassList *psl = vedata->psl;
126  OVERLAY_PrivateData *pd = vedata->stl->pd;
127  const DRWContextState *draw_ctx = DRW_context_state_get();
128  ParticleEditSettings *pset = PE_settings(draw_ctx->scene);
129  GPUShader *sh;
130  DRWShadingGroup *grp;
131 
134 
137 
140  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
141  DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.ramp);
142 
145  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
146  DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.ramp);
147 }
148 
150 {
151  OVERLAY_PrivateData *pd = vedata->stl->pd;
152 
155  continue;
156  }
157 
158  ParticleSettings *part = psys->part;
159  int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
160 
161  if (part->type == PART_HAIR) {
162  /* Hairs should have been rendered by the render engine. */
163  continue;
164  }
165 
166  if (!ELEM(draw_as, PART_DRAW_NOT, PART_DRAW_OB, PART_DRAW_GR)) {
167  struct GPUBatch *geom = DRW_cache_particles_get_dots(ob, psys);
168  struct GPUBatch *shape = NULL;
169  DRWShadingGroup *grp;
170 
171  /* TODO(fclem): Here would be a good place for preemptive culling. */
172 
173  /* NOTE(fclem): Is color even useful in our modern context? */
174  Material *ma = BKE_object_material_get_eval(ob, part->omat);
175  float color[4] = {0.6f, 0.6f, 0.6f, part->draw_size};
176  if (ma != NULL) {
177  copy_v3_v3(color, &ma->r);
178  }
179 
180  switch (draw_as) {
181  default:
182  case PART_DRAW_DOT:
184  DRW_shgroup_uniform_vec4_copy(grp, "color", color);
185  DRW_shgroup_call(grp, geom, NULL);
186  break;
187  case PART_DRAW_AXIS:
188  case PART_DRAW_CIRC:
189  case PART_DRAW_CROSS:
191  DRW_shgroup_uniform_vec4_copy(grp, "color", color);
192  shape = DRW_cache_particles_get_prim(draw_as);
193  DRW_shgroup_call_instances_with_attrs(grp, NULL, shape, geom);
194  break;
195  }
196  }
197  }
198 }
199 
201 {
202  OVERLAY_PassList *psl = vedata->psl;
203 
205 }
206 
struct Material * BKE_object_material_get_eval(struct Object *ob, short act)
Definition: material.c:707
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define ELEM(...)
struct Object * DEG_get_original_object(struct Object *object)
struct ID * DEG_get_original_id(struct ID *id)
#define PART_DRAW_DOT
#define PART_DRAW_OB
#define PART_DRAW_REND
#define PART_DRAW_NOT
#define PART_DRAW_AXIS
@ PART_HAIR
#define PART_DRAW_CROSS
#define PART_DRAW_GR
#define PART_DRAW_CIRC
#define SCE_SELECT_END
#define SCE_SELECT_POINT
#define PE_BRUSH_WEIGHT
DRWState
Definition: DRW_render.h:298
@ DRW_STATE_WRITE_DEPTH
Definition: DRW_render.h:302
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition: DRW_render.h:311
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:690
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
Definition: DRW_render.h:651
#define DRW_shgroup_call(shgroup, geom, ob)
Definition: DRW_render.h:414
struct PTCacheEdit * PE_get_current_from_psys(struct ParticleSystem *psys)
struct ParticleEditSettings * PE_settings(struct Scene *scene)
struct PTCacheEdit * PE_create_current(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
GPUBatch
Definition: GPU_batch.h:78
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUShader GPUShader
Definition: GPU_shader.h:20
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 a color
GPUBatch * DRW_cache_particles_get_edit_inner_points(Object *object, ParticleSystem *psys, struct PTCacheEdit *edit)
Definition: draw_cache.c:3111
GPUBatch * DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
Definition: draw_cache.c:3098
GPUBatch * DRW_cache_particles_get_prim(int type)
Definition: draw_cache.c:3125
GPUBatch * DRW_cache_particles_get_edit_tip_points(Object *object, ParticleSystem *psys, struct PTCacheEdit *edit)
Definition: draw_cache.c:3118
GPUBatch * DRW_cache_particles_get_edit_strands(Object *object, ParticleSystem *psys, struct PTCacheEdit *edit, bool use_weight)
Definition: draw_cache.c:3103
struct DRW_Global G_draw
Definition: draw_common.c:32
bool DRW_state_is_fbo(void)
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
Definition: draw_manager.c:234
const DRWContextState * DRW_context_state_get(void)
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
void DRW_shgroup_call_instances_with_attrs(DRWShadingGroup *shgroup, Object *ob, struct GPUBatch *geom, struct GPUBatch *inst_attributes)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
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)
const int state
ccl_gpu_kernel_postfix ccl_global float int int int int sh
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_particle_dot(void)
GPUShader * OVERLAY_shader_particle_shape(void)
GPUShader * OVERLAY_shader_edit_particle_strand(void)
GPUShader * OVERLAY_shader_edit_particle_point(void)
struct Scene * scene
Definition: DRW_render.h:979
struct Depsgraph * depsgraph
Definition: DRW_render.h:987
struct GPUUniformBuf * block_ubo
Definition: draw_common.h:129
struct GPUTexture * weight_ramp
Definition: draw_common.h:132
struct GPUTexture * ramp
Definition: draw_common.h:131
void * first
Definition: DNA_listBase.h:31
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
struct GPUFrameBuffer * overlay_default_fb
DRWPass * edit_particle_ps
DRWShadingGroup * edit_particle_point_grp
DRWShadingGroup * edit_particle_strand_grp
struct OVERLAY_PrivateData::@254 edit_particle
DRWShadingGroup * particle_dots_grp
DRWShadingGroup * particle_shapes_grp
struct OVERLAY_PrivateData * pd
ListBase particlesystem
struct ParticleSystem * next