[Bf-blender-cvs] [95b9680597f] blender2.8: Draw manager: Make particle code drawing closer to old viewport

Sergey Sharybin noreply at git.blender.org
Thu Mar 29 12:40:36 CEST 2018


Commit: 95b9680597f53add7c36740d90bad7b283cb27c1
Author: Sergey Sharybin
Date:   Thu Mar 29 12:30:20 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB95b9680597f53add7c36740d90bad7b283cb27c1

Draw manager: Make particle code drawing closer to old viewport

The way how particle state is to be accessed or used did not change
in Blender 2.8, so the drawing code should follow old design.

This code is somewhat duplicated from drawobject.c, but old draw
code is on the way to be removed anyway.

This fixes issue with disappearing particles when tweaking number
of particles.

===================================================================

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/draw/modes/object_mode.c

===================================================================

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 8fdf1a2fce7..301a39d053f 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -2573,9 +2573,9 @@ Gwn_Batch *DRW_cache_particles_get_hair(ParticleSystem *psys, ModifierData *md)
 	return DRW_particles_batch_cache_get_hair(psys, md);
 }
 
-Gwn_Batch *DRW_cache_particles_get_dots(ParticleSystem *psys)
+Gwn_Batch *DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
 {
-	return DRW_particles_batch_cache_get_dots(psys);
+	return DRW_particles_batch_cache_get_dots(object, psys);
 }
 
 Gwn_Batch *DRW_cache_particles_get_prim(int type)
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 60c41ddc798..2ef57884a44 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -165,7 +165,7 @@ struct Gwn_Batch *DRW_cache_lattice_vert_overlay_get(struct Object *ob);
 
 /* Particles */
 struct Gwn_Batch *DRW_cache_particles_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
-struct Gwn_Batch *DRW_cache_particles_get_dots(struct ParticleSystem *psys);
+struct Gwn_Batch *DRW_cache_particles_get_dots(struct Object *object, struct ParticleSystem *psys);
 struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
 
 /* Metaball */
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 0b18f3a257f..83cc87307b5 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -122,6 +122,6 @@ void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
 
 /* Particles */
 struct Gwn_Batch *DRW_particles_batch_cache_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
-struct Gwn_Batch *DRW_particles_batch_cache_get_dots(struct ParticleSystem *psys);
+struct Gwn_Batch *DRW_particles_batch_cache_get_dots(struct Object *object, struct ParticleSystem *psys);
 
 #endif /* __DRAW_CACHE_IMPL_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 97e1a3b3e05..55d528e49b0 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -29,6 +29,8 @@
  * \brief Particle API for render engines
  */
 
+#include "DRW_render.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "BLI_utildefines.h"
@@ -442,7 +444,7 @@ static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, Modifi
 	cache->segments = GWN_indexbuf_build(&elb);
 }
 
-static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchCache *cache)
+static void particle_batch_cache_ensure_pos(Object *object, ParticleSystem *psys, ParticleBatchCache *cache)
 {
 	if (cache->pos != NULL) {
 		return;
@@ -452,6 +454,23 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
 	static unsigned pos_id, rot_id, val_id;
 	int i, curr_point;
 	ParticleData *pa;
+	ParticleKey state;
+	ParticleSimulationData sim = {NULL};
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+
+	sim.eval_ctx = &draw_ctx->eval_ctx;
+	sim.scene = draw_ctx->scene;
+	sim.ob = object;
+	sim.psys = psys;
+	sim.psmd = psys_get_modifier(object, psys);
+
+	if (psys->part->phystype == PART_PHYS_KEYED) {
+		if (psys->flag & PSYS_KEYED) {
+			psys_count_keyed_targets(&sim);
+			if (psys->totkeyed == 0)
+				return;
+		}
+	}
 
 	GWN_VERTBUF_DISCARD_SAFE(cache->pos);
 	GWN_INDEXBUF_DISCARD_SAFE(cache->segments);
@@ -467,30 +486,31 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
 	GWN_vertbuf_data_alloc(cache->pos, psys->totpart);
 
 	for (curr_point = 0, i = 0, pa = psys->particles; i < psys->totpart; i++, pa++) {
-		if (pa->state.time >= pa->time && pa->state.time < pa->dietime &&
-		    !(pa->flag & (PARS_NO_DISP | PARS_UNEXIST)))
-		{
-			float val;
-
-			GWN_vertbuf_attr_set(cache->pos, pos_id, curr_point, pa->state.co);
-			GWN_vertbuf_attr_set(cache->pos, rot_id, curr_point, pa->state.rot);
-
-			switch (psys->part->draw_col) {
-				case PART_DRAW_COL_VEL:
-					val = len_v3(pa->state.vel) / psys->part->color_vec_max;
-					break;
-				case PART_DRAW_COL_ACC:
-					val = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * psys->part->color_vec_max);
-					break;
-				default:
-					val = -1.0f;
-					break;
-			}
-
-			GWN_vertbuf_attr_set(cache->pos, val_id, curr_point, &val);
+		state.time = draw_ctx->eval_ctx.ctime;
+		if (!psys_get_particle_state(&sim, curr_point, &state, 0)) {
+			continue;
+		}
 
-			curr_point++;
+		float val;
+
+		GWN_vertbuf_attr_set(cache->pos, pos_id, curr_point, pa->state.co);
+		GWN_vertbuf_attr_set(cache->pos, rot_id, curr_point, pa->state.rot);
+
+		switch (psys->part->draw_col) {
+			case PART_DRAW_COL_VEL:
+				val = len_v3(pa->state.vel) / psys->part->color_vec_max;
+				break;
+			case PART_DRAW_COL_ACC:
+				val = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * psys->part->color_vec_max);
+				break;
+			default:
+				val = -1.0f;
+				break;
 		}
+
+		GWN_vertbuf_attr_set(cache->pos, val_id, curr_point, &val);
+
+		curr_point++;
 	}
 
 	if (curr_point != psys->totpart) {
@@ -511,12 +531,12 @@ Gwn_Batch *DRW_particles_batch_cache_get_hair(ParticleSystem *psys, ModifierData
 	return cache->hairs;
 }
 
-Gwn_Batch *DRW_particles_batch_cache_get_dots(ParticleSystem *psys)
+Gwn_Batch *DRW_particles_batch_cache_get_dots(Object *object, ParticleSystem *psys)
 {
 	ParticleBatchCache *cache = particle_batch_cache_get(psys);
 
 	if (cache->hairs == NULL) {
-		particle_batch_cache_ensure_pos(psys, cache);
+		particle_batch_cache_ensure_pos(object, psys, cache);
 		cache->hairs = GWN_batch_create(GWN_PRIM_POINTS, cache->pos, NULL);
 	}
 
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 71da4e6dd35..939507a4f21 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -1812,7 +1812,7 @@ static void OBJECT_cache_populate_particles(Object *ob,
 			unit_m4(mat);
 
 			if (draw_as != PART_DRAW_PATH) {
-				struct Gwn_Batch *geom = DRW_cache_particles_get_dots(psys);
+				struct Gwn_Batch *geom = DRW_cache_particles_get_dots(ob, psys);
 				DRWShadingGroup *shgrp = NULL;
 				static int screen_space[2] = {0, 1};
 				static float def_prim_col[3] = {0.5f, 0.5f, 0.5f};



More information about the Bf-blender-cvs mailing list