[Bf-blender-cvs] [49fc1d0f540] blender2.8: Draw manager: Initial implementation of particle edit mode

Sergey Sharybin noreply at git.blender.org
Wed May 9 10:35:19 CEST 2018


Commit: 49fc1d0f54010b19c7c2ae5f7692fac62c617e5a
Author: Sergey Sharybin
Date:   Tue May 8 17:11:42 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB49fc1d0f54010b19c7c2ae5f7692fac62c617e5a

Draw manager: Initial implementation of particle edit mode

Gets edit more from the current object and displays it as a path.
this is how both hair and particle edit modes are supposed to work.

This only covers path itself, it doesn't do anything like keys
visualization or selection. However, it's already possible to
comb and such.

Only implements particle mode. There are also some settings to
do soft body and cloth. No idea yet what that all is about.

Copy-on-write is not supported either, this is due to some
edit mode ownership problems which are to be addressed from
dependency graph side.

Shading is dead-simple: uses tangent as a color. This is where
i hope to get some help from Clément.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/modes/particle_mode.c
A	source/blender/draw/modes/shaders/particle_strand_frag.glsl
A	source/blender/draw/modes/shaders/particle_vert.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 71285d7ba04..2207dfe5c34 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -277,6 +277,8 @@ data_to_c_simple(modes/shaders/paint_vertex_vert.glsl SRC)
 data_to_c_simple(modes/shaders/paint_wire_frag.glsl SRC)
 data_to_c_simple(modes/shaders/paint_wire_vert.glsl SRC)
 data_to_c_simple(modes/shaders/paint_vert_frag.glsl SRC)
+data_to_c_simple(modes/shaders/particle_strand_frag.glsl SRC)
+data_to_c_simple(modes/shaders/particle_vert.glsl SRC)
 
 list(APPEND INC
 )
diff --git a/source/blender/draw/modes/particle_mode.c b/source/blender/draw/modes/particle_mode.c
index f022a68aa8a..25143afff14 100644
--- a/source/blender/draw/modes/particle_mode.c
+++ b/source/blender/draw/modes/particle_mode.c
@@ -26,53 +26,49 @@
 #include "DRW_engine.h"
 #include "DRW_render.h"
 
-/* If builtin shaders are needed */
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+
+#include "BKE_particle.h"
+#include "BKE_pointcache.h"
+
 #include "GPU_shader.h"
+#include "GPU_batch.h"
 
 #include "draw_common.h"
 
 #include "draw_mode_engines.h"
 
+#include "ED_particle.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "draw_cache_impl.h"
+
+extern char datatoc_particle_vert_glsl[];
+extern char datatoc_particle_strand_frag_glsl[];
+
 /* *********** LISTS *********** */
