Commit: 29a834e530ec38547eed6952889ddedf917c214e
Author: Clément Foucault
Date:   Thu Jun 21 17:51:37 2018 +0200
Branches: temp-eeveelightcache
https://developer.blender.org/rB29a834e530ec38547eed6952889ddedf917c214e

Eevee: LightProbes: Add back and optimize the irradiance sample display

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

M       source/blender/draw/engines/eevee/eevee_engine.c
M       source/blender/draw/engines/eevee/eevee_lightprobes.c
M       
source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
M       
source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_engine.c 
b/source/blender/draw/engines/eevee/eevee_engine.c
index 24d2934cf91..b2aebdbd762 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -289,7 +289,7 @@ static void eevee_draw_background(void *vedata)
                EEVEE_subsurface_compute(sldata, vedata);
                EEVEE_reflection_compute(sldata, vedata);
                EEVEE_occlusion_draw_debug(sldata, vedata);
-               // DRW_draw_pass(psl->probe_display);
+               DRW_draw_pass(psl->probe_display);
                EEVEE_refraction_compute(sldata, vedata);
 
                /* Opaque refraction */
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c 
b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index 682b85c9344..147ab2eac72 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -456,21 +456,33 @@ void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData 
*sldata, EEVEE_Data *vedat
                DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH 
| DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
                psl->probe_display = DRW_pass_create("LightProbe Display", 
state);
 
-               DRW_shgroup_instance_format(e_data.format_probe_display_cube, {
-                   {"probe_id",       DRW_ATTRIB_INT, 1},
-                   {"probe_location", DRW_ATTRIB_FLOAT, 3},
-                   {"sphere_size",    DRW_ATTRIB_FLOAT, 1},
-               });
-
-               DRWShadingGroup *grp = DRW_shgroup_instance_create(
+               /* Cube Display */
+               DRWShadingGroup *grp = DRW_shgroup_empty_tri_batch_create(
                        e_data.probe_cube_display_sh,
                        psl->probe_display,
-                       DRW_cache_sphere_get(),
-                       e_data.format_probe_display_cube);
-               stl->g_data->cube_display_shgrp = grp;
+                       GPU_texture_layers(lcache->cube_tx) * 2);
                DRW_shgroup_uniform_texture_ref(grp, "probeCubes", 
&lcache->cube_tx);
                DRW_shgroup_uniform_block(grp, "common_block", 
sldata->common_ubo);
+               DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", 
DRW_viewport_screenvecs_get(), 2);
+
+               /* Grid Display */
+               EEVEE_LightGrid *egrid = lcache->grid_data + 1;
+               for (int p = 1; p < lcache->grid_count; ++p, egrid++) {
+                       DRWShadingGroup *shgrp = 
DRW_shgroup_create(e_data.probe_grid_display_sh, psl->probe_display);
+                       DRW_shgroup_uniform_int(shgrp, "offset", 
&egrid->offset, 1);
+                       DRW_shgroup_uniform_ivec3(shgrp, "grid_resolution", 
egrid->resolution, 1);
+                       DRW_shgroup_uniform_vec3(shgrp, "corner", 
egrid->corner, 1);
+                       DRW_shgroup_uniform_vec3(shgrp, "increment_x", 
egrid->increment_x, 1);
+                       DRW_shgroup_uniform_vec3(shgrp, "increment_y", 
egrid->increment_y, 1);
+                       DRW_shgroup_uniform_vec3(shgrp, "increment_z", 
egrid->increment_z, 1);
+                       DRW_shgroup_uniform_vec3(shgrp, "screen_vecs[0]", 
DRW_viewport_screenvecs_get(), 2);
+                       DRW_shgroup_uniform_texture_ref(shgrp, 
"irradianceGrid", &lcache->grid_tx);
+                       DRW_shgroup_uniform_float_copy(shgrp, "sphere_size", 
1.0f); /* TODO param */
+                       int tri_count = egrid->resolution[0] * 
egrid->resolution[1] * egrid->resolution[2] * 2;
+                       DRW_shgroup_call_procedural_triangles_add(shgrp, 
tri_count, NULL);
+               }
 
+               /* Planar Display */
                DRW_shgroup_instance_format(e_data.format_probe_display_planar, 
{
                    {"probe_id", DRW_ATTRIB_INT, 1},
                    {"probe_mat", DRW_ATTRIB_FLOAT, 16},
diff --git 
a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl 
b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
index d333ad34bb0..fd8eb157aa5 100644
--- 
a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
+++ 
b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
@@ -1,11 +1,19 @@
 
 flat in int cellOffset;
-in vec3 worldNormal;
+in vec2 quadCoord;
 
 out vec4 FragColor;
 
 void main()
 {
-       IrradianceData ir_data = load_irradiance_cell(cellOffset, worldNormal);
-       FragColor = vec4(compute_irradiance(worldNormal, ir_data), 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_nor = mat3(ViewMatrixInverse) * view_nor;
+       IrradianceData ir_data = load_irradiance_cell(cellOffset, world_nor);
+       FragColor = vec4(compute_irradiance(world_nor, ir_data), 1.0);
 }
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 a017a791e41..b13a986cb04 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,4 @@
 
-in vec3 pos;
-
 uniform float sphere_size;
 uniform int offset;
 uniform ivec3 grid_resolution;
@@ -8,25 +6,43 @@ uniform vec3 corner;
 uniform vec3 increment_x;
 uniform vec3 increment_y;
 uniform vec3 increment_z;
+uniform vec3 screen_vecs[2];
 
 flat out int cellOffset;
-out vec3 worldNormal;
+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()
 {
+       int cell_id = gl_VertexID / 6;
+       int vert_id = gl_VertexID % 6;
+
        vec3 ls_cell_location;
        /* Keep in sync with update_irradiance_probe */
-       ls_cell_location.z = float(gl_InstanceID % grid_resolution.z);
-       ls_cell_location.y = float((gl_InstanceID / grid_resolution.z) % 
grid_resolution.y);
-       ls_cell_location.x = float(gl_InstanceID / (grid_resolution.z * 
grid_resolution.y));
+       ls_cell_location.z = float(cell_id % grid_resolution.z);
+       ls_cell_location.y = float((cell_id / grid_resolution.z) % 
grid_resolution.y);
+       ls_cell_location.x = float(cell_id / (grid_resolution.z * 
grid_resolution.y));
 
-       cellOffset = offset + gl_InstanceID;
+       cellOffset = offset + cell_id;
 
        vec3 ws_cell_location = corner +
            (increment_x * ls_cell_location.x +
             increment_y * ls_cell_location.y +
             increment_z * ls_cell_location.z);
 
-       gl_Position = ViewProjectionMatrix * vec4(pos * 0.02 * sphere_size + 
ws_cell_location, 1.0);
-       worldNormal = normalize(pos);
+
+       quadCoord = pos[vert_id];
+       vec3 screen_pos = screen_vecs[0] * quadCoord.x + screen_vecs[1] * 
quadCoord.y;
+       ws_cell_location += screen_pos * 0.02 * sphere_size;
+
+       gl_Position = ViewProjectionMatrix * vec4(ws_cell_location , 1.0);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to