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>2021-04-26 02:44:52 +0300
committerClément Foucault <foucault.clem@gmail.com>2021-04-26 02:44:52 +0300
commit1d3de154e21645656291b532a112957a9f034da7 (patch)
tree6c1410dc4f4d4b7e265f3404dfbddd8e0b8ef4e1 /source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl
parent4090bac8c8259926d1727f6347459d4c36b6d6d4 (diff)
EEVEE: Shadow: Simplify the shadow module
Now the shadows are linked to a `Light` object. The `Light` object is linked to an `ObjectKey` to ensure persistence and deletion tracking. The Uniform data are packed so that there is 1 `ShadowPunctualData` per light in a `LightBatch`. This means there is only a shadowmap limit to the number of `Shadow` in a scene.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl40
1 files changed, 39 insertions, 1 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl
index 743f4f16173..55733bf5b14 100644
--- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl
@@ -1,11 +1,12 @@
+#pragma BLENDER_REQUIRE(eevee_shader_shared.hh)
/* ---------------------------------------------------------------------- */
/** \name Shadow Sampling Functions
* \{ */
/* Turns local light coordinate into shadow region index. Matches eShadowCubeFace order. */
-int shadow_punctual_region_get(vec3 lL)
+int shadow_punctual_face_index_get(vec3 lL)
{
vec3 aP = abs(lL);
if (all(greaterThan(aP.xx, aP.yz))) {
@@ -19,4 +20,41 @@ int shadow_punctual_region_get(vec3 lL)
}
}
+/* Transform vector to face local coordinate. */
+vec3 shadow_punctual_local_position_to_face_local(int face_id, vec3 lL)
+{
+ switch (face_id) {
+ case 1:
+ return vec3(-lL.y, lL.z, -lL.x);
+ break;
+ case 2:
+ return vec3(lL.y, lL.z, lL.x);
+ break;
+ case 3:
+ return vec3(lL.x, lL.z, -lL.y);
+ break;
+ case 4:
+ return vec3(-lL.x, lL.z, lL.y);
+ break;
+ case 5:
+ return vec3(lL.x, -lL.y, -lL.z);
+ default:
+ return lL;
+ }
+}
+
+vec3 shadow_punctual_coordinates_get(ShadowPunctualData data, vec3 lL)
+{
+ int face_id = shadow_punctual_face_index_get(lL);
+ lL = shadow_punctual_local_position_to_face_local(face_id, lL);
+ lL *= min(0.0, lL.z + data.shadow_bias) / lL.z;
+
+ vec3 shadow_co = project_point(data.shadow_mat, lL);
+ /* Add one more offset if not omni because region_offset is half a face (in this case) and
+ * only the first face is full sized. */
+ float offset_fac = float(face_id > 0 && !data.is_omni) + float(face_id);
+ shadow_co.y += offset_fac * data.region_offset;
+ return shadow_co;
+}
+
/** \} */