Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-07-10 16:02:25 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-07-10 16:31:34 +0300
commit1a43e081873415754950766edaddad220adf67bc (patch)
tree6a4e61b2337606daf442973d9f82e1d56b906a98 /source/blender/draw/engines/eevee/shaders
parent97f90d48a02eef89949532b166f57ea178ee5a87 (diff)
Eevee: LightCache: Initial Implementation
This separate probe rendering from viewport rendering, making possible to run the baking in another thread (non blocking and faster). The baked lighting is saved in the blend file. Nothing needs to be recomputed on load. There is a few missing bits / bugs: - Cache cannot be saved to disk as a separate file, it is saved in the DNA for now making file larger and memory usage higher. - Auto update only cubemaps does update the grids (bug). - Probes cannot be updated individually (considered as dynamic). - Light Cache cannot be (re)generated during render.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl17
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl49
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl14
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl35
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl1
-rw-r--r--source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl11
6 files changed, 89 insertions, 38 deletions
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_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..7a92b55e530 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,44 @@ 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 * 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 */
}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
index 0ffc0cc4b49..6ae13e0102d 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
@@ -27,6 +27,7 @@ struct PlanarData {
vec4 clip_edges;
vec4 facing_scale_bias;
mat4 reflectionmat; /* transform world space into reflection texture space */
+ mat4 unused;
};
#define pl_plane_eq plane_equation
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index 644b449c03e..22194c22f39 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -256,7 +256,7 @@ void CLOSURE_NAME(
PlanarData pd = planars_data[i];
/* Fade on geometric normal. */
- float fade = probe_attenuation_planar(pd, worldPosition, worldNormal, roughness);
+ float fade = probe_attenuation_planar(pd, worldPosition, (gl_FrontFacing) ? worldNormal : -worldNormal, roughness);
if (fade > 0.0) {
if (!(ssrToggle && ssr_id == outputSsrId)) {
@@ -404,7 +404,7 @@ void CLOSURE_NAME(
spec_occlu = 1.0;
}
- out_spec += spec_accum.rgb * ssr_spec * spec_occlu * float(specToggle);
+ out_spec += spec_accum.rgb * ssr_spec * spec_occlu;
#endif
#ifdef CLOSURE_REFRACTION
@@ -419,7 +419,12 @@ void CLOSURE_NAME(
vec2 C_brdf_lut = texture(utilTex, vec3(C_uv, 1.0)).rg;
vec3 C_fresnel = F_ibl(vec3(0.04), brdf_lut) * specular_occlusion(NV, final_ao, C_roughness);
- out_spec += C_spec_accum.rgb * C_fresnel * float(specToggle) * C_intensity;
+ out_spec += C_spec_accum.rgb * C_fresnel * C_intensity;
+#endif
+
+#ifdef CLOSURE_GLOSSY
+ /* Global toggle for lightprobe baking. */
+ out_spec *= float(specToggle);
#endif
/* ---------------------------------------------------------------- */