Blender  V2.93
overlay_particle.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2019, Blender Foundation.
17  */
18 
23 #include "DRW_render.h"
24 
25 #include "DEG_depsgraph_query.h"
26 
27 #include "DNA_particle_types.h"
28 
29 #include "BKE_pointcache.h"
30 
31 #include "ED_particle.h"
32 
33 #include "overlay_private.h"
34 
35 /* -------------------------------------------------------------------- */
40 {
41  OVERLAY_PassList *psl = vedata->psl;
42  OVERLAY_PrivateData *pd = vedata->stl->pd;
43  const DRWContextState *draw_ctx = DRW_context_state_get();
44  ParticleEditSettings *pset = PE_settings(draw_ctx->scene);
45  GPUShader *sh;
46  DRWShadingGroup *grp;
47 
50 
53 
56  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
59 
62  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
63 }
64 
66 {
67  OVERLAY_PrivateData *pd = vedata->stl->pd;
68  const DRWContextState *draw_ctx = DRW_context_state_get();
69  Scene *scene_orig = (Scene *)DEG_get_original_id(&draw_ctx->scene->id);
70 
71  /* Usually the edit structure is created by Particle Edit Mode Toggle
72  * operator, but sometimes it's invoked after tagging hair as outdated
73  * (for example, when toggling edit mode). That makes it impossible to
74  * create edit structure for until after next dependency graph evaluation.
75  *
76  * Ideally, the edit structure will be created here already via some
77  * dependency graph callback or so, but currently trying to make it nicer
78  * only causes bad level calls and breaks design from the past.
79  */
80  Object *ob_orig = DEG_get_original_object(ob);
81  PTCacheEdit *edit = PE_create_current(draw_ctx->depsgraph, scene_orig, ob_orig);
82  if (edit == NULL) {
83  /* Happens when trying to edit particles in EMITTER mode without
84  * having them cached.
85  */
86  return;
87  }
88  /* NOTE: We need to pass evaluated particle system, which we need
89  * to find first.
90  */
92  LISTBASE_FOREACH (ParticleSystem *, psys_orig, &ob_orig->particlesystem) {
93  if (PE_get_current_from_psys(psys_orig) == edit) {
94  break;
95  }
96  psys = psys->next;
97  }
98  if (psys == NULL) {
99  printf("Error getting evaluated particle system for edit.\n");
100  return;
101  }
102 
103  struct GPUBatch *geom;
104  {
107  }
108 
110  geom = DRW_cache_particles_get_edit_inner_points(ob, psys, edit);
112  }
113 
115  geom = DRW_cache_particles_get_edit_tip_points(ob, psys, edit);
117  }
118 }
119 
121 {
122  OVERLAY_PassList *psl = vedata->psl;
123  OVERLAY_FramebufferList *fbl = vedata->fbl;
124 
125  if (DRW_state_is_fbo()) {
127  }
128 
130 }
131 
134 /* -------------------------------------------------------------------- */
139 {
140  OVERLAY_PassList *psl = vedata->psl;
141  OVERLAY_PrivateData *pd = vedata->stl->pd;
142  const DRWContextState *draw_ctx = DRW_context_state_get();
143  ParticleEditSettings *pset = PE_settings(draw_ctx->scene);
144  GPUShader *sh;
145  DRWShadingGroup *grp;
146 
149 
152 
154  pd->particle_dots_grp = grp = DRW_shgroup_create(sh, psl->particle_ps);
155  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
156  DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.ramp);
157 
159  pd->particle_shapes_grp = grp = DRW_shgroup_create(sh, psl->particle_ps);
160  DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
161  DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.ramp);
162 }
163 
165 {
166  OVERLAY_PrivateData *pd = vedata->stl->pd;
167 
170  continue;
171  }
172 
173  ParticleSettings *part = psys->part;
174  int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
175 
176  if (part->type == PART_HAIR) {
177  /* Hairs should have been rendered by the render engine.*/
178  continue;
179  }
180 
181  if (!ELEM(draw_as, PART_DRAW_NOT, PART_DRAW_OB, PART_DRAW_GR)) {
182  struct GPUBatch *geom = DRW_cache_particles_get_dots(ob, psys);
183  struct GPUBatch *shape = NULL;
184  DRWShadingGroup *grp;
185 
186  /* TODO(fclem): Here would be a good place for preemptive culling. */
187 
188  /* NOTE(fclem): Is color even useful in our modern context? */
189  Material *ma = BKE_object_material_get(ob, part->omat);
190  float color[4] = {0.6f, 0.6f, 0.6f, part->draw_size};
191  if (ma != NULL) {
192  copy_v3_v3(color, &ma->r);
193  }
194 
195  switch (draw_as) {
196  default:
197  case PART_DRAW_DOT:
199  DRW_shgroup_uniform_vec4_copy(grp, "color", color);
200  DRW_shgroup_call(grp, geom, NULL);
201  break;
202  case PART_DRAW_AXIS:
203  case PART_DRAW_CIRC:
204  case PART_DRAW_CROSS:
206  DRW_shgroup_uniform_vec4_copy(grp, "color", color);
207  shape = DRW_cache_particles_get_prim(draw_as);
208  DRW_shgroup_call_instances_with_attrs(grp, NULL, shape, geom);
209  break;
210  }
211  }
212  }
213 }
214 
216 {
217  OVERLAY_PassList *psl = vedata->psl;
218 
220 }
221 
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:697
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
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
#define PART_DRAW_CROSS
#define PART_DRAW_GR
#define PART_DRAW_CIRC
@ PART_HAIR
#define SCE_SELECT_END
#define SCE_SELECT_POINT
#define PE_BRUSH_WEIGHT
DRWState
Definition: DRW_render.h:312
@ DRW_STATE_WRITE_DEPTH
Definition: DRW_render.h:314
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:315
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition: DRW_render.h:323
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:593
#define DRW_shgroup_call(shgroup, geom, ob)
Definition: DRW_render.h:420
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:93
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUShader GPUShader
Definition: GPU_shader.h:33
GPUBatch * DRW_cache_particles_get_edit_inner_points(Object *object, ParticleSystem *psys, struct PTCacheEdit *edit)
Definition: draw_cache.c:3350
GPUBatch * DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
Definition: draw_cache.c:3337
GPUBatch * DRW_cache_particles_get_prim(int type)
Definition: draw_cache.c:3364
GPUBatch * DRW_cache_particles_get_edit_tip_points(Object *object, ParticleSystem *psys, struct PTCacheEdit *edit)
Definition: draw_cache.c:3357
GPUBatch * DRW_cache_particles_get_edit_strands(Object *object, ParticleSystem *psys, struct PTCacheEdit *edit, bool use_weight)
Definition: draw_cache.c:3342
struct DRW_Global G_draw
Definition: draw_common.c:45
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:271
const DRWContextState * DRW_context_state_get(void)
void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const GPUUniformBuf *ubo)
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)
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_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:745
struct Depsgraph * depsgraph
Definition: DRW_render.h:753
struct GPUUniformBuf * block_ubo
Definition: draw_common.h:210
struct GPUTexture * weight_ramp
Definition: draw_common.h:213
struct GPUTexture * ramp
Definition: draw_common.h:212
void * first
Definition: DNA_listBase.h:47
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
struct GPUFrameBuffer * overlay_default_fb
DRWPass * edit_particle_ps
struct OVERLAY_PrivateData::@243 edit_particle
DRWShadingGroup * edit_particle_point_grp
DRWShadingGroup * edit_particle_strand_grp
DRWShadingGroup * particle_dots_grp
DRWShadingGroup * particle_shapes_grp
struct OVERLAY_PrivateData * pd
ListBase particlesystem
struct ParticleSystem * next