[Bf-blender-cvs] [1054f65a29b] blender2.8: Object Mode : Add probes data outlines and selectability

Clément Foucault noreply at git.blender.org
Sat Sep 30 19:38:00 CEST 2017


Commit: 1054f65a29b0b9ee9cf7db8a4036e4a55506ce03
Author: Clément Foucault
Date:   Sat Sep 30 19:34:23 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB1054f65a29b0b9ee9cf7db8a4036e4a55506ce03

Object Mode : Add probes data outlines and selectability

This required some small changes to the data display shaders so that they match the way the object mode renders them.
Strangely enough, I had to remove the normal attribute from the display code because it was being not bound as soon as I created another rendering call in object mode. The problem may be deeper but I did not have time for this so I derive the normal from the sphere pos.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/eevee/eevee_lightprobes.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl
M	source/blender/draw/modes/object_mode.c
A	source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 43e07d51255..64edd76c257 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -195,6 +195,7 @@ data_to_c_simple(modes/shaders/object_outline_expand_frag.glsl SRC)
 data_to_c_simple(modes/shaders/object_outline_detect_frag.glsl SRC)
 data_to_c_simple(modes/shaders/object_grid_frag.glsl SRC)
 data_to_c_simple(modes/shaders/object_grid_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_lightprobe_grid_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_particle_prim_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_particle_prim_frag.glsl SRC)
 data_to_c_simple(modes/shaders/object_particle_dot_vert.glsl SRC)
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index fad1b58f34b..bbd82f1c3a0 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -253,19 +253,9 @@ void EEVEE_lightprobes_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *UNUSED(ved
 
 		MEM_freeN(shader_str);
 
-		ds_frag = BLI_dynstr_new();
-		BLI_dynstr_append(ds_frag, datatoc_octahedron_lib_glsl);
-		BLI_dynstr_append(ds_frag, datatoc_bsdf_common_lib_glsl);
-		BLI_dynstr_append(ds_frag, datatoc_lightprobe_lib_glsl);
-		BLI_dynstr_append(ds_frag, datatoc_lightprobe_planar_display_frag_glsl);
-		shader_str = BLI_dynstr_get_cstring(ds_frag);
-		BLI_dynstr_free(ds_frag);
-
 		e_data.probe_planar_display_sh = DRW_shader_create(
-		        datatoc_lightprobe_planar_display_vert_glsl, NULL, shader_str,
-		        "#define MAX_PLANAR " STRINGIFY(MAX_PLANAR) "\n");
-
-		MEM_freeN(shader_str);
+		        datatoc_lightprobe_planar_display_vert_glsl, NULL,
+		        datatoc_lightprobe_planar_display_frag_glsl, NULL);
 
 		e_data.probe_planar_downsample_sh = DRW_shader_create(
 		        datatoc_lightprobe_planar_downsample_vert_glsl,
@@ -440,6 +430,12 @@ void EEVEE_lightprobes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *veda
 		DRW_shgroup_attrib_float(grp, "sphere_size", 1);
 		DRW_shgroup_uniform_float(grp, "lodCubeMax", &sldata->probes->lod_cube_max, 1);
 		DRW_shgroup_uniform_buffer(grp, "probeCubes", &sldata->probe_pool);
+
+		geom = DRW_cache_quad_get();
+		grp = stl->g_data->planar_display_shgrp = DRW_shgroup_instance_create(e_data.probe_planar_display_sh, psl->probe_display, geom);
+		DRW_shgroup_attrib_float(grp, "probe_id", 1); /* XXX this works because we are still uploading 4bytes and using the right stride */
+		DRW_shgroup_attrib_float(grp, "probe_mat", 16);
+		DRW_shgroup_uniform_buffer(grp, "probePlanars", &txl->planar_pool);
 	}
 
 	{
@@ -512,7 +508,7 @@ static void scale_m4_v3(float R[4][4], float v[3])
 		mul_v3_v3(R[i], v);
 }
 
-static void EEVEE_planar_reflections_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl, EEVEE_TextureList *txl)
+static void EEVEE_planar_reflections_updates(EEVEE_SceneLayerData *sldata, EEVEE_StorageList *stl)
 {
 	EEVEE_LightProbesInfo *pinfo = sldata->probes;
 	Object *ob;
@@ -612,14 +608,7 @@ static void EEVEE_planar_reflections_updates(EEVEE_SceneLayerData *sldata, EEVEE
 		    DRW_state_draw_support() &&
 		    (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
 		{
-			DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_planar_display_sh, psl->probe_display);
-
-			DRW_shgroup_uniform_int(grp, "probeIdx", &ped->probe_id, 1);
-			DRW_shgroup_uniform_buffer(grp, "probePlanars", &txl->planar_pool);
-			DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
-
-			struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
-			DRW_shgroup_call_add(grp, geom, ob->obmat);
+			DRW_shgroup_call_dynamic_add(stl->g_data->planar_display_shgrp, &ped->probe_id, ob->obmat);
 		}
 	}
 }
@@ -668,8 +657,9 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
 			DRW_state_draw_support() &&
 		    (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
 		{
+			ped->probe_size = probe->data_draw_size * 0.1f;
 			DRW_shgroup_call_dynamic_add(
-			            stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &probe->data_draw_size);
+			            stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &ped->probe_size);
 		}
 	}
 
