[Bf-blender-cvs] [90fdb427afe] temp-eeveelightcache: Eevee: LightProbes: Change/optimize the cubemap probe display

Clément Foucault noreply at git.blender.org
Fri Jun 22 17:46:34 CEST 2018


Commit: 90fdb427afe05362dbfa79bc74c175468c67cb04
Author: Clément Foucault
Date:   Thu Jun 21 18:45:47 2018 +0200
Branches: temp-eeveelightcache
https://developer.blender.org/rB90fdb427afe05362dbfa79bc74c175468c67cb04

Eevee: LightProbes: Change/optimize the cubemap probe display

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

M	source/blender/draw/engines/eevee/eevee_lightprobes.c
M	source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index 147ab2eac72..8690bbe148c 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -211,7 +211,7 @@ static void lightprobe_shaders_init(void)
 	        datatoc_common_view_lib_glsl,
 	        datatoc_lightprobe_cube_display_vert_glsl);
 
-	e_data.probe_cube_display_sh = DRW_shader_create(vert_str, NULL, shader_str, NULL);
+	e_data.probe_cube_display_sh = DRW_shader_create(vert_str, NULL, shader_str, SHADER_DEFINES);
 
 	MEM_freeN(vert_str);
 	MEM_freeN(shader_str);
@@ -457,13 +457,14 @@ void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedat
 		psl->probe_display = DRW_pass_create("LightProbe Display", state);
 
 		/* Cube Display */
-		DRWShadingGroup *grp = DRW_shgroup_empty_tri_batch_create(
-		        e_data.probe_cube_display_sh,
-		        psl->probe_display,
-		        GPU_texture_layers(lcache->cube_tx) * 2);
+		int cube_count = GPU_texture_layers(lcache->cube_tx) - 1; /* don't count the world. */
+		DRWShadingGroup *grp = DRW_shgroup_empty_tri_batch_create(e_data.probe_cube_display_sh,
+		                                                          psl->probe_display, cube_count * 2);
 		DRW_shgroup_uniform_texture_ref(grp, "probeCubes", &lcache->cube_tx);
+		DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
 		DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 		DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+		DRW_shgroup_uniform_float_copy(grp, "sphere_size", 0.2f); /* TODO param */
 
 		/* Grid Display */
 		EEVEE_LightGrid *egrid = lcache->grid_data + 1;
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
index d10f4bc0d42..5a72244cfbe 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
@@ -1,15 +1,18 @@
 
 flat in int pid;
-in vec3 worldNormal;
-in vec3 worldPosition;
+in vec2 quadCoord;
 
 out vec4 FragColor;
 
 void main()
 {
-	vec3 V = (ProjectionMatrix[3][3] == 0.0) /* if perspective */
-	            ? normalize(cameraPos - worldPosition)
-	            : cameraForward;
-	vec3 N = normalize(worldNormal);
-	FragColor = vec4(textureLod_octahedron(probeCubes, vec4(reflect(-V, N), pid), 0.0, prbLodCubeMax).rgb, 1.0);
+	float dist_sqr = dot(quadCoord, quadCoord);
+
+	/* Discard outside the circle. */
+	if (dist_sqr > 1.0)
+		discard;
+
+	vec3 view_nor = vec3(quadCoord, sqrt(max(0.0, 1.0 - dist_sqr)));
+	vec3 world_ref = mat3(ViewMatrixInverse) * reflect(vec3(0.0, 0.0, -1.0), view_nor);
+	FragColor = vec4(textureLod_octahedron(probeCubes, vec4(world_ref, pid), 0.0, prbLodCubeMax).rgb, 1.0);
 }
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 b0a6cbe1707..b327878b63d 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,26 +1,43 @@
 
-in vec3 pos;
+/* XXX TODO fix code duplication */
+struct CubeData {
+	vec4 position_type;
+	vec4 attenuation_fac_type;
+	mat4 influencemat;
+	mat4 parallaxmat;
+};
 
-/* Instance attrib */
-in int probe_id;
-in vec3 probe_location;
-in float sphere_size;
+layout(std140) uniform probe_block {
+	CubeData probes_data[MAX_PROBE];
+};
+
+uniform float sphere_size;
+uniform vec3 screen_vecs[2];
 
 flat out int pid;
-out vec3 worldNormal;
-out vec3 worldPosition;
+out vec2 quadCoord;
+
+const vec2 pos[6] = vec2[6](
+	vec2(-1.0, -1.0),
+	vec2( 1.0, -1.0),
+	vec2(-1.0,  1.0),
+
+	vec2( 1.0, -1.0),
+	vec2( 1.0,  1.0),
+	vec2(-1.0,  1.0)
+);
 
 void main()
 {
-	pid = probe_id;
+	pid = 1 + (gl_VertexID / 6); /* +1 for the world */
+	int vert_id = gl_VertexID % 6;
+
+	quadCoord = pos[vert_id];
 
-	/* 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;
+	vec3 ws_location = probes_data[pid].position_type.xyz;
+	vec3 screen_pos = screen_vecs[0] * quadCoord.x + screen_vecs[1] * quadCoord.y;
+	ws_location += screen_pos * sphere_size;
 
-	vec4 wpos = offsetmat * vec4(pos * sphere_size, 1.0);
-	worldPosition = wpos.xyz;
-	gl_Position = ViewProjectionMatrix * wpos;
-	worldNormal = normalize(pos);
+	gl_Position = ViewProjectionMatrix * vec4(ws_location, 1.0);
+	gl_Position.z += 0.0001; /* Small bias to let the icon draw without zfighting */
 }
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 b13a986cb04..4c77430ddf9 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
@@ -45,4 +45,5 @@ void main()
 	ws_cell_location += screen_pos * 0.02 * sphere_size;
 
 	gl_Position = ViewProjectionMatrix * vec4(ws_cell_location , 1.0);
+	gl_Position.z += 0.0001; /* Small bias to let the icon draw without zfighting */
 }



More information about the Bf-blender-cvs mailing list