[Bf-blender-cvs] [0eb32ab2280] blender2.8: Implement hair drawing with Draw Manager in Clay engine

Luca Rood noreply at git.blender.org
Fri May 12 16:15:00 CEST 2017


Commit: 0eb32ab22809d9c0c41bfff5082f58b1a7aa9965
Author: Luca Rood
Date:   Tue May 9 16:23:47 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB0eb32ab22809d9c0c41bfff5082f58b1a7aa9965

Implement hair drawing with Draw Manager in Clay engine

Part of T51378

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

M	release/scripts/startup/bl_ui/properties_collection.py
M	release/scripts/startup/bl_ui/properties_render.py
M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/clay/clay_engine.c
A	source/blender/draw/engines/clay/shaders/particle_strand_frag.glsl
A	source/blender/draw/engines/clay/shaders/particle_vert.glsl
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
A	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/makesdna/DNA_particle_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_collection.py b/release/scripts/startup/bl_ui/properties_collection.py
index dc02037586c..4e545778162 100644
--- a/release/scripts/startup/bl_ui/properties_collection.py
+++ b/release/scripts/startup/bl_ui/properties_collection.py
@@ -68,6 +68,16 @@ class COLLECTION_PT_clay_settings(CollectionButtonsPanel, Panel):
         col.template_override_property(collection_props, scene_props, "ssao_factor_edge")
         col.template_override_property(collection_props, scene_props, "ssao_distance")
         col.template_override_property(collection_props, scene_props, "ssao_attenuation")
+        col.template_override_property(collection_props, scene_props, "world_intensity")
+
+        col.separator()
+        col.label("Hair Settings:")
+        col.template_override_property(collection_props, scene_props, "diffuse_intensity")
+        col.template_override_property(collection_props, scene_props, "specular_intensity")
+        col.template_override_property(collection_props, scene_props, "specular_hardness")
+        col.template_override_property(collection_props, scene_props, "color_randomicity")
+        col.template_override_property(collection_props, scene_props, "hair_diffuse_color")
+        col.template_override_property(collection_props, scene_props, "hair_specular_color")
 
 
 class COLLECTION_PT_object_mode_settings(CollectionButtonsPanel, Panel):
diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index 0431cd51663..e56c559a163 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -615,6 +615,16 @@ class RENDER_PT_clay_collection_settings(RenderButtonsPanel, Panel):
         col.prop(props, "ssao_distance")
         col.prop(props, "ssao_attenuation")
 
+        col.separator()
+        col.label("Hair Settings:")
+        col.prop(props, "world_intensity")
+        col.prop(props, "diffuse_intensity")
+        col.prop(props, "specular_intensity")
+        col.prop(props, "specular_hardness")
+        col.prop(props, "color_randomicity")
+        col.prop(props, "hair_diffuse_color")
+        col.prop(props, "hair_specular_color")
+
 class RENDER_PT_eevee_poststack_settings(RenderButtonsPanel, Panel):
     bl_label = "Post Process Stack"
     COMPAT_ENGINES = {'BLENDER_EEVEE'}
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 2b6a84a2f87..90f7703b967 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -479,3 +479,10 @@ void BKE_particle_system_eval(struct EvaluationContext *eval_ctx,
                               struct ParticleSystem *psys);
 
 #endif
+
+/* Draw Cache */
+enum {
+	BKE_PARTICLE_BATCH_DIRTY_ALL = 0,
+};
+void BKE_particle_batch_cache_dirty(struct ParticleSystem *psys, int mode);
+void BKE_particle_batch_cache_free(struct ParticleSystem *psys);
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index b6f5f11846b..71257fdc4b4 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -4305,3 +4305,22 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys)
 		psys->flag |= PSYS_EDITED;
 	}
 }