@@ -836,7 +826,7 @@ void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata, EEVEE_Data *ve
 	}
 
 	EEVEE_lightprobes_updates(sldata, vedata->psl, vedata->stl);
-	EEVEE_planar_reflections_updates(sldata, vedata->psl, vedata->txl);
+	EEVEE_planar_reflections_updates(sldata, vedata->stl);
 
 	DRW_uniformbuffer_update(sldata->probe_ubo, &sldata->probes->probe_data);
 	DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index 480ff81f3a0..85838898b9b 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -486,6 +486,7 @@ typedef struct EEVEE_LightProbeEngineData {
 	int num_cell;
 	int max_lvl;
 	int probe_id; /* Only used for display data */
+	float probe_size; /* Only used for display data */
 	/* For planar reflection rendering */
 	float viewmat[4][4];
 	float persmat[4][4];
@@ -518,6 +519,7 @@ typedef struct EEVEE_PrivateData {
 	struct DRWShadingGroup *refract_depth_shgrp_clip;
 	struct DRWShadingGroup *refract_depth_shgrp_clip_cull;
 	struct DRWShadingGroup *cube_display_shgrp;
+	struct DRWShadingGroup *planar_display_shgrp;
 	struct DRWShadingGroup *planar_downsample;
 	struct GHash *material_hash;
 	struct GHash *hair_material_hash;
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
index b943a59feeb..893647d8ecc 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
@@ -1,6 +1,5 @@
 
 in vec3 pos;
-in vec3 nor;
 
 /* Instance attrib */
 in int probe_id;
@@ -16,7 +15,13 @@ out vec3 worldPosition;
 void main()
 {
 	pid = probe_id;
-	worldPosition = pos * 0.1 * sphere_size + probe_location;
-	gl_Position = ViewProjectionMatrix * vec4(worldPosition, 1.0);
-	worldNormal = normalize(nor);
+
+	/* While this is not performant, we do this to
+	 * match the object mode engine instancing shader. */
+	mat4 offsetmat = mat4(1.0); /* Identity */
+	offsetmat[3].xyz = probe_location;
+
+	worldPosition = pos * sphere_size;
+	gl_Position = ViewProjectionMatrix * offsetmat * vec4(worldPosition, 1.0);
+	worldNormal = normalize(pos);
 }
\ No newline at end of file
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
index 121859c98f1..fd200ec5984 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
@@ -1,6 +1,5 @@
 
 in vec3 pos;
-in vec3 nor;
 
 uniform mat4 ViewProjectionMatrix;
 
@@ -31,5 +30,5 @@ void main()
 	     increment_z * ls_cell_location.z);
 
 	gl_Position = ViewProjectionMatrix * vec4(pos * 0.02 * sphere_size + ws_cell_location, 1.0);
-	worldNormal = normalize(nor);
+	worldNormal = normalize(pos);
 }
\ No newline at end of file
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
index 676f7e49ebf..655cc626bba 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
@@ -1,24 +1,14 @@
 
-uniform int probeIdx;
+uniform mat4 ViewProjectionMatrix;
+uniform sampler2DArray probePlanars;
 
 in vec3 worldPosition;
+flat in int probeIdx;
 
 out vec4 FragColor;
 
 void main()
 {
-	PlanarData pd = planars_data[probeIdx];
-
-	/* Fancy fast clipping calculation */
-	vec2 dist_to_clip;
-	dist_to_clip.x = dot(pd.pl_clip_pos_x, worldPosition);
-	dist_to_clip.y = dot(pd.pl_clip_pos_y, worldPosition);
-	float fac = dot(step(pd.pl_clip_edges, dist_to_clip.xxyy), vec2(-1.0, 1.0).xyxy); /* compare and add all tests */
-
-	if (fac != 2.0) {
-		discard;
-	}
-
 	vec4 refco = ViewProjectionMatrix * vec4(worldPosition, 1.0);
 	refco.xy /= refco.w;
 	FragColor = vec4(textureLod(probePlanars, vec3(refco.xy * 0.5 + 0.5, float(probeIdx)), 0.0).rgb, 1.0);
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl
index 3c620982273..a9716332eb5 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl
@@ -1,13 +1,17 @@
 
 in vec3 pos;
 
-uniform mat4 ModelViewProjectionMatrix;
-uniform mat4 ModelMatrix;
+in int probe_id;
+in mat4 probe_mat;
+
+uniform mat4 ViewProjectionMatrix;
 
 out vec3 worldPosition;
+flat out int probeIdx;
 
 void main()
 {
-	gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
-	worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
+	gl_Position = ViewProjectionMatrix * probe_mat * vec4(pos, 1.0);
+	worldPosition = (probe_mat * vec4(pos, 1.0)).xyz;
+	probeIdx = probe_id;
 }
\ No newline at end of file
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 1667dd9e846..46153ede354 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -71,6 +71,7 @@ extern char datatoc_object_grid_frag_glsl[];
 extern char datatoc_object_grid_vert_glsl[];
 extern char datatoc_object_empty_image_frag_glsl[];
 extern char datatoc_object_empty_image_vert_glsl[];
+extern char datatoc_object_lightprobe_grid_vert_glsl[];
 extern char datatoc_object_particle_prim_vert_glsl[];
 extern char datatoc_object_particle_prim_frag_glsl[];
 extern char datatoc_object_particle_dot_vert_glsl[];
@@ -78,6 +79,7 @@ extern char datato

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list