-/* All lists are per viewport specific datas.
- * They are all free when viewport changes engines
- * or is free itself. Use PARTICLE_engine_init() to
- * initialize most of them and PARTICLE_cache_init()
- * for PARTICLE_PassList */
 
 typedef struct PARTICLE_PassList {
-	/* Declare all passes here and init them in
-	 * PARTICLE_cache_init().
-	 * Only contains (DRWPass *) */
-	struct DRWPass *pass;
+	struct DRWPass *hair_pass;
 } PARTICLE_PassList;
 
 typedef struct PARTICLE_FramebufferList {
-	/* Contains all framebuffer objects needed by this engine.
-	 * Only contains (GPUFrameBuffer *) */
 	struct GPUFrameBuffer *fb;
 } PARTICLE_FramebufferList;
 
 typedef struct PARTICLE_TextureList {
-	/* Contains all framebuffer textures / utility textures
-	 * needed by this engine. Only viewport specific textures
-	 * (not per object). Only contains (GPUTexture *) */
 	struct GPUTexture *texture;
 } PARTICLE_TextureList;
 
 typedef struct PARTICLE_StorageList {
-	/* Contains any other memory block that the engine needs.
-	 * Only directly MEM_(m/c)allocN'ed blocks because they are
-	 * free with MEM_freeN() when viewport is freed.
-	 * (not per object) */
 	struct CustomStruct *block;
 	struct PARTICLE_PrivateData *g_data;
 } PARTICLE_StorageList;
 
 typedef struct PARTICLE_Data {
-	/* Struct returned by DRW_viewport_engine_data_ensure.
-	 * If you don't use one of these, just make it a (void *) */
-	// void *fbl;
 	void *engine_type; /* Required */
 	PARTICLE_FramebufferList *fbl;
 	PARTICLE_TextureList *txl;
@@ -83,55 +79,27 @@ typedef struct PARTICLE_Data {
 /* *********** STATIC *********** */
 
 static struct {
-	/* Custom shaders :
-	 * Add sources to source/blender/draw/modes/shaders
-	 * init in PARTICLE_engine_init();
-	 * free in PARTICLE_engine_free(); */
-	struct GPUShader *custom_shader;
+	struct GPUShader *hair_shader;
 } e_data = {NULL}; /* Engine data */
 
 typedef struct PARTICLE_PrivateData {
-	/* This keeps the references of the shading groups for
-	 * easy access in PARTICLE_cache_populate() */
-	DRWShadingGroup *group;
+	DRWShadingGroup *hair_group;
 } PARTICLE_PrivateData; /* Transient data */
 
 /* *********** FUNCTIONS *********** */
 
-/* Init Textures, Framebuffers, Storage and Shaders.
- * It is called for every frames.
- * (Optional) */
-static void PARTICLE_engine_init(void *vedata)
+static void particle_engine_init(void *UNUSED(vedata))
 {
-	PARTICLE_TextureList *txl = ((PARTICLE_Data *)vedata)->txl;
-	PARTICLE_FramebufferList *fbl = ((PARTICLE_Data *)vedata)->fbl;
-	PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
-
-	UNUSED_VARS(txl, fbl, stl);
-
-	/* Init Framebuffers like this: order is attachment order (for color texs) */
-	/*
-	 * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
-	 *                         {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
-	 */
-
-	/* DRW_framebuffer_init takes care of checking if
-	 * the framebuffer is valid and has the right size*/
-	/*
-	 * float *viewport_size = DRW_viewport_size_get();
-	 * DRW_framebuffer_init(&fbl->occlude_wire_fb,
-	 *                     (int)viewport_size[0], (int)viewport_size[1],
-	 *                     tex, 2);
-	 */
-
-	if (!e_data.custom_shader) {
-		e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+	if (!e_data.hair_shader) {
+		e_data.hair_shader = DRW_shader_create(
+		        datatoc_particle_vert_glsl,
+		        NULL,
+		        datatoc_particle_strand_frag_glsl,
+		        "#define MAX_MATERIAL 1\n" );
 	}
 }
 
-/* Here init all passes and shading groups
- * Assume that all Passes are NULL */
-static void PARTICLE_cache_init(void *vedata)
+static void particle_cache_init(void *vedata)
 {
 	PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
 	PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
@@ -141,125 +109,69 @@ static void PARTICLE_cache_init(void *vedata)
 		stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
 	}
 
-	{
-		/* Create a pass */
-		DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE;
-		psl->pass = DRW_pass_create("My Pass", state);
-
-		/* Create a shadingGroup using a function in draw_common.c or custom one */
-		/*
-		 * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
-		 * -- or --
-		 * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
-		 */
-		stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
-
-		/* Uniforms need a pointer to it's value so be sure it's accessible at
-		 * any given time (i.e. use static vars) */
-		static float color[4] = {0.2f, 0.5f, 0.3f, 1.0};
-		DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1);
-	}
+	/* Create a pass */
+	psl->hair_pass = DRW_pass_create("Hair Pass", (DRW_STATE_WRITE_COLOR |
+	                                               DRW_STATE_WRITE_DEPTH |
+	                                               DRW_STATE_DEPTH_LESS |
+	                                               DRW_STATE_WIRE));
 
+	stl->g_data->hair_group = DRW_shgroup_create(e_data.hair_shader,
+	                                             psl->hair_pass);
 }
 
-/* Add geometry to shadingGroups. Execute for each objects */
-static void PARTICLE_cache_populate(void *vedata, Object *ob)
+static void particle_cache_populate(void *vedata, Object *object)
 {
-	PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
 	PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
-
-	UNUSED_VARS(psl, stl);
-
-	if (ob->type == OB_MESH) {
-		/* Get geometry cache */
-		struct Gwn_Batch *geom = DRW_cache_mesh_surface_get(ob);
-
-		/* Add geom to a shading group */
-		DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat);
+	for (ParticleSystem *psys = object->particlesystem.first;
+	     psys != NULL;
+	     psys = psys->next)
+	{
+		if (!psys_check_enabled(object, psys, false)) {
+			continue;
+		}
+		if (PE_get_current_from_psys(psys) == NULL) {
+			continue;
+		}
+		/* NOTE: Particle edit mode visualizes particles as strands. */
+		struct Gwn_Batch *hair = DRW_cache_particles_get_hair(psys, NULL);
+		DRW_shgroup_call_add(stl->g_data->hair_group, hair, NULL);
+		break;
 	}
 }
 
 /* Optional: Post-cache_populate callback */
-static void PARTICLE_cache_finish(void *vedata)
+static void particle_cache_finish(void *UNUSED(vedata))
 {
-	PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
-	PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
-
-	/* Do something here! dependant on the objects gathered */
-	UNUSED_VARS(psl, stl);
 }
 
 /* Draw time ! Control rendering pipeline from here */
-static void PARTICLE_draw_scene(void *vedata)
+static void particle_draw_scene(void *vedata)
 {
 
 	PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
-	PARTICLE_FramebufferList *fbl = ((PARTICLE_Data *)vedata)->fbl;
-
-	/* Default framebuffer and texture */
-	DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
-	DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
-
-	UNUSED_VARS(fbl, dfbl, dtxl, psl);
-
-	/* Show / hide entire passes, swap framebuffers ... whatever you fancy */
-	/*
-	 * DRW_framebuffer_texture_detach(dtxl->depth);
-	 * DRW_framebuffer_bind(fbl->custom_fb);
-	 * DRW_draw_pass(psl->pass);
-	 * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
-	 * DRW_framebuffer_bind(dfbl->default_fb);
-	 */
 
-	/* ... or just render passes on default framebuffer. */
-	//DRW_draw_pass(psl->pass);
-
-	/* If you changed framebuffer, double check you rebind
-	 * the default one with its textures attached before finishing */
-}
-
-/* Cleanup when destroying the engine.
- * This is not per viewport ! only when quitting blender.
- * Mostly used for freeing shaders */
-static void PARTICLE_engine_free(void)
-{
-	// DRW_SHADER_FREE_SAFE(custom_shader);
+	DRW_draw_pass(psl->hair_pass);
 }
 
-/* Create collection settings here.
- *
- * Be sure to add this function there :
- * source/blender/draw/DRW_engine.h
- * source/blender/blenkernel/intern/layer.c
- * source/blenderplayer/bad_level_call_stubs/stubs.c
- *
- * And relevant collection settings to :
- * source/blender/makesrna/intern/rna_scene.c
- * source/blender/blenkernel/intern/layer.c
- */
-#if 0
-void PARTICLE_collection_settings_create(CollectionEngineSettings *ces)
+static void particle_engine_free(void)
 {
-	BLI_assert(ces);
-	// BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
-	// BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
-	// BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+	DRW_SHADER_FREE_SAFE(e_data.hair_shader);
 }
-#endif
 
-static const DrawEngineDataSize PARTICLE_data_size = DRW_VIEWPORT_DATA_SIZE(PARTICLE_Data);
+static cons

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list