+
+
+
+/* Draw Engine */
+void (*BKE_particle_batch_cache_dirty_cb)(ParticleSystem *psys, int mode) = NULL;
+void (*BKE_particle_batch_cache_free_cb)(ParticleSystem *psys) = NULL;
+
+void BKE_particle_batch_cache_dirty(ParticleSystem *psys, int mode)
+{
+	if (psys->batch_cache) {
+		BKE_particle_batch_cache_dirty_cb(psys, mode);
+	}
+}
+void BKE_particle_batch_cache_free(ParticleSystem *psys)
+{
+	if (psys->batch_cache) {
+		BKE_particle_batch_cache_free_cb(psys);
+	}
+}
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index c26ac056499..2da0b6aeb4f 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4321,6 +4321,8 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, cons
 	/* save matrix for duplicators, at rendertime the actual dupliobject's matrix is used so don't update! */
 	if (psys->renderdata==0)
 		invert_m4_m4(psys->imat, ob->obmat);
+
+	BKE_particle_batch_cache_dirty(psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
 }
 
 /* ID looper */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bd2180c28a2..cac1ec084b5 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4372,6 +4372,8 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
 
 		psys->tree = NULL;
 		psys->bvhtree = NULL;
+
+		psys->batch_cache = NULL;
 	}
 	return;
 }
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index fa625f608a1..45c52187f72 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -59,6 +59,7 @@ set(SRC
 	intern/draw_cache_impl_displist.c
 	intern/draw_cache_impl_lattice.c
 	intern/draw_cache_impl_mesh.c
+	intern/draw_cache_impl_particles.c
 	intern/draw_common.c
 	intern/draw_manager.c
 	intern/draw_manager_text.c
@@ -108,6 +109,8 @@ data_to_c_simple(engines/clay/shaders/clay_frag.glsl SRC)
 data_to_c_simple(engines/clay/shaders/clay_vert.glsl SRC)
 data_to_c_simple(engines/clay/shaders/ssao_alchemy.glsl SRC)
 data_to_c_simple(engines/clay/shaders/ssao_groundtruth.glsl SRC)
+data_to_c_simple(engines/clay/shaders/particle_vert.glsl SRC)
+data_to_c_simple(engines/clay/shaders/particle_strand_frag.glsl SRC)
 
 data_to_c_simple(engines/eevee/shaders/default_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/default_world_frag.glsl SRC)
diff --git a/source/blender/draw/engines/clay/clay_engine.c b/source/blender/draw/engines/clay/clay_engine.c
index a405f26ea8e..95ddb3cc6fa 100644
--- a/source/blender/draw/engines/clay/clay_engine.c
+++ b/source/blender/draw/engines/clay/clay_engine.c
@@ -21,9 +21,12 @@
 
 #include "DRW_render.h"
 
+#include "DNA_particle_types.h"
+
 #include "BKE_icons.h"
 #include "BKE_idprop.h"
 #include "BKE_main.h"
+#include "BKE_particle.h"
 
 #include "BLI_dynstr.h"
 #include "BLI_rand.h"
@@ -43,6 +46,8 @@
 extern char datatoc_clay_frag_glsl[];
 extern char datatoc_clay_vert_glsl[];
 extern char datatoc_ssao_alchemy_glsl[];
+extern char datatoc_particle_vert_glsl[];
+extern char datatoc_particle_strand_frag_glsl[];
 
 /* *********** LISTS *********** */
 
@@ -59,24 +64,45 @@ typedef struct CLAY_UBO_Material {
 } CLAY_UBO_Material; /* 48 bytes */
 BLI_STATIC_ASSERT_ALIGN(CLAY_UBO_Material, 16);
 
+typedef struct CLAY_HAIR_UBO_Material {
+	float hair_world;
+	float hair_diffuse;
+	float hair_specular;
+	float hair_hardness;
+	float hair_randomicity;
+	float pad1[3];
+	float hair_diffuse_color[3];
+	float pad2;
+	float hair_specular_color[3];
+	float pad3;
+} CLAY_HAIR_UBO_Material; /* 48 bytes */
+
 #define MAX_CLAY_MAT 512 /* 512 = 9 bit material id */
 
 typedef struct CLAY_UBO_Storage {
 	CLAY_UBO_Material materials[MAX_CLAY_MAT];
 } CLAY_UBO_Storage;
 
+typedef struct CLAY_HAIR_UBO_Storage {
+	CLAY_HAIR_UBO_Material materials[MAX_CLAY_MAT];
+} CLAY_HAIR_UBO_Storage;
+
 /* GPUViewport.storage
  * Is freed everytime the viewport engine changes */
 typedef struct CLAY_Storage {
 	/* Materials Parameter UBO */
 	CLAY_UBO_Storage mat_storage;
+	CLAY_HAIR_UBO_Storage hair_mat_storage;
 	int ubo_current_id;
+	int hair_ubo_current_id;
 	DRWShadingGroup *shgrps[MAX_CLAY_MAT];
+	DRWShadingGroup *hair_shgrps[MAX_CLAY_MAT];
 } CLAY_Storage;
 
 typedef struct CLAY_StorageList {
 	struct CLAY_Storage *storage;
 	struct GPUUniformBuffer *mat_ubo;
+	struct GPUUniformBuffer *hair_mat_ubo;
 	struct CLAY_PrivateData *g_data;
 } CLAY_StorageList;
 
@@ -99,6 +125,7 @@ typedef struct CLAY_PassList {
 	struct DRWPass *depth_pass;
 	struct DRWPass *depth_pass_cull;
 	struct DRWPass *clay_pass;
+	struct DRWPass *hair_pass;
 } CLAY_PassList;
 
 typedef struct CLAY_Data {
@@ -116,6 +143,7 @@ static struct {
 	struct GPUShader *depth_sh;
 	/* Shading Pass */
 	struct GPUShader *clay_sh;
+	struct GPUShader *hair_sh;
 
 	/* Matcap textures */
 	struct GPUTexture *matcap_array;
@@ -129,8 +157,12 @@ static struct {
 	struct GPUTexture *jitter_tx;
 	struct GPUTexture *sampling_tx;
 
+	/* hair */
+	float hair_light[3];
+
 	/* Just a serie of int from 0 to MAX_CLAY_MAT-1 */
 	int ubo_mat_idxs[MAX_CLAY_MAT];
+	int hair_ubo_mat_idxs[MAX_CLAY_MAT];
 } e_data = {NULL}; /* Engine data */
 
 typedef struct CLAY_PrivateData {
@@ -140,6 +172,7 @@ typedef struct CLAY_PrivateData {
 	DRWShadingGroup *depth_shgrp_cull;
 	DRWShadingGroup *depth_shgrp_cull_select;
 	DRWShadingGroup *depth_shgrp_cull_active;
+	DRWShadingGroup *hair;
 } CLAY_PrivateData; /* Transient data */
 
 /* Functions */
@@ -324,6 +357,10 @@ static void CLAY_engine_init(void *vedata)
 		MEM_freeN(matcap_with_ao);
 	}
 
+	if (!e_data.hair_sh) {
+		e_data.hair_sh = DRW_shader_create(datatoc_particle_vert_glsl, NULL, datatoc_particle_strand_frag_glsl, "#define MAX_MATERIAL 512\n");
+	}
+
 	if (!stl->storage) {
 		stl->storage = MEM_callocN(sizeof(CLAY_Storage), "CLAY_Storage");
 	}
@@ -332,6 +369,10 @@ static void CLAY_engine_init(void *vedata)
 		stl->mat_ubo = DRW_uniformbuffer_create(sizeof(CLAY_UBO_Storage), NULL);
 	}
 
+	if (!stl->hair_mat_ubo) {
+		stl->hair_mat_ubo = DRW_uniformbuffer_create(sizeof(CLAY_HAIR_UBO_Storage), NULL);
+	}
+
 	if (e_data.ubo_mat_idxs[1] == 0) {
 		/* Just int to have pointers to them */
 		for (int i = 0; i < MAX_CLAY_MAT; ++i) {
@@ -413,6 +454,13 @@ static void CLAY_engine_init(void *vedata)
 			e_data.cached_sample_num = ssao_samples;
 		}
 	}
+
+	/* hair setup */
+	{
+		e_data.hair_light[0] = 1.0f;
+		e_data.hair_light[1] = -0.5f;
+		e_data.hair_light[2] = -0.7f;
+	}
 }
 
 static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *vedata, DRWPass *pass, int *material_id)
@@ -437,6 +485,16 @@ static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *vedata, DRWPass *pass, in
 	return grp;
 }
 
+stat

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list