[Bf-blender-cvs] [d9d65a06d3d] blender2.8: Eevee: Move cube shadows to octahedron shadowmaps.
Clément Foucault
noreply at git.blender.org
Sat May 20 23:58:20 CEST 2017
Commit: d9d65a06d3db36efd5848cf7ae3e08c72c2c296b
Author: Clément Foucault
Date: Sat May 20 13:16:14 2017 +0200
Branches: blender2.8
https://developer.blender.org/rBd9d65a06d3db36efd5848cf7ae3e08c72c2c296b
Eevee: Move cube shadows to octahedron shadowmaps.
We render linear distance to the light in a R32 texture and store it into an octahedron projection inside a 2D texture array.
This render the sampling function much more simpler and without edge artifacts.
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/eevee/eevee_engine.c
M source/blender/draw/engines/eevee/eevee_lights.c
M source/blender/draw/engines/eevee/eevee_private.h
M source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M source/blender/draw/engines/eevee/shaders/shadow_frag.glsl
M source/blender/draw/engines/eevee/shaders/shadow_geom.glsl
A source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl
A source/blender/draw/engines/eevee/shaders/shadow_store_geom.glsl
A source/blender/draw/engines/eevee/shaders/shadow_store_vert.glsl
M source/blender/draw/engines/eevee/shaders/shadow_vert.glsl
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index a7432211160..3bfa9a15ce3 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -131,6 +131,9 @@ data_to_c_simple(engines/eevee/shaders/probe_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/shadow_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/shadow_geom.glsl SRC)
data_to_c_simple(engines/eevee/shaders/shadow_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_store_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_store_geom.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_store_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/bsdf_lut_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/bsdf_direct_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/bsdf_common_lib.glsl SRC)
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c
index fcbc3f073ff..01363ef878d 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -56,8 +56,6 @@ static struct {
struct GPUShader *default_world;
struct GPUShader *default_background;
struct GPUShader *depth_sh;
- struct GPUShader *tonemap;
- struct GPUShader *shadow_sh;
struct GPUShader *probe_filter_sh;
struct GPUShader *probe_spherical_harmonic_sh;
@@ -263,11 +261,6 @@ static void EEVEE_engine_init(void *ved)
MEM_freeN(frag_str);
}
- if (!e_data.shadow_sh) {
- e_data.shadow_sh = DRW_shader_create(
- datatoc_shadow_vert_glsl, datatoc_shadow_geom_glsl, datatoc_shadow_frag_glsl, NULL);
- }
-
if (!e_data.default_world) {
e_data.default_world = DRW_shader_create(
datatoc_probe_vert_glsl, datatoc_probe_geom_glsl, datatoc_default_world_frag_glsl, NULL);
@@ -341,32 +334,6 @@ static DRWShadingGroup *eevee_cube_shgroup(struct GPUShader *sh, DRWPass *pass,
return grp;
}
-static DRWShadingGroup *eevee_cube_shadow_shgroup(
- EEVEE_PassList *psl, EEVEE_StorageList *stl, struct Batch *geom, float (*obmat)[4])
-{
- DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.shadow_sh, psl->shadow_cube_pass, geom);
- DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
- DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
-
- for (int i = 0; i < 6; ++i)
- DRW_shgroup_call_dynamic_add_empty(grp);
-
- return grp;
-}
-
-static DRWShadingGroup *eevee_cascade_shadow_shgroup(
- EEVEE_PassList *psl, EEVEE_StorageList *stl, struct Batch *geom, float (*obmat)[4])
-{
- DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.shadow_sh, psl->shadow_cascade_pass, geom);
- DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
- DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
-
- for (int i = 0; i < MAX_CASCADE_NUM; ++i)
- DRW_shgroup_call_dynamic_add_empty(grp);
-
- return grp;
-}
-
static void EEVEE_cache_init(void *vedata)
{
static int zero = 0;
@@ -381,14 +348,6 @@ static void EEVEE_cache_init(void *vedata)
}
{
- psl->shadow_cube_pass = DRW_pass_create("Shadow Cube Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
- }
-
- {
- psl->shadow_cascade_pass = DRW_pass_create("Shadow Cascade Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
- }
-
- {
// psl->shadow_pass = DRW_pass_create("Shadow Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
// stl->g_data->shadow_shgrp = DRW_shgroup_create(e_data.shadow_sh, psl->shadow_pass);
// DRW_shgroup_uniform_mat4(stl->g_data->shadow_shgrp, "ShadowMatrix", (float *)stl->lamps->shadowmat);
@@ -556,7 +515,7 @@ static void EEVEE_cache_init(void *vedata)
}
- EEVEE_lights_cache_init(stl);
+ EEVEE_lights_cache_init(stl, psl, txl);
EEVEE_effects_cache_init(vedata);
}
@@ -683,8 +642,11 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
// GPUMaterial *gpumat = GPU_material_from_nodetree(struct bNodeTree *ntree, ListBase *gpumaterials, void *engine_type, int options)
// DRW_shgroup_call_add(stl->g_data->shadow_shgrp, geom, ob->obmat);
- eevee_cascade_shadow_shgroup(psl, stl, geom, ob->obmat);
- eevee_cube_shadow_shgroup(psl, stl, geom, ob->obmat);
+ const bool cast_shadow = true;
+
+ if (cast_shadow) {
+ EEVEE_lights_cache_shcaster_add(psl, stl, geom, ob->obmat);
+ }
}
else if (ob->type == OB_LAMP) {
EEVEE_lights_cache_add(stl, ob);
@@ -692,7 +654,6 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
}
typedef struct eevee_bind_shadow_data {
- struct GPUTexture *shadow_depth_map_pool;
struct GPUTexture *shadow_depth_cube_pool;
struct GPUTexture *shadow_depth_cascade_pool;
} eevee_bind_shadow_data;
@@ -700,7 +661,6 @@ typedef struct eevee_bind_shadow_data {
static void eevee_bind_shadow(void *data, DRWShadingGroup *shgrp)
{
eevee_bind_shadow_data *shdw_data = data;
- DRW_shgroup_uniform_texture(shgrp, "shadowMaps", shdw_data->shadow_depth_map_pool);
DRW_shgroup_uniform_texture(shgrp, "shadowCubes", shdw_data->shadow_depth_cube_pool);
DRW_shgroup_uniform_texture(shgrp, "shadowCascades", shdw_data->shadow_depth_cascade_pool);
}
@@ -717,7 +677,6 @@ static void EEVEE_cache_finish(void *vedata)
/* Shadows binding */
eevee_bind_shadow_data data;
- data.shadow_depth_map_pool = txl->shadow_depth_map_pool;
data.shadow_depth_cube_pool = txl->shadow_depth_cube_pool;
data.shadow_depth_cascade_pool = txl->shadow_depth_cascade_pool;
@@ -757,11 +716,11 @@ static void EEVEE_draw_scene(void *vedata)
static void EEVEE_engine_free(void)
{
EEVEE_effects_free();
+ EEVEE_lights_free();
MEM_SAFE_FREE(e_data.frag_shader_lib);
DRW_SHADER_FREE_SAFE(e_data.default_lit);
DRW_SHADER_FREE_SAFE(e_data.default_lit_flat);
- DRW_SHADER_FREE_SAFE(e_data.shadow_sh);
DRW_SHADER_FREE_SAFE(e_data.default_world);
DRW_SHADER_FREE_SAFE(e_data.default_background);
DRW_SHADER_FREE_SAFE(e_data.probe_filter_sh);
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index aeeb25ca1c0..7adc2696746 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -47,6 +47,18 @@ typedef struct EEVEE_ShadowCascadeData {
float viewprojmat[MAX_CASCADE_NUM][4][4]; /* World->Lamp->NDC : used for rendering the shadow map. */
} EEVEE_ShadowCascadeData;
+static struct {
+ struct GPUShader *shadow_sh;
+ struct GPUShader *shadow_store_sh;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_shadow_vert_glsl[];
+extern char datatoc_shadow_geom_glsl[];
+extern char datatoc_shadow_frag_glsl[];
+extern char datatoc_shadow_store_vert_glsl[];
+extern char datatoc_shadow_store_geom_glsl[];
+extern char datatoc_shadow_store_frag_glsl[];
+
/* *********** FUNCTIONS *********** */
void EEVEE_lights_init(EEVEE_StorageList *stl)
@@ -55,6 +67,14 @@ void EEVEE_lights_init(EEVEE_StorageList *stl)
sizeof(EEVEE_ShadowMap) * MAX_SHADOW_MAP +
sizeof(EEVEE_ShadowCascade) * MAX_SHADOW_CASCADE;
+ if (!e_data.shadow_sh) {
+ e_data.shadow_sh = DRW_shader_create(
+ datatoc_shadow_vert_glsl, datatoc_shadow_geom_glsl, datatoc_shadow_frag_glsl, NULL);
+
+ e_data.shadow_store_sh = DRW_shader_create(
+ datatoc_shadow_store_vert_glsl, datatoc_shadow_store_geom_glsl, datatoc_shadow_store_frag_glsl, NULL);
+ }
+
if (!stl->lamps) {
stl->lamps = MEM_callocN(sizeof(EEVEE_LampsInfo), "EEVEE_LampsInfo");
stl->light_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_Light) * MAX_LIGHT, NULL);
@@ -63,7 +83,7 @@ void EEVEE_lights_init(EEVEE_StorageList *stl)
}
}
-void EEVEE_lights_cache_init(EEVEE_StorageList *stl)
+void EEVEE_lights_cache_init(EEVEE_StorageList *stl, EEVEE_PassList *psl, EEVEE_TextureList *txl)
{
EEVEE_LampsInfo *linfo = stl->lamps;
@@ -72,6 +92,23 @@ void EEVEE_lights_cache_init(EEVEE_StorageList *stl)
memset(linfo->shadow_cube_ref, 0, sizeof(linfo->shadow_cube_ref));
memset(linfo->shadow_map_ref, 0, sizeof(linfo->shadow_map_ref));
memset(linfo->shadow_cascade_ref, 0, sizeof(linfo->shadow_cascade_ref));
+
+ {
+ psl->shadow_cube_store_pass = DRW_pass_create("Shadow Storage Pass", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.shadow_store_sh, psl->shadow_cube_store_pass);
+ DRW_shgroup_uniform_buffer(grp, "shadowCube", &txl->shadow_color_cube_target);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ {
+ psl->shadow_cube_pass = DRW_pass_create("Shadow Cube Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+ }
+
+ {
+ psl->shadow_cascade_pass = DRW_pass_create("Shadow Cascade Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+ }
}
void EEVEE_lights_cache_add(EEVEE_StorageList *stl, Object *ob)
@@ -89,7 +126,7 @@ void EEVEE_lights_cache_add(EEVEE_StorageList *stl, Object *ob)
DRW_lamp_engine_data_free((void *)led);
-#if 0 /* TODO Waiting for notified refresh. only on scene change. Else too much perf cost. */
+#if 1 /* TODO Waiting for notified refresh. only on scene change. Else too much perf cost. */
if (la->mode & (LA_SHAD_BUF | LA_SHAD_RAY)) {
if (la->type == LA_SUN && linfo->num_cascade < MAX_SHADOW_CASCADE) {
led->sto = MEM_mallocN(sizeof(EEVEE_ShadowCascadeData), "EEVEE_ShadowCascadeData");
@@ -119,6 +156,24 @@ void EEVEE_lights_cache_add(EEVEE_StorageList *stl, Object *ob)
}
}
+/* Add a shadow caster to the shadowpasses */
+void EEVEE_lights_cache_shcaster_add(EEVEE_PassList *psl, EEVEE_StorageList *stl, struct Batch *geom, float (*obmat)[4])
+{
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.shadow_sh, psl->shadow_cube_pass, geom);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
+ DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
+
+ for (int i = 0; i < 6; ++i)
+ DRW_shgroup_call_dynamic_add_empty(grp);
+
+ grp = DRW_shgroup_instance_create(e_data.shadow_sh, psl->shadow_cascade
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list