2017-03-17 00:00:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file eevee_lights.c
|
|
|
|
* \ingroup DNA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
2017-09-08 20:21:57 +02:00
|
|
|
#include "BLI_dynstr.h"
|
2018-10-28 21:41:40 +01:00
|
|
|
#include "BLI_rand.h"
|
2018-03-02 18:35:25 +01:00
|
|
|
#include "BLI_rect.h"
|
2017-09-08 20:21:57 +02:00
|
|
|
|
2017-06-01 18:20:44 +02:00
|
|
|
#include "BKE_object.h"
|
|
|
|
|
2018-05-16 19:34:24 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2017-04-26 17:42:39 +10:00
|
|
|
#include "eevee_engine.h"
|
2017-03-17 00:00:46 +01:00
|
|
|
#include "eevee_private.h"
|
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
#define SHADOW_CASTER_ALLOC_CHUNK 16
|
2017-06-01 18:20:44 +02:00
|
|
|
|
2018-07-16 20:08:02 +02:00
|
|
|
// #define DEBUG_CSM
|
2018-10-28 21:41:40 +01:00
|
|
|
// #define DEBUG_SHADOW_DISTRIBUTION
|
2018-07-16 20:08:02 +02:00
|
|
|
|
2017-05-20 13:16:14 +02:00
|
|
|
static struct {
|
|
|
|
struct GPUShader *shadow_sh;
|
2017-09-01 18:39:39 +02:00
|
|
|
struct GPUShader *shadow_store_cube_sh[SHADOW_METHOD_MAX];
|
2018-06-03 22:47:01 +02:00
|
|
|
struct GPUShader *shadow_store_cube_high_sh[SHADOW_METHOD_MAX];
|
2017-09-01 18:39:39 +02:00
|
|
|
struct GPUShader *shadow_store_cascade_sh[SHADOW_METHOD_MAX];
|
2018-06-03 22:47:01 +02:00
|
|
|
struct GPUShader *shadow_store_cascade_high_sh[SHADOW_METHOD_MAX];
|
2017-09-08 20:21:57 +02:00
|
|
|
struct GPUShader *shadow_copy_cube_sh[SHADOW_METHOD_MAX];
|
|
|
|
struct GPUShader *shadow_copy_cascade_sh[SHADOW_METHOD_MAX];
|
2017-05-20 13:16:14 +02:00
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
|
|
|
extern char datatoc_shadow_vert_glsl[];
|
|
|
|
extern char datatoc_shadow_frag_glsl[];
|
|
|
|
extern char datatoc_shadow_store_frag_glsl[];
|
2017-09-08 20:21:57 +02:00
|
|
|
extern char datatoc_shadow_copy_frag_glsl[];
|
|
|
|
extern char datatoc_concentric_samples_lib_glsl[];
|
2017-05-20 13:16:14 +02:00
|
|
|
|
2018-11-15 14:44:45 +01:00
|
|
|
/* Prototypes */
|
2018-01-09 18:01:56 +01:00
|
|
|
static void eevee_light_setup(Object *ob, EEVEE_Light *evli);
|
2018-11-15 14:44:45 +01:00
|
|
|
static float light_attenuation_radius_get(Lamp *la, float light_threshold);
|
2018-01-09 18:01:56 +01:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* *********** LIGHT BITS *********** */
|
2018-05-11 07:48:52 +02:00
|
|
|
static void lightbits_set_single(EEVEE_LightBits *bitf, uint idx, bool val)
|
2018-01-11 14:08:21 +01:00
|
|
|
{
|
|
|
|
if (val) {
|
|
|
|
bitf->fields[idx / 8] |= (1 << (idx % 8));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bitf->fields[idx / 8] &= ~(1 << (idx % 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lightbits_set_all(EEVEE_LightBits *bitf, bool val)
|
|
|
|
{
|
|
|
|
memset(bitf, (val) ? 0xFF : 0x00, sizeof(EEVEE_LightBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lightbits_or(EEVEE_LightBits *r, const EEVEE_LightBits *v)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_LIGHTBITS_FIELDS; ++i) {
|
|
|
|
r->fields[i] |= v->fields[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 07:48:52 +02:00
|
|
|
static bool lightbits_get(const EEVEE_LightBits *r, uint idx)
|
2018-01-11 14:08:21 +01:00
|
|
|
{
|
|
|
|
return r->fields[idx / 8] & (1 << (idx % 8));
|
|
|
|
}
|
|
|
|
|
2018-05-26 10:41:25 +02:00
|
|
|
static void lightbits_convert(
|
|
|
|
EEVEE_LightBits *r, const EEVEE_LightBits *bitf, const int *light_bit_conv_table, uint table_length)
|
2018-01-11 14:08:21 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < table_length; ++i) {
|
|
|
|
if (lightbits_get(bitf, i) != 0) {
|
|
|
|
if (light_bit_conv_table[i] >= 0) {
|
|
|
|
r->fields[i / 8] |= (1 << (i % 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 12:06:17 +02:00
|
|
|
/* *********** FUNCTIONS *********** */
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
void EEVEE_lights_init(EEVEE_ViewLayerData *sldata)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2018-05-11 07:48:52 +02:00
|
|
|
const uint shadow_ubo_size = sizeof(EEVEE_Shadow) * MAX_SHADOW +
|
2017-09-05 21:02:17 +02:00
|
|
|
sizeof(EEVEE_ShadowCube) * MAX_SHADOW_CUBE +
|
2017-04-10 12:06:17 +02:00
|
|
|
sizeof(EEVEE_ShadowCascade) * MAX_SHADOW_CASCADE;
|
|
|
|
|
2017-09-01 15:59:01 +02:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2018-05-16 19:34:24 +02:00
|
|
|
const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph);
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2017-05-20 13:16:14 +02:00
|
|
|
if (!e_data.shadow_sh) {
|
|
|
|
e_data.shadow_sh = DRW_shader_create(
|
2018-04-15 22:22:50 +02:00
|
|
|
datatoc_shadow_vert_glsl, NULL, datatoc_shadow_frag_glsl, NULL);
|
2017-05-20 13:16:14 +02:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:29:20 +02:00
|
|
|
if (!sldata->lamps) {
|
|
|
|
sldata->lamps = MEM_callocN(sizeof(EEVEE_LampsInfo), "EEVEE_LampsInfo");
|
|
|
|
sldata->light_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_Light) * MAX_LIGHT, NULL);
|
|
|
|
sldata->shadow_ubo = DRW_uniformbuffer_create(shadow_ubo_size, NULL);
|
|
|
|
sldata->shadow_render_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_ShadowRender), NULL);
|
2018-01-11 14:08:21 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
sldata->shcasters_buffers[i].shadow_casters = MEM_callocN(sizeof(EEVEE_ShadowCaster) * SHADOW_CASTER_ALLOC_CHUNK, "EEVEE_ShadowCaster buf");
|
|
|
|
sldata->shcasters_buffers[i].flags = MEM_callocN(sizeof(sldata->shcasters_buffers[0].flags) * SHADOW_CASTER_ALLOC_CHUNK, "EEVEE_shcast_buffer flags buf");
|
|
|
|
sldata->shcasters_buffers[i].alloc_count = SHADOW_CASTER_ALLOC_CHUNK;
|
|
|
|
sldata->shcasters_buffers[i].count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sldata->lamps->shcaster_frontbuffer = &sldata->shcasters_buffers[0];
|
|
|
|
sldata->lamps->shcaster_backbuffer = &sldata->shcasters_buffers[1];
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Flip buffers */
|
|
|
|
SWAP(EEVEE_ShadowCasterBuffer *, sldata->lamps->shcaster_frontbuffer, sldata->lamps->shcaster_backbuffer);
|
|
|
|
|
2018-05-16 19:34:24 +02:00
|
|
|
const int sh_method = scene_eval->eevee.shadow_method;
|
|
|
|
int sh_cube_size = scene_eval->eevee.shadow_cube_size;
|
|
|
|
int sh_cascade_size = scene_eval->eevee.shadow_cascade_size;
|
|
|
|
const bool sh_high_bitdepth = (scene_eval->eevee.flag & SCE_EEVEE_SHADOW_HIGH_BITDEPTH) != 0;
|
2018-10-28 21:41:40 +01:00
|
|
|
sldata->lamps->soft_shadows = (scene_eval->eevee.flag & SCE_EEVEE_SHADOW_SOFT) != 0;
|
2017-09-01 15:59:01 +02:00
|
|
|
|
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
2018-05-04 14:39:05 +02:00
|
|
|
if ((linfo->shadow_cube_size != sh_cube_size) ||
|
2017-10-07 15:57:14 +11:00
|
|
|
(linfo->shadow_method != sh_method) ||
|
|
|
|
(linfo->shadow_high_bitdepth != sh_high_bitdepth))
|
2017-09-02 02:27:28 +02:00
|
|
|
{
|
2018-05-04 15:42:06 +02:00
|
|
|
BLI_assert((sh_cube_size > 0) && (sh_cube_size <= 4096));
|
2018-05-04 14:39:05 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
|
2017-09-02 02:27:28 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
|
2017-09-09 21:11:22 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_blur);
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2018-05-04 15:59:01 +02:00
|
|
|
/* Compute adequate size for the octahedral map. */
|
2018-07-10 15:02:25 +02:00
|
|
|
linfo->shadow_cube_store_size = OCTAHEDRAL_SIZE_FROM_CUBESIZE(sh_cube_size);
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2018-05-04 15:59:01 +02:00
|
|
|
CLAMP(linfo->shadow_cube_store_size, 1, 4096);
|
2018-05-04 15:42:06 +02:00
|
|
|
CLAMP(sh_cube_size, 1, 4096);
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2018-05-04 15:59:01 +02:00
|
|
|
linfo->shadow_render_data.cube_texel_size = 1.0f / sh_cube_size;
|
2017-09-01 15:59:01 +02:00
|
|
|
}
|
2018-04-08 14:31:41 +02:00
|
|
|
|
2018-05-04 14:39:05 +02:00
|
|
|
if ((linfo->shadow_cascade_size != sh_cascade_size) ||
|
|
|
|
(linfo->shadow_method != sh_method) ||
|
|
|
|
(linfo->shadow_high_bitdepth != sh_high_bitdepth))
|
|
|
|
{
|
2018-05-04 15:42:06 +02:00
|
|
|
BLI_assert((sh_cascade_size > 0) && (sh_cascade_size <= 4096));
|
2018-05-04 14:39:05 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
|
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_target);
|
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_blur);
|
2018-05-04 15:42:06 +02:00
|
|
|
|
|
|
|
CLAMP(sh_cascade_size, 1, 4096);
|
2018-05-04 14:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
linfo->shadow_high_bitdepth = sh_high_bitdepth;
|
|
|
|
linfo->shadow_method = sh_method;
|
|
|
|
linfo->shadow_cube_size = sh_cube_size;
|
|
|
|
linfo->shadow_cascade_size = sh_cascade_size;
|
|
|
|
|
2018-04-08 14:31:41 +02:00
|
|
|
/* only compile the ones needed. reduce startup time. */
|
2018-06-03 22:47:01 +02:00
|
|
|
if ((sh_method == SHADOW_ESM) && !e_data.shadow_copy_cube_sh[SHADOW_ESM]) {
|
2018-04-08 14:31:41 +02:00
|
|
|
e_data.shadow_copy_cube_sh[SHADOW_ESM] = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_shadow_copy_frag_glsl,
|
|
|
|
"#define ESM\n"
|
|
|
|
"#define COPY\n");
|
|
|
|
e_data.shadow_copy_cascade_sh[SHADOW_ESM] = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_shadow_copy_frag_glsl,
|
|
|
|
"#define ESM\n"
|
|
|
|
"#define COPY\n"
|
|
|
|
"#define CSM\n");
|
|
|
|
}
|
2018-06-03 22:47:01 +02:00
|
|
|
else if ((sh_method == SHADOW_VSM) && !e_data.shadow_copy_cube_sh[SHADOW_VSM]) {
|
2018-04-08 14:31:41 +02:00
|
|
|
e_data.shadow_copy_cube_sh[SHADOW_VSM] = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_shadow_copy_frag_glsl,
|
|
|
|
"#define VSM\n"
|
|
|
|
"#define COPY\n");
|
|
|
|
e_data.shadow_copy_cascade_sh[SHADOW_VSM] = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_shadow_copy_frag_glsl,
|
|
|
|
"#define VSM\n"
|
|
|
|
"#define COPY\n"
|
|
|
|
"#define CSM\n");
|
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2018-06-03 22:47:01 +02:00
|
|
|
static GPUShader *eevee_lights_get_store_sh(int shadow_method, bool high_blur, bool cascade)
|
|
|
|
{
|
|
|
|
GPUShader **shader;
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
shader = (high_blur) ? &e_data.shadow_store_cascade_high_sh[shadow_method]
|
|
|
|
: &e_data.shadow_store_cascade_sh[shadow_method];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
shader = (high_blur) ? &e_data.shadow_store_cube_high_sh[shadow_method]
|
|
|
|
: &e_data.shadow_store_cube_sh[shadow_method];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*shader == NULL) {
|
|
|
|
DynStr *ds_frag = BLI_dynstr_new();
|
|
|
|
BLI_dynstr_append(ds_frag, datatoc_concentric_samples_lib_glsl);
|
|
|
|
BLI_dynstr_append(ds_frag, datatoc_shadow_store_frag_glsl);
|
|
|
|
char *store_shadow_shader_str = BLI_dynstr_get_cstring(ds_frag);
|
|
|
|
BLI_dynstr_free(ds_frag);
|
|
|
|
|
|
|
|
ds_frag = BLI_dynstr_new();
|
|
|
|
BLI_dynstr_append(ds_frag, (shadow_method == SHADOW_VSM) ? "#define VSM\n" : "#define ESM\n");
|
|
|
|
if (high_blur) BLI_dynstr_append(ds_frag, "#define HIGH_BLUR\n");
|
|
|
|
if (cascade) BLI_dynstr_append(ds_frag, "#define CSM\n");
|
|
|
|
char *define_str = BLI_dynstr_get_cstring(ds_frag);
|
|
|
|
BLI_dynstr_free(ds_frag);
|
|
|
|
|
|
|
|
*shader = DRW_shader_create_fullscreen(
|
|
|
|
store_shadow_shader_str, define_str);
|
|
|
|
|
|
|
|
MEM_freeN(store_shadow_shader_str);
|
|
|
|
MEM_freeN(define_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *shader;
|
|
|
|
}
|
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
static DRWPass *eevee_lights_cube_store_pass_get(EEVEE_PassList *psl, EEVEE_ViewLayerData *sldata, int shadow_method, int shadow_samples_len)
|
2018-06-03 22:47:01 +02:00
|
|
|
{
|
2018-07-08 12:45:53 +02:00
|
|
|
bool high_blur = shadow_samples_len > 16;
|
2018-06-03 22:47:01 +02:00
|
|
|
DRWPass **pass = (high_blur) ? &psl->shadow_cube_store_pass : &psl->shadow_cube_store_high_pass;
|
|
|
|
if (*pass == NULL) {
|
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
|
|
|
*pass = DRW_pass_create("Shadow Cube Storage Pass", DRW_STATE_WRITE_COLOR);
|
|
|
|
GPUShader *shader = eevee_lights_get_store_sh(shadow_method, high_blur, false);
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(shader, *pass);
|
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cube_blur);
|
|
|
|
DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
|
|
|
|
DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
|
|
|
|
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
|
|
|
|
}
|
|
|
|
return *pass;
|
|
|
|
}
|
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
static DRWPass *eevee_lights_cascade_store_pass_get(EEVEE_PassList *psl, EEVEE_ViewLayerData *sldata, int shadow_method, int shadow_samples_len)
|
2018-06-03 22:47:01 +02:00
|
|
|
{
|
2018-07-08 12:45:53 +02:00
|
|
|
bool high_blur = shadow_samples_len > 16;
|
2018-06-03 22:47:01 +02:00
|
|
|
DRWPass **pass = (high_blur) ? &psl->shadow_cascade_store_pass : &psl->shadow_cascade_store_high_pass;
|
|
|
|
if (*pass == NULL) {
|
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
|
|
|
*pass = DRW_pass_create("Shadow Cascade Storage Pass", DRW_STATE_WRITE_COLOR);
|
|
|
|
GPUShader *shader = eevee_lights_get_store_sh(shadow_method, high_blur, true);
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(shader, *pass);
|
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cascade_blur);
|
|
|
|
DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
|
|
|
|
DRW_shgroup_uniform_int(grp, "cascadeId", &linfo->current_shadow_cascade, 1);
|
|
|
|
DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
|
|
|
|
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
|
|
|
|
}
|
|
|
|
return *pass;
|
|
|
|
}
|
|
|
|
|
2018-03-01 19:27:38 +01:00
|
|
|
void EEVEE_lights_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
2018-03-01 19:27:38 +01:00
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
EEVEE_PassList *psl = vedata->psl;
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
linfo->shcaster_frontbuffer->count = 0;
|
2017-09-05 21:02:17 +02:00
|
|
|
linfo->num_light = 0;
|
2018-05-04 14:39:05 +02:00
|
|
|
linfo->num_cube_layer = 0;
|
|
|
|
linfo->num_cascade_layer = 0;
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->gpu_cube_len = linfo->gpu_cascade_len = linfo->gpu_shadow_len = 0;
|
|
|
|
linfo->cpu_cube_len = linfo->cpu_cascade_len = 0;
|
2017-04-10 12:06:17 +02:00
|
|
|
memset(linfo->light_ref, 0, sizeof(linfo->light_ref));
|
|
|
|
memset(linfo->shadow_cube_ref, 0, sizeof(linfo->shadow_cube_ref));
|
|
|
|
memset(linfo->shadow_cascade_ref, 0, sizeof(linfo->shadow_cascade_ref));
|
2018-01-11 14:08:21 +01:00
|
|
|
memset(linfo->new_shadow_id, -1, sizeof(linfo->new_shadow_id));
|
|
|
|
|
|
|
|
/* Shadow Casters: Reset flags. */
|
|
|
|
memset(linfo->shcaster_backbuffer->flags, (char)SHADOW_CASTER_PRUNED, linfo->shcaster_backbuffer->alloc_count);
|
|
|
|
memset(linfo->shcaster_frontbuffer->flags, 0x00, linfo->shcaster_frontbuffer->alloc_count);
|
2017-05-20 13:16:14 +02:00
|
|
|
|
2018-06-03 22:47:01 +02:00
|
|
|
psl->shadow_cube_store_pass = NULL;
|
|
|
|
psl->shadow_cube_store_high_pass = NULL;
|
|
|
|
psl->shadow_cascade_store_pass = NULL;
|
|
|
|
psl->shadow_cascade_store_high_pass = NULL;
|
2017-05-20 13:16:14 +02:00
|
|
|
|
2017-09-08 20:21:57 +02:00
|
|
|
{
|
|
|
|
psl->shadow_cube_copy_pass = DRW_pass_create("Shadow Copy Pass", DRW_STATE_WRITE_COLOR);
|
|
|
|
|
2017-11-20 14:28:24 +11:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(
|
|
|
|
e_data.shadow_copy_cube_sh[linfo->shadow_method], psl->shadow_cube_copy_pass);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cube_target);
|
2017-09-08 20:21:57 +02:00
|
|
|
DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
|
|
|
|
DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
|
|
|
|
DRW_shgroup_uniform_int(grp, "faceId", &linfo->current_shadow_face, 1);
|
|
|
|
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
psl->shadow_cascade_copy_pass = DRW_pass_create("Shadow Cascade Copy Pass", DRW_STATE_WRITE_COLOR);
|
|
|
|
|
2017-11-20 14:28:24 +11:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(
|
|
|
|
e_data.shadow_copy_cascade_sh[linfo->shadow_method], psl->shadow_cascade_copy_pass);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cascade_target);
|
2017-09-08 20:21:57 +02:00
|
|
|
DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
|
|
|
|
DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
|
|
|
|
DRW_shgroup_uniform_int(grp, "cascadeId", &linfo->current_shadow_cascade, 1);
|
|
|
|
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
|
|
|
|
}
|
|
|
|
|
2017-05-20 13:16:14 +02:00
|
|
|
{
|
2018-05-20 19:05:13 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
|
2018-03-01 19:27:38 +01:00
|
|
|
psl->shadow_pass = DRW_pass_create("Shadow Pass", state);
|
2017-05-20 13:16:14 +02:00
|
|
|
|
2018-04-15 22:22:50 +02:00
|
|
|
stl->g_data->shadow_shgrp = DRW_shgroup_create(e_data.shadow_sh, psl->shadow_pass);
|
2017-05-20 13:16:14 +02:00
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
void EEVEE_lights_cache_add(EEVEE_ViewLayerData *sldata, Object *ob)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2018-11-15 14:44:45 +01:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
const float threshold = draw_ctx->scene->eevee.light_threshold;
|
|
|
|
|
2017-04-10 12:06:17 +02:00
|
|
|
/* Step 1 find all lamps in the scene and setup them */
|
2017-09-12 13:13:20 +02:00
|
|
|
if (linfo->num_light >= MAX_LIGHT) {
|
2018-06-27 14:41:53 +02:00
|
|
|
printf("Too many lights in the scene !!!\n");
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
else {
|
|
|
|
Lamp *la = (Lamp *)ob->data;
|
2018-01-09 18:01:56 +01:00
|
|
|
EEVEE_Light *evli = linfo->light_data + linfo->num_light;
|
|
|
|
eevee_light_setup(ob, evli);
|
|
|
|
|
|
|
|
/* We do not support shadowmaps for dupli lamps. */
|
|
|
|
if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
|
|
|
|
linfo->num_light++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
|
2017-06-01 18:20:44 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Save previous shadow id. */
|
|
|
|
int prev_cube_sh_id = led->prev_cube_shadow_id;
|
|
|
|
|
|
|
|
/* Default light without shadows */
|
|
|
|
led->data.ld.shadow_id = -1;
|
|
|
|
led->prev_cube_shadow_id = -1;
|
2017-04-10 12:06:17 +02:00
|
|
|
|
2018-04-24 12:11:31 +02:00
|
|
|
if (la->mode & LA_SHADOW) {
|
2017-10-07 15:57:14 +11:00
|
|
|
if (la->type == LA_SUN) {
|
2018-05-04 19:24:02 +02:00
|
|
|
int cascade_nbr = la->cascade_count;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2018-10-31 21:14:32 +01:00
|
|
|
if ((linfo->gpu_cascade_len + 1) <= MAX_SHADOW_CASCADE) {
|
2017-09-05 21:02:17 +02:00
|
|
|
/* Save Light object. */
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->shadow_cascade_ref[linfo->cpu_cascade_len] = ob;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Store indices. */
|
|
|
|
EEVEE_ShadowCascadeData *data = &led->data.scad;
|
2018-07-08 12:45:53 +02:00
|
|
|
data->shadow_id = linfo->gpu_shadow_len;
|
|
|
|
data->cascade_id = linfo->gpu_cascade_len;
|
2018-05-04 14:39:05 +02:00
|
|
|
data->layer_id = linfo->num_cascade_layer;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
|
|
|
/* Increment indices. */
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->gpu_shadow_len += 1;
|
2018-10-31 19:44:01 +01:00
|
|
|
linfo->gpu_cascade_len += 1;
|
|
|
|
linfo->num_cascade_layer += cascade_nbr;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->cpu_cascade_len += 1;
|
2017-09-05 21:02:17 +02:00
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2017-09-05 21:02:17 +02:00
|
|
|
else if (la->type == LA_SPOT || la->type == LA_LOCAL || la->type == LA_AREA) {
|
2018-10-31 19:44:01 +01:00
|
|
|
if ((linfo->gpu_cube_len + 1) <= MAX_SHADOW_CUBE) {
|
2017-09-05 21:02:17 +02:00
|
|
|
/* Save Light object. */
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->shadow_cube_ref[linfo->cpu_cube_len] = ob;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* For light update tracking. */
|
|
|
|
if ((prev_cube_sh_id >= 0) &&
|
2018-02-15 18:03:55 +11:00
|
|
|
(prev_cube_sh_id < linfo->shcaster_backbuffer->count))
|
2018-01-11 14:08:21 +01:00
|
|
|
{
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->new_shadow_id[prev_cube_sh_id] = linfo->cpu_cube_len;
|
2018-01-11 14:08:21 +01:00
|
|
|
}
|
2018-07-08 12:45:53 +02:00
|
|
|
led->prev_cube_shadow_id = linfo->cpu_cube_len;
|
2018-01-11 14:08:21 +01:00
|
|
|
|
|
|
|
/* Saving lamp bounds for later. */
|
2018-07-08 12:45:53 +02:00
|
|
|
BLI_assert(linfo->cpu_cube_len >= 0 && linfo->cpu_cube_len < MAX_LIGHT);
|
|
|
|
copy_v3_v3(linfo->shadow_bounds[linfo->cpu_cube_len].center, ob->obmat[3]);
|
2018-11-15 14:44:45 +01:00
|
|
|
linfo->shadow_bounds[linfo->cpu_cube_len].radius = light_attenuation_radius_get(la, threshold);
|
2018-01-11 14:08:21 +01:00
|
|
|
|
|
|
|
EEVEE_ShadowCubeData *data = &led->data.scd;
|
|
|
|
/* Store indices. */
|
2018-07-08 12:45:53 +02:00
|
|
|
data->shadow_id = linfo->gpu_shadow_len;
|
|
|
|
data->cube_id = linfo->gpu_cube_len;
|
2018-05-04 14:39:05 +02:00
|
|
|
data->layer_id = linfo->num_cube_layer;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
|
|
|
/* Increment indices. */
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->gpu_shadow_len += 1;
|
2018-10-31 19:44:01 +01:00
|
|
|
linfo->gpu_cube_len += 1;
|
|
|
|
linfo->num_cube_layer += 1;
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
linfo->cpu_cube_len += 1;
|
2017-09-05 21:02:17 +02:00
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
led->data.ld.light_id = linfo->num_light;
|
2017-04-10 12:06:17 +02:00
|
|
|
linfo->light_ref[linfo->num_light] = ob;
|
|
|
|
linfo->num_light++;
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 13:16:14 +02:00
|
|
|
/* Add a shadow caster to the shadowpasses */
|
2017-11-20 14:28:24 +11:00
|
|
|
void EEVEE_lights_cache_shcaster_add(
|
2018-07-18 00:12:21 +02:00
|
|
|
EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_StorageList *stl, struct GPUBatch *geom, Object *ob)
|
2017-05-20 13:16:14 +02:00
|
|
|
{
|
2018-04-15 22:22:50 +02:00
|
|
|
DRW_shgroup_call_object_add(
|
2018-03-01 19:27:38 +01:00
|
|
|
stl->g_data->shadow_shgrp,
|
2018-04-15 22:22:50 +02:00
|
|
|
geom, ob);
|
2017-05-20 13:16:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 01:10:57 +02:00
|
|
|
void EEVEE_lights_cache_shcaster_material_add(
|
2018-09-10 18:05:00 +02:00
|
|
|
EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl, struct GPUMaterial *gpumat,
|
2018-07-18 00:12:21 +02:00
|
|
|
struct GPUBatch *geom, struct Object *ob, float *alpha_threshold)
|
2017-07-11 01:10:57 +02:00
|
|
|
{
|
2018-03-01 19:27:38 +01:00
|
|
|
/* TODO / PERF : reuse the same shading group for objects with the same material */
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_material_create(gpumat, psl->shadow_pass);
|
2017-07-11 12:42:59 +02:00
|
|
|
|
|
|
|
if (grp == NULL) return;
|
|
|
|
|
2018-09-10 18:05:00 +02:00
|
|
|
/* Grrr needed for correctness but not 99% of the time not needed.
|
|
|
|
* TODO detect when needed? */
|
|
|
|
DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
|
|
|
|
DRW_shgroup_uniform_block(grp, "grid_block", sldata->grid_ubo);
|
|
|
|
DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
|
|
|
|
DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
|
|
|
|
DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
|
|
|
|
DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
|
|
|
|
|
2017-07-11 01:10:57 +02:00
|
|
|
if (alpha_threshold != NULL)
|
|
|
|
DRW_shgroup_uniform_float(grp, "alphaThreshold", alpha_threshold, 1);
|
|
|
|
|
2018-04-15 22:22:50 +02:00
|
|
|
DRW_shgroup_call_object_add(grp, geom, ob);
|
2017-07-11 01:10:57 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Make that object update shadow casting lamps inside its influence bounding box. */
|
|
|
|
void EEVEE_lights_cache_shcaster_object_add(EEVEE_ViewLayerData *sldata, Object *ob)
|
|
|
|
{
|
|
|
|
if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
|
|
|
|
/* TODO: Special case for dupli objects because we cannot save the object pointer. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EEVEE_ObjectEngineData *oedata = EEVEE_object_data_ensure(ob);
|
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
|
|
|
EEVEE_ShadowCasterBuffer *backbuffer = linfo->shcaster_backbuffer;
|
|
|
|
EEVEE_ShadowCasterBuffer *frontbuffer = linfo->shcaster_frontbuffer;
|
|
|
|
int past_id = oedata->shadow_caster_id;
|
|
|
|
|
|
|
|
/* Update flags in backbuffer. */
|
|
|
|
if (past_id > -1 && past_id < backbuffer->count) {
|
|
|
|
backbuffer->flags[past_id] &= ~SHADOW_CASTER_PRUNED;
|
|
|
|
|
|
|
|
if (oedata->need_update) {
|
|
|
|
backbuffer->flags[past_id] |= SHADOW_CASTER_UPDATED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update id. */
|
|
|
|
oedata->shadow_caster_id = frontbuffer->count++;
|
|
|
|
|
|
|
|
/* Make sure shadow_casters is big enough. */
|
|
|
|
if (oedata->shadow_caster_id >= frontbuffer->alloc_count) {
|
|
|
|
frontbuffer->alloc_count += SHADOW_CASTER_ALLOC_CHUNK;
|
|
|
|
frontbuffer->shadow_casters = MEM_reallocN(frontbuffer->shadow_casters, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
|
|
|
|
frontbuffer->flags = MEM_reallocN(frontbuffer->flags, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
EEVEE_ShadowCaster *shcaster = frontbuffer->shadow_casters + oedata->shadow_caster_id;
|
|
|
|
|
|
|
|
if (oedata->need_update) {
|
|
|
|
frontbuffer->flags[oedata->shadow_caster_id] = SHADOW_CASTER_UPDATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update World AABB in frontbuffer. */
|
|
|
|
BoundBox *bb = BKE_object_boundbox_get(ob);
|
|
|
|
float min[3], max[3];
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
float vec[3];
|
|
|
|
copy_v3_v3(vec, bb->vec[i]);
|
|
|
|
mul_m4_v3(ob->obmat, vec);
|
|
|
|
minmax_v3v3_v3(min, max, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
EEVEE_BoundBox *aabb = &shcaster->bbox;
|
|
|
|
add_v3_v3v3(aabb->center, min, max);
|
|
|
|
mul_v3_fl(aabb->center, 0.5f);
|
|
|
|
sub_v3_v3v3(aabb->halfdim, aabb->center, max);
|
|
|
|
|
|
|
|
aabb->halfdim[0] = fabsf(aabb->halfdim[0]);
|
|
|
|
aabb->halfdim[1] = fabsf(aabb->halfdim[1]);
|
|
|
|
aabb->halfdim[2] = fabsf(aabb->halfdim[2]);
|
|
|
|
|
|
|
|
oedata->need_update = false;
|
|
|
|
}
|
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
void EEVEE_lights_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
|
2017-04-10 12:06:17 +02:00
|
|
|
{
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
2018-04-30 16:02:24 +02:00
|
|
|
GPUTextureFormat shadow_pool_format = GPU_R32F;
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2018-01-21 17:25:10 +01:00
|
|
|
sldata->common_data.la_num_light = linfo->num_light;
|
|
|
|
|
2017-06-01 18:20:44 +02:00
|
|
|
/* Setup enough layers. */
|
|
|
|
/* Free textures if number mismatch. */
|
2018-05-04 14:39:05 +02:00
|
|
|
if (linfo->num_cube_layer != linfo->cache_num_cube_layer) {
|
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
|
|
|
|
linfo->cache_num_cube_layer = linfo->num_cube_layer;
|
|
|
|
linfo->update_flag |= LIGHT_UPDATE_SHADOW_CUBE;
|
|
|
|
}
|
|
|
|
|
2018-05-04 17:33:16 +02:00
|
|
|
if (linfo->num_cascade_layer != linfo->cache_num_cascade_layer) {
|
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
|
|
|
|
linfo->cache_num_cascade_layer = linfo->num_cascade_layer;
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
|
2017-09-01 18:39:39 +02:00
|
|
|
switch (linfo->shadow_method) {
|
2018-04-30 16:02:24 +02:00
|
|
|
case SHADOW_ESM: shadow_pool_format = ((linfo->shadow_high_bitdepth) ? GPU_R32F : GPU_R16F); break;
|
|
|
|
case SHADOW_VSM: shadow_pool_format = ((linfo->shadow_high_bitdepth) ? GPU_RG32F : GPU_RG16F); break;
|
2017-09-01 18:39:39 +02:00
|
|
|
default:
|
|
|
|
BLI_assert(!"Incorrect Shadow Method");
|
|
|
|
break;
|
|
|
|
}
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2018-05-04 14:39:05 +02:00
|
|
|
/* Cubemaps */
|
2017-09-01 15:59:01 +02:00
|
|
|
if (!sldata->shadow_cube_target) {
|
2017-11-20 14:28:24 +11:00
|
|
|
sldata->shadow_cube_target = DRW_texture_create_cube(
|
2018-05-04 15:59:01 +02:00
|
|
|
linfo->shadow_cube_size, GPU_DEPTH_COMPONENT24, 0, NULL);
|
2017-11-20 14:28:24 +11:00
|
|
|
sldata->shadow_cube_blur = DRW_texture_create_cube(
|
2018-05-04 15:59:01 +02:00
|
|
|
linfo->shadow_cube_size, shadow_pool_format, DRW_TEX_FILTER, NULL);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2018-05-04 14:39:05 +02:00
|
|
|
if (!sldata->shadow_cube_pool) {
|
|
|
|
sldata->shadow_cube_pool = DRW_texture_create_2D_array(
|
2018-05-04 17:33:16 +02:00
|
|
|
linfo->shadow_cube_store_size, linfo->shadow_cube_store_size, max_ii(1, linfo->num_cube_layer),
|
2018-05-04 14:39:05 +02:00
|
|
|
shadow_pool_format, DRW_TEX_FILTER, NULL);
|
|
|
|
}
|
2018-05-04 17:33:16 +02:00
|
|
|
GPU_framebuffer_ensure_config(&sldata->shadow_cube_target_fb, {
|
|
|
|
GPU_ATTACHMENT_TEXTURE(sldata->shadow_cube_target)
|
|
|
|
});
|
|
|
|
GPU_framebuffer_ensure_config(&sldata->shadow_cube_store_fb, {
|
|
|
|
GPU_ATTACHMENT_NONE,
|
|
|
|
GPU_ATTACHMENT_TEXTURE(sldata->shadow_cube_pool)
|
|
|
|
});
|
2017-09-01 15:59:01 +02:00
|
|
|
|
2018-05-04 14:39:05 +02:00
|
|
|
/* CSM */
|
2017-09-01 15:59:01 +02:00
|
|
|
if (!sldata->shadow_cascade_target) {
|
|
|
|
sldata->shadow_cascade_target = DRW_texture_create_2D_array(
|
2018-05-04 14:39:05 +02:00
|
|
|
linfo->shadow_cascade_size, linfo->shadow_cascade_size, MAX_CASCADE_NUM, GPU_DEPTH_COMPONENT24, 0, NULL);
|
2017-09-08 20:21:57 +02:00
|
|
|
sldata->shadow_cascade_blur = DRW_texture_create_2D_array(
|
2018-05-04 14:39:05 +02:00
|
|
|
linfo->shadow_cascade_size, linfo->shadow_cascade_size, MAX_CASCADE_NUM, shadow_pool_format, DRW_TEX_FILTER, NULL);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2018-05-04 14:39:05 +02:00
|
|
|
if (!sldata->shadow_cascade_pool) {
|
|
|
|
sldata->shadow_cascade_pool = DRW_texture_create_2D_array(
|
2018-05-04 17:33:16 +02:00
|
|
|
linfo->shadow_cascade_size, linfo->shadow_cascade_size, max_ii(1, linfo->num_cascade_layer),
|
2017-09-01 15:59:01 +02:00
|
|
|
shadow_pool_format, DRW_TEX_FILTER, NULL);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_ensure_config(&sldata->shadow_cascade_target_fb, {
|
|
|
|
GPU_ATTACHMENT_TEXTURE(sldata->shadow_cascade_target)
|
|
|
|
});
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_framebuffer_ensure_config(&sldata->shadow_cascade_store_fb, {
|
|
|
|
GPU_ATTACHMENT_NONE,
|
|
|
|
GPU_ATTACHMENT_TEXTURE(sldata->shadow_cascade_pool)
|
2018-03-25 17:46:48 +02:00
|
|
|
});
|
2017-06-01 18:20:44 +02:00
|
|
|
|
|
|
|
/* Update Lamps UBOs. */
|
2018-10-28 21:41:40 +01:00
|
|
|
EEVEE_lights_update(sldata, vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2018-11-15 14:44:45 +01:00
|
|
|
float light_attenuation_radius_get(Lamp *la, float light_threshold)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2018-11-15 14:44:45 +01:00
|
|
|
if (la->mode & LA_CUSTOM_ATTENUATION)
|
|
|
|
return la->att_dist;
|
|
|
|
|
|
|
|
/* Compute max light power. */
|
|
|
|
float power = max_fff(la->r, la->g, la->b);
|
|
|
|
power *= fabsf(la->energy);
|
|
|
|
power *= max_ff(1.0f, la->spec_fac);
|
|
|
|
/* Compute the distance (using the inverse square law)
|
|
|
|
* at which the light power reaches the light_threshold. */
|
|
|
|
float distance = sqrtf(max_ff(1e-16, power / max_ff(1e-16, light_threshold)));
|
|
|
|
return distance;
|
|
|
|
}
|
2017-03-28 00:09:45 +02:00
|
|
|
|
2018-11-15 14:44:45 +01:00
|
|
|
static void light_shape_parameters_set(EEVEE_Light *evli, const Lamp *la, float scale[3])
|
|
|
|
{
|
2017-04-10 12:06:17 +02:00
|
|
|
if (la->type == LA_SPOT) {
|
2018-11-15 14:44:45 +01:00
|
|
|
/* Spot size & blend */
|
2017-04-10 12:06:17 +02:00
|
|
|
evli->sizex = scale[0] / scale[2];
|
|
|
|
evli->sizey = scale[1] / scale[2];
|
|
|
|
evli->spotsize = cosf(la->spotsize * 0.5f);
|
|
|
|
evli->spotblend = (1.0f - evli->spotsize) * la->spotblend;
|
2017-04-27 22:27:41 +02:00
|
|
|
evli->radius = max_ff(0.001f, la->area_size);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
else if (la->type == LA_AREA) {
|
2018-10-09 19:07:52 +02:00
|
|
|
evli->sizex = max_ff(0.003f, la->area_size * scale[0] * 0.5f);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
if (ELEM(la->area_shape, LA_AREA_RECT, LA_AREA_ELLIPSE)) {
|
2018-10-09 19:07:52 +02:00
|
|
|
evli->sizey = max_ff(0.003f, la->area_sizey * scale[1] * 0.5f);
|
2017-03-29 23:45:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-10-09 19:07:52 +02:00
|
|
|
evli->sizey = max_ff(0.003f, la->area_size * scale[1] * 0.5f);
|
2017-03-29 23:45:07 +02:00
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-04-27 22:27:41 +02:00
|
|
|
evli->radius = max_ff(0.001f, la->area_size);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2018-11-15 14:44:45 +01:00
|
|
|
}
|
2017-03-28 00:09:45 +02:00
|
|
|
|
2018-11-15 14:44:45 +01:00
|
|
|
static float light_shape_power_get(const Lamp *la, const EEVEE_Light *evli)
|
|
|
|
{
|
|
|
|
float power;
|
2017-04-10 12:06:17 +02:00
|
|
|
/* Make illumination power constant */
|
|
|
|
if (la->type == LA_AREA) {
|
2017-10-07 15:57:14 +11:00
|
|
|
power = 1.0f / (evli->sizex * evli->sizey * 4.0f * M_PI) * /* 1/(w*h*Pi) */
|
|
|
|
80.0f; /* XXX : Empirical, Fit cycles power */
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
if (ELEM(la->area_shape, LA_AREA_DISK, LA_AREA_ELLIPSE)) {
|
2018-09-19 18:19:49 +02:00
|
|
|
/* Scale power to account for the lower area of the ellipse compared to the surrounding rectangle. */
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
power *= 4.0f / M_PI;
|
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
else if (la->type == LA_SPOT || la->type == LA_LOCAL) {
|
2017-10-07 15:57:14 +11:00
|
|
|
power = 1.0f / (4.0f * evli->radius * evli->radius * M_PI * M_PI) * /* 1/(4*r²*Pi²) */
|
2018-01-18 21:51:23 +01:00
|
|
|
M_PI * M_PI * 10.0; /* XXX : Empirical, Fit cycles power */
|
2017-03-31 01:07:30 +02:00
|
|
|
|
2017-04-10 12:06:17 +02:00
|
|
|
/* for point lights (a.k.a radius == 0.0) */
|
|
|
|
// power = M_PI * M_PI * 0.78; /* XXX : Empirical, Fit cycles power */
|
|
|
|
}
|
|
|
|
else {
|
2018-11-14 15:54:10 +01:00
|
|
|
power = 1.0f / (evli->radius * evli->radius * M_PI); /* 1/(r²*Pi) */
|
2018-11-14 15:46:40 +01:00
|
|
|
/* Make illumation power closer to cycles for bigger radii. Cycles uses a cos^3 term that we cannot reproduce
|
|
|
|
* so we account for that by scaling the light power. This function is the result of a rough manual fitting. */
|
2018-11-15 14:44:45 +01:00
|
|
|
power += 1.0f / (2.0f * M_PI); /* power *= 1 + r²/2 */
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2018-11-15 14:44:45 +01:00
|
|
|
return power;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update buffer with lamp data */
|
|
|
|
static void eevee_light_setup(Object *ob, EEVEE_Light *evli)
|
|
|
|
{
|
|
|
|
Lamp *la = (Lamp *)ob->data;
|
|
|
|
float mat[4][4], scale[3], power, att_radius;
|
|
|
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
const float light_threshold = draw_ctx->scene->eevee.light_threshold;
|
|
|
|
|
|
|
|
/* Position */
|
|
|
|
copy_v3_v3(evli->position, ob->obmat[3]);
|
|
|
|
|
|
|
|
/* Color */
|
|
|
|
copy_v3_v3(evli->color, &la->r);
|
|
|
|
|
|
|
|
evli->spec = la->spec_fac;
|
|
|
|
|
|
|
|
/* Influence Radius */
|
|
|
|
att_radius = light_attenuation_radius_get(la, light_threshold);
|
|
|
|
/* Take the inverse square of this distance. */
|
|
|
|
evli->invsqrdist = 1.0 / max_ff(1e-4f, att_radius * att_radius);
|
|
|
|
|
|
|
|
/* Vectors */
|
|
|
|
normalize_m4_m4_ex(mat, ob->obmat, scale);
|
|
|
|
copy_v3_v3(evli->forwardvec, mat[2]);
|
|
|
|
normalize_v3(evli->forwardvec);
|
|
|
|
negate_v3(evli->forwardvec);
|
|
|
|
|
|
|
|
copy_v3_v3(evli->rightvec, mat[0]);
|
|
|
|
normalize_v3(evli->rightvec);
|
|
|
|
|
|
|
|
copy_v3_v3(evli->upvec, mat[1]);
|
|
|
|
normalize_v3(evli->upvec);
|
|
|
|
|
|
|
|
light_shape_parameters_set(evli, la, scale);
|
|
|
|
|
|
|
|
/* Lamp Type */
|
|
|
|
evli->lamptype = (float)la->type;
|
|
|
|
if ((la->type == LA_AREA) && ELEM(la->area_shape, LA_AREA_DISK, LA_AREA_ELLIPSE)) {
|
|
|
|
evli->lamptype = LAMPTYPE_AREA_ELLIPSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
power = light_shape_power_get(la, evli);
|
2017-05-11 14:32:03 +02:00
|
|
|
mul_v3_fl(evli->color, power * la->energy);
|
2017-04-10 12:06:17 +02:00
|
|
|
|
|
|
|
/* No shadow by default */
|
|
|
|
evli->shadowid = -1.0f;
|
|
|
|
}
|
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
/**
|
|
|
|
* Special ball distribution:
|
|
|
|
* Point are distributed in a way that when they are orthogonaly
|
|
|
|
* projected into any plane, the resulting distribution is (close to)
|
|
|
|
* a uniform disc distribution.
|
|
|
|
**/
|
|
|
|
static void sample_ball(int sample_ofs, float radius, float rsample[3])
|
|
|
|
{
|
|
|
|
double ht_point[3];
|
|
|
|
double ht_offset[3] = {0.0, 0.0, 0.0};
|
|
|
|
uint ht_primes[3] = {2, 3, 7};
|
|
|
|
|
|
|
|
BLI_halton_3D(ht_primes, ht_offset, sample_ofs, ht_point);
|
|
|
|
|
|
|
|
float omega = ht_point[1] * 2.0f * M_PI;
|
|
|
|
|
|
|
|
rsample[2] = ht_point[0] * 2.0f - 1.0f; /* cos theta */
|
|
|
|
|
2018-10-29 10:24:42 +11:00
|
|
|
float r = sqrtf(fmaxf(0.0f, 1.0f - rsample[2] * rsample[2])); /* sin theta */
|
2018-10-28 21:41:40 +01:00
|
|
|
|
|
|
|
rsample[0] = r * cosf(omega);
|
|
|
|
rsample[1] = r * sinf(omega);
|
|
|
|
|
|
|
|
radius *= sqrt(sqrt(ht_point[2]));
|
|
|
|
mul_v3_fl(rsample, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sample_rectangle(
|
|
|
|
int sample_ofs, float x_axis[3], float y_axis[3], float size_x, float size_y,
|
|
|
|
float rsample[3])
|
|
|
|
{
|
|
|
|
double ht_point[2];
|
|
|
|
double ht_offset[2] = {0.0, 0.0};
|
|
|
|
uint ht_primes[2] = {2, 3};
|
|
|
|
|
|
|
|
BLI_halton_2D(ht_primes, ht_offset, sample_ofs, ht_point);
|
|
|
|
|
|
|
|
/* Change ditribution center to be 0,0 */
|
|
|
|
ht_point[0] = (ht_point[0] > 0.5f) ? ht_point[0] - 1.0f : ht_point[0];
|
|
|
|
ht_point[1] = (ht_point[1] > 0.5f) ? ht_point[1] - 1.0f : ht_point[1];
|
|
|
|
|
|
|
|
zero_v3(rsample);
|
|
|
|
madd_v3_v3fl(rsample, x_axis, (ht_point[0] * 2.0f) * size_x);
|
|
|
|
madd_v3_v3fl(rsample, y_axis, (ht_point[1] * 2.0f) * size_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sample_ellipse(
|
|
|
|
int sample_ofs, float x_axis[3], float y_axis[3], float size_x, float size_y,
|
|
|
|
float rsample[3])
|
|
|
|
{
|
|
|
|
double ht_point[2];
|
|
|
|
double ht_offset[2] = {0.0, 0.0};
|
|
|
|
uint ht_primes[2] = {2, 3};
|
|
|
|
|
|
|
|
BLI_halton_2D(ht_primes, ht_offset, sample_ofs, ht_point);
|
|
|
|
|
|
|
|
/* Uniform disc sampling. */
|
|
|
|
float omega = ht_point[1] * 2.0f * M_PI;
|
|
|
|
float r = sqrtf(ht_point[0]);
|
|
|
|
ht_point[0] = r * cosf(omega) * size_x;
|
|
|
|
ht_point[1] = r * sinf(omega) * size_y;
|
|
|
|
|
|
|
|
zero_v3(rsample);
|
|
|
|
madd_v3_v3fl(rsample, x_axis, ht_point[0]);
|
|
|
|
madd_v3_v3fl(rsample, y_axis, ht_point[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void shadow_cube_random_position_set(
|
2018-10-29 10:24:42 +11:00
|
|
|
EEVEE_Light *evli, Lamp *la,
|
2018-10-28 21:41:40 +01:00
|
|
|
int sample_ofs,
|
|
|
|
float ws_sample_pos[3])
|
|
|
|
{
|
|
|
|
float jitter[3];
|
|
|
|
|
|
|
|
#ifndef DEBUG_SHADOW_DISTRIBUTION
|
|
|
|
int i = sample_ofs;
|
|
|
|
#else
|
2018-10-29 16:02:13 +01:00
|
|
|
for (int i = 0; i <= sample_ofs; ++i) {
|
2018-10-28 21:41:40 +01:00
|
|
|
#endif
|
|
|
|
switch (la->type) {
|
|
|
|
case LA_AREA:
|
|
|
|
if (ELEM(la->area_shape, LA_AREA_RECT, LA_AREA_SQUARE)) {
|
|
|
|
sample_rectangle(i, evli->rightvec, evli->upvec, evli->sizex, evli->sizey, jitter);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sample_ellipse(i, evli->rightvec, evli->upvec, evli->sizex, evli->sizey, jitter);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sample_ball(i, evli->radius, jitter);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_SHADOW_DISTRIBUTION
|
|
|
|
float p[3];
|
|
|
|
add_v3_v3v3(p, jitter, ws_sample_pos);
|
|
|
|
DRW_debug_sphere(p, 0.01f, (float[4]){1.0f, (sample_ofs == i) ? 1.0f : 0.0f, 0.0f, 1.0f});
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
add_v3_v3(ws_sample_pos, jitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eevee_shadow_cube_setup(Object *ob, EEVEE_LampsInfo *linfo, EEVEE_LampEngineData *led, int sample_ofs)
|
2017-04-10 12:06:17 +02:00
|
|
|
{
|
2018-01-11 14:08:21 +01:00
|
|
|
EEVEE_ShadowCubeData *sh_data = &led->data.scd;
|
2017-09-05 21:02:17 +02:00
|
|
|
EEVEE_Light *evli = linfo->light_data + sh_data->light_id;
|
|
|
|
EEVEE_Shadow *ubo_data = linfo->shadow_data + sh_data->shadow_id;
|
|
|
|
EEVEE_ShadowCube *cube_data = linfo->shadow_cube_data + sh_data->cube_id;
|
2017-04-10 12:06:17 +02:00
|
|
|
Lamp *la = (Lamp *)ob->data;
|
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
copy_v3_v3(cube_data->position, ob->obmat[3]);
|
2017-04-10 12:06:17 +02:00
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
if (linfo->soft_shadows) {
|
|
|
|
shadow_cube_random_position_set(evli, la, sample_ofs, cube_data->position);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
ubo_data->bias = 0.05f * la->bias;
|
|
|
|
ubo_data->near = la->clipsta;
|
2018-11-15 14:44:45 +01:00
|
|
|
ubo_data->far = 1.0f / (evli->invsqrdist * evli->invsqrdist);
|
2017-09-05 21:02:17 +02:00
|
|
|
ubo_data->exp = (linfo->shadow_method == SHADOW_VSM) ? la->bleedbias : la->bleedexp;
|
2017-04-10 12:06:17 +02:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
evli->shadowid = (float)(sh_data->shadow_id);
|
|
|
|
ubo_data->shadow_start = (float)(sh_data->layer_id);
|
|
|
|
ubo_data->data_start = (float)(sh_data->cube_id);
|
2017-11-22 04:51:21 +01:00
|
|
|
ubo_data->shadow_blur = la->soft * 0.02f; /* Used by translucence shadowmap blur */
|
2017-10-06 23:43:36 +02:00
|
|
|
|
|
|
|
ubo_data->contact_dist = (la->mode & LA_SHAD_CONTACT) ? la->contact_dist : 0.0f;
|
|
|
|
ubo_data->contact_bias = 0.05f * la->contact_bias;
|
|
|
|
ubo_data->contact_spread = la->contact_spread;
|
|
|
|
ubo_data->contact_thickness = la->contact_thickness;
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
static void shadow_cascade_random_matrix_set(float mat[4][4], float radius, int sample_ofs)
|
|
|
|
{
|
|
|
|
float jitter[3];
|
|
|
|
|
|
|
|
#ifndef DEBUG_SHADOW_DISTRIBUTION
|
|
|
|
int i = sample_ofs;
|
|
|
|
#else
|
2018-10-29 16:02:13 +01:00
|
|
|
for (int i = 0; i <= sample_ofs; ++i) {
|
2018-10-28 21:41:40 +01:00
|
|
|
#endif
|
|
|
|
sample_ellipse(i, mat[0], mat[1], radius, radius, jitter);
|
|
|
|
#ifdef DEBUG_SHADOW_DISTRIBUTION
|
|
|
|
float p[3];
|
|
|
|
add_v3_v3v3(p, jitter, mat[2]);
|
|
|
|
DRW_debug_sphere(p, 0.01f, (float[4]){1.0f, (sample_ofs == i) ? 1.0f : 0.0f, 0.0f, 1.0f});
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
add_v3_v3(mat[2], jitter);
|
|
|
|
orthogonalize_m4(mat, 2);
|
|
|
|
}
|
|
|
|
|
2017-04-20 13:07:24 +02:00
|
|
|
#define LERP(t, a, b) ((a) + (t) * ((b) - (a)))
|
|
|
|
|
2018-02-24 04:25:25 +01:00
|
|
|
static double round_to_digits(double value, int digits)
|
2017-04-21 16:43:14 +02:00
|
|
|
{
|
2018-02-24 04:25:25 +01:00
|
|
|
double factor = pow(10.0, digits - ceil(log10(fabs(value))));
|
|
|
|
return round(value * factor) / factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void frustum_min_bounding_sphere(const float corners[8][3], float r_center[3], float *r_radius)
|
|
|
|
{
|
|
|
|
#if 0 /* Simple solution but waste too much space. */
|
2017-04-21 16:43:14 +02:00
|
|
|
float minvec[3], maxvec[3];
|
|
|
|
|
|
|
|
/* compute the bounding box */
|
|
|
|
INIT_MINMAX(minvec, maxvec);
|
2017-10-07 15:57:14 +11:00
|
|
|
for (int i = 0; i < 8; ++i) {
|
2017-04-21 16:43:14 +02:00
|
|
|
minmax_v3v3_v3(minvec, maxvec, corners[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute the bounding sphere of this box */
|
|
|
|
r_radius = len_v3v3(minvec, maxvec) * 0.5f;
|
|
|
|
add_v3_v3v3(r_center, minvec, maxvec);
|
|
|
|
mul_v3_fl(r_center, 0.5f);
|
|
|
|
#else
|
2018-02-24 04:25:25 +01:00
|
|
|
/* Find averaged center. */
|
|
|
|
zero_v3(r_center);
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
add_v3_v3(r_center, corners[i]);
|
|
|
|
}
|
|
|
|
mul_v3_fl(r_center, 1.0f / 8.0f);
|
2017-04-21 16:43:14 +02:00
|
|
|
|
2018-02-24 04:25:25 +01:00
|
|
|
/* Search the largest distance from the sphere center. */
|
|
|
|
*r_radius = 0.0f;
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
float rad = len_squared_v3v3(corners[i], r_center);
|
2017-04-21 16:43:14 +02:00
|
|
|
if (rad > *r_radius) {
|
|
|
|
*r_radius = rad;
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 04:25:25 +01:00
|
|
|
|
|
|
|
/* TODO try to reduce the radius further by moving the center.
|
|
|
|
* Remember we need a __stable__ solution! */
|
|
|
|
|
|
|
|
/* Try to reduce float imprecision leading to shimmering. */
|
|
|
|
*r_radius = (float)round_to_digits(sqrtf(*r_radius), 3);
|
2017-04-21 16:43:14 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-04 17:33:16 +02:00
|
|
|
static void eevee_shadow_cascade_setup(
|
|
|
|
Object *ob, EEVEE_LampsInfo *linfo, EEVEE_LampEngineData *led,
|
2018-10-28 21:41:40 +01:00
|
|
|
DRWMatrixState *saved_mats, float view_near, float view_far, int sample_ofs)
|
2017-04-20 13:07:24 +02:00
|
|
|
{
|
2017-09-07 15:31:11 +02:00
|
|
|
Lamp *la = (Lamp *)ob->data;
|
|
|
|
|
2017-04-20 13:07:24 +02:00
|
|
|
/* Camera Matrices */
|
2018-05-04 17:33:16 +02:00
|
|
|
float (*persinv)[4] = saved_mats->mat[DRW_MAT_PERSINV];
|
|
|
|
float (*vp_projmat)[4] = saved_mats->mat[DRW_MAT_WIN];
|
2017-04-21 16:43:14 +02:00
|
|
|
bool is_persp = DRW_viewport_is_persp_get();
|
|
|
|
|
2017-04-20 13:07:24 +02:00
|
|
|
/* Lamps Matrices */
|
2017-09-07 15:31:11 +02:00
|
|
|
int cascade_nbr = la->cascade_count;
|
2017-04-20 13:07:24 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
EEVEE_ShadowCascadeData *sh_data = &led->data.scad;
|
2017-09-05 21:02:17 +02:00
|
|
|
EEVEE_Light *evli = linfo->light_data + sh_data->light_id;
|
|
|
|
EEVEE_Shadow *ubo_data = linfo->shadow_data + sh_data->shadow_id;
|
|
|
|
EEVEE_ShadowCascade *cascade_data = linfo->shadow_cascade_data + sh_data->cascade_id;
|
2017-04-20 13:07:24 +02:00
|
|
|
|
2018-03-02 18:35:25 +01:00
|
|
|
/* obmat = Object Space > World Space */
|
|
|
|
/* viewmat = World Space > View Space */
|
2018-04-15 22:22:50 +02:00
|
|
|
float (*viewmat)[4] = sh_data->viewmat;
|
2018-05-03 15:44:19 +02:00
|
|
|
#if 0 /* done at culling time */
|
|
|
|
normalize_m4_m4(viewmat, ob->obmat);
|
|
|
|
#endif
|
2018-10-28 21:41:40 +01:00
|
|
|
|
|
|
|
if (linfo->soft_shadows) {
|
|
|
|
shadow_cascade_random_matrix_set(viewmat, evli->radius, sample_ofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_m4_m4(sh_data->viewinv, viewmat);
|
2018-05-03 15:44:19 +02:00
|
|
|
invert_m4(viewmat);
|
2018-03-02 18:35:25 +01:00
|
|
|
|
2017-04-20 13:07:24 +02:00
|
|
|
/* The technique consists into splitting
|
|
|
|
* the view frustum into several sub-frustum
|
|
|
|
* that are individually receiving one shadow map */
|
|
|
|
|
2017-09-07 15:31:11 +02:00
|
|
|
float csm_start, csm_end;
|
|
|
|
|
|
|
|
if (is_persp) {
|
|
|
|
csm_start = view_near;
|
|
|
|
csm_end = max_ff(view_far, -la->cascade_max_dist);
|
|
|
|
/* Avoid artifacts */
|
|
|
|
csm_end = min_ff(view_near, csm_end);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
csm_start = -view_far;
|
|
|
|
csm_end = view_far;
|
|
|
|
}
|
|
|
|
|
2017-04-21 16:43:14 +02:00
|
|
|
/* init near/far */
|
|
|
|
for (int c = 0; c < MAX_CASCADE_NUM; ++c) {
|
2017-09-07 15:31:11 +02:00
|
|
|
cascade_data->split_start[c] = csm_end;
|
|
|
|
cascade_data->split_end[c] = csm_end;
|
2017-04-21 16:43:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute split planes */
|
2017-09-07 15:31:11 +02:00
|
|
|
float splits_start_ndc[MAX_CASCADE_NUM];
|
|
|
|
float splits_end_ndc[MAX_CASCADE_NUM];
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Nearest plane */
|
|
|
|
float p[4] = {1.0f, 1.0f, csm_start, 1.0f};
|
|
|
|
/* TODO: we don't need full m4 multiply here */
|
2018-05-04 17:33:16 +02:00
|
|
|
mul_m4_v4(vp_projmat, p);
|
2017-09-07 15:31:11 +02:00
|
|
|
splits_start_ndc[0] = p[2];
|
|
|
|
if (is_persp) {
|
|
|
|
splits_start_ndc[0] /= p[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Farthest plane */
|
|
|
|
float p[4] = {1.0f, 1.0f, csm_end, 1.0f};
|
|
|
|
/* TODO: we don't need full m4 multiply here */
|
2018-05-04 17:33:16 +02:00
|
|
|
mul_m4_v4(vp_projmat, p);
|
2017-09-07 15:31:11 +02:00
|
|
|
splits_end_ndc[cascade_nbr - 1] = p[2];
|
|
|
|
if (is_persp) {
|
|
|
|
splits_end_ndc[cascade_nbr - 1] /= p[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cascade_data->split_start[0] = csm_start;
|
|
|
|
cascade_data->split_end[cascade_nbr - 1] = csm_end;
|
2017-04-21 16:43:14 +02:00
|
|
|
|
2017-09-07 15:31:11 +02:00
|
|
|
for (int c = 1; c < cascade_nbr; ++c) {
|
2017-04-21 16:43:14 +02:00
|
|
|
/* View Space */
|
2017-09-07 15:31:11 +02:00
|
|
|
float linear_split = LERP(((float)(c) / (float)cascade_nbr), csm_start, csm_end);
|
|
|
|
float exp_split = csm_start * powf(csm_end / csm_start, (float)(c) / (float)cascade_nbr);
|
2017-04-21 16:43:14 +02:00
|
|
|
|
|
|
|
if (is_persp) {
|
2017-09-07 15:31:11 +02:00
|
|
|
cascade_data->split_start[c] = LERP(la->cascade_exponent, linear_split, exp_split);
|
2017-04-21 16:43:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-09-07 15:31:11 +02:00
|
|
|
cascade_data->split_start[c] = linear_split;
|
2017-04-21 16:43:14 +02:00
|
|
|
}
|
2017-10-07 15:57:14 +11:00
|
|
|
cascade_data->split_end[c - 1] = cascade_data->split_start[c];
|
2017-09-07 15:31:11 +02:00
|
|
|
|
|
|
|
/* Add some overlap for smooth transition */
|
2017-10-07 15:57:14 +11:00
|
|
|
cascade_data->split_start[c] = LERP(la->cascade_fade, cascade_data->split_end[c - 1],
|
|
|
|
(c > 1) ? cascade_data->split_end[c - 2] : cascade_data->split_start[0]);
|
2017-04-21 16:43:14 +02:00
|
|
|
|
|
|
|
/* NDC Space */
|
2017-09-07 15:31:11 +02:00
|
|
|
{
|
|
|
|
float p[4] = {1.0f, 1.0f, cascade_data->split_start[c], 1.0f};
|
|
|
|
/* TODO: we don't need full m4 multiply here */
|
2018-05-04 17:33:16 +02:00
|
|
|
mul_m4_v4(vp_projmat, p);
|
2017-09-07 15:31:11 +02:00
|
|
|
splits_start_ndc[c] = p[2];
|
2017-04-21 16:43:14 +02:00
|
|
|
|
2017-09-07 15:31:11 +02:00
|
|
|
if (is_persp) {
|
|
|
|
splits_start_ndc[c] /= p[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-10-07 15:57:14 +11:00
|
|
|
float p[4] = {1.0f, 1.0f, cascade_data->split_end[c - 1], 1.0f};
|
2017-09-07 15:31:11 +02:00
|
|
|
/* TODO: we don't need full m4 multiply here */
|
2018-05-04 17:33:16 +02:00
|
|
|
mul_m4_v4(vp_projmat, p);
|
2017-10-07 15:57:14 +11:00
|
|
|
splits_end_ndc[c - 1] = p[2];
|
2017-09-07 15:31:11 +02:00
|
|
|
|
|
|
|
if (is_persp) {
|
2017-10-07 15:57:14 +11:00
|
|
|
splits_end_ndc[c - 1] /= p[3];
|
2017-09-07 15:31:11 +02:00
|
|
|
}
|
2017-04-21 16:43:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 15:31:11 +02:00
|
|
|
/* Set last cascade split fade distance into the first split_start. */
|
2017-10-07 15:57:14 +11:00
|
|
|
float prev_split = (cascade_nbr > 1) ? cascade_data->split_end[cascade_nbr - 2] : cascade_data->split_start[0];
|
|
|
|
cascade_data->split_start[0] = LERP(la->cascade_fade, cascade_data->split_end[cascade_nbr - 1], prev_split);
|
2017-09-07 15:31:11 +02:00
|
|
|
|
2017-04-20 13:07:24 +02:00
|
|
|
/* For each cascade */
|
2017-09-05 21:02:17 +02:00
|
|
|
for (int c = 0; c < cascade_nbr; ++c) {
|
2018-04-15 22:22:50 +02:00
|
|
|
float (*projmat)[4] = sh_data->projmat[c];
|
2017-09-05 21:02:17 +02:00
|
|
|
/* Given 8 frustum corners */
|
2018-02-24 04:25:25 +01:00
|
|
|
float corners[8][3] = {
|
2017-04-20 13:07:24 +02:00
|
|
|
/* Near Cap */
|
2018-02-24 04:25:25 +01:00
|
|
|
{ 1.0f, -1.0f, splits_start_ndc[c]},
|
2018-07-16 20:08:02 +02:00
|
|
|
{-1.0f, -1.0f, splits_start_ndc[c]},
|
2018-02-24 04:25:25 +01:00
|
|
|
{-1.0f, 1.0f, splits_start_ndc[c]},
|
|
|
|
{ 1.0f, 1.0f, splits_start_ndc[c]},
|
2017-04-21 16:43:14 +02:00
|
|
|
/* Far Cap */
|
2018-02-24 04:25:25 +01:00
|
|
|
{ 1.0f, -1.0f, splits_end_ndc[c]},
|
2018-07-16 20:08:02 +02:00
|
|
|
{-1.0f, -1.0f, splits_end_ndc[c]},
|
2018-02-24 04:25:25 +01:00
|
|
|
{-1.0f, 1.0f, splits_end_ndc[c]},
|
|
|
|
{ 1.0f, 1.0f, splits_end_ndc[c]}
|
2017-04-20 13:07:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Transform them into world space */
|
2017-10-07 15:57:14 +11:00
|
|
|
for (int i = 0; i < 8; ++i) {
|
2018-02-24 04:25:25 +01:00
|
|
|
mul_project_m4_v3(persinv, corners[i]);
|
2017-04-20 13:07:24 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 04:25:25 +01:00
|
|
|
float center[3];
|
|
|
|
frustum_min_bounding_sphere(corners, center, &(sh_data->radius[c]));
|
2017-09-07 15:31:11 +02:00
|
|
|
|
2018-07-16 20:08:02 +02:00
|
|
|
#ifdef DEBUG_CSM
|
|
|
|
float dbg_col[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
|
|
|
if (c < 3) {
|
|
|
|
dbg_col[c] = 1.0f;
|
|
|
|
}
|
|
|
|
DRW_debug_bbox((BoundBox *)&corners, dbg_col);
|
|
|
|
DRW_debug_sphere(center, sh_data->radius[c], dbg_col);
|
|
|
|
#endif
|
|
|
|
|
2018-02-24 04:25:25 +01:00
|
|
|
/* Project into lightspace */
|
2018-07-16 19:54:37 +02:00
|
|
|
mul_m4_v3(viewmat, center);
|
2017-04-21 16:43:14 +02:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
/* Snap projection center to nearest texel to cancel shimmering. */
|
2017-04-21 16:43:14 +02:00
|
|
|
float shadow_origin[2], shadow_texco[2];
|
2017-11-20 14:28:24 +11:00
|
|
|
/* Light to texture space. */
|
2018-05-04 14:39:05 +02:00
|
|
|
mul_v2_v2fl(shadow_origin, center, linfo->shadow_cascade_size / (2.0f * sh_data->radius[c]));
|
2017-04-21 16:43:14 +02:00
|
|
|
|
|
|
|
/* Find the nearest texel. */
|
2018-02-24 04:25:25 +01:00
|
|
|
shadow_texco[0] = roundf(shadow_origin[0]);
|
|
|
|
shadow_texco[1] = roundf(shadow_origin[1]);
|
2017-04-21 16:43:14 +02:00
|
|
|
|
|
|
|
/* Compute offset. */
|
|
|
|
sub_v2_v2(shadow_texco, shadow_origin);
|
2018-05-04 14:39:05 +02:00
|
|
|
mul_v2_fl(shadow_texco, (2.0f * sh_data->radius[c]) / linfo->shadow_cascade_size); /* Texture to light space. */
|
2017-04-20 13:07:24 +02:00
|
|
|
|
2017-04-21 16:43:14 +02:00
|
|
|
/* Apply offset. */
|
|
|
|
add_v2_v2(center, shadow_texco);
|
|
|
|
|
|
|
|
/* Expand the projection to cover frustum range */
|
2018-04-15 22:22:50 +02:00
|
|
|
rctf rect_cascade;
|
2018-03-02 18:35:25 +01:00
|
|
|
BLI_rctf_init_pt_radius(&rect_cascade, center, sh_data->radius[c]);
|
2017-04-21 16:43:14 +02:00
|
|
|
orthographic_m4(projmat,
|
2018-03-02 18:35:25 +01:00
|
|
|
rect_cascade.xmin, rect_cascade.xmax,
|
|
|
|
rect_cascade.ymin, rect_cascade.ymax,
|
2017-04-21 16:43:14 +02:00
|
|
|
la->clipsta, la->clipend);
|
2017-04-20 13:07:24 +02:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
mul_m4_m4m4(sh_data->viewprojmat[c], projmat, viewmat);
|
|
|
|
mul_m4_m4m4(cascade_data->shadowmat[c], texcomat, sh_data->viewprojmat[c]);
|
2018-07-16 20:08:02 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_CSM
|
|
|
|
DRW_debug_m4_as_bbox(sh_data->viewprojmat[c], dbg_col, true);
|
|
|
|
#endif
|
2017-04-21 16:43:14 +02:00
|
|
|
}
|
2017-04-20 13:07:24 +02:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
ubo_data->bias = 0.05f * la->bias;
|
|
|
|
ubo_data->near = la->clipsta;
|
|
|
|
ubo_data->far = la->clipend;
|
|
|
|
ubo_data->exp = (linfo->shadow_method == SHADOW_VSM) ? la->bleedbias : la->bleedexp;
|
|
|
|
|
|
|
|
evli->shadowid = (float)(sh_data->shadow_id);
|
|
|
|
ubo_data->shadow_start = (float)(sh_data->layer_id);
|
|
|
|
ubo_data->data_start = (float)(sh_data->cascade_id);
|
2017-11-22 04:51:21 +01:00
|
|
|
ubo_data->shadow_blur = la->soft * 0.02f; /* Used by translucence shadowmap blur */
|
2017-10-06 23:43:36 +02:00
|
|
|
|
|
|
|
ubo_data->contact_dist = (la->mode & LA_SHAD_CONTACT) ? la->contact_dist : 0.0f;
|
|
|
|
ubo_data->contact_bias = 0.05f * la->contact_bias;
|
|
|
|
ubo_data->contact_spread = la->contact_spread;
|
|
|
|
ubo_data->contact_thickness = la->contact_thickness;
|
2017-04-20 13:07:24 +02:00
|
|
|
}
|
|
|
|
|
2017-06-01 18:20:44 +02:00
|
|
|
/* Used for checking if object is inside the shadow volume. */
|
2018-01-11 14:08:21 +01:00
|
|
|
static bool sphere_bbox_intersect(const EEVEE_BoundSphere *bs, const EEVEE_BoundBox *bb)
|
2017-06-01 18:20:44 +02:00
|
|
|
{
|
2018-01-11 14:08:21 +01:00
|
|
|
/* We are testing using a rougher AABB vs AABB test instead of full AABB vs Sphere. */
|
|
|
|
/* TODO test speed with AABB vs Sphere. */
|
|
|
|
bool x = fabsf(bb->center[0] - bs->center[0]) <= (bb->halfdim[0] + bs->radius);
|
|
|
|
bool y = fabsf(bb->center[1] - bs->center[1]) <= (bb->halfdim[1] + bs->radius);
|
|
|
|
bool z = fabsf(bb->center[2] - bs->center[2]) <= (bb->halfdim[2] + bs->radius);
|
2017-06-01 18:20:44 +02:00
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
return x && y && z;
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
void EEVEE_lights_update(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
|
2017-06-01 18:20:44 +02:00
|
|
|
{
|
2018-10-28 21:41:40 +01:00
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
2018-01-11 14:08:21 +01:00
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
|
|
|
Object *ob;
|
|
|
|
int i;
|
|
|
|
char *flag;
|
|
|
|
EEVEE_ShadowCaster *shcaster;
|
|
|
|
EEVEE_BoundSphere *bsphere;
|
|
|
|
EEVEE_ShadowCasterBuffer *frontbuffer = linfo->shcaster_frontbuffer;
|
|
|
|
EEVEE_ShadowCasterBuffer *backbuffer = linfo->shcaster_backbuffer;
|
|
|
|
|
|
|
|
EEVEE_LightBits update_bits = {{0}};
|
|
|
|
if ((linfo->update_flag & LIGHT_UPDATE_SHADOW_CUBE) != 0) {
|
|
|
|
/* Update all lights. */
|
|
|
|
lightbits_set_all(&update_bits, true);
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
2018-01-11 14:08:21 +01:00
|
|
|
else {
|
|
|
|
/* Search for deleted shadow casters and if shcaster WAS in shadow radius. */
|
|
|
|
/* No need to run this if we already update all lamps. */
|
|
|
|
EEVEE_LightBits past_bits = {{0}};
|
|
|
|
EEVEE_LightBits curr_bits = {{0}};
|
|
|
|
shcaster = backbuffer->shadow_casters;
|
|
|
|
flag = backbuffer->flags;
|
|
|
|
for (i = 0; i < backbuffer->count; ++i, ++flag, ++shcaster) {
|
|
|
|
/* If the shadowcaster has been deleted or updated. */
|
|
|
|
if (*flag != 0) {
|
|
|
|
/* Add the lamps that were intersecting with its BBox. */
|
|
|
|
lightbits_or(&past_bits, &shcaster->bits);
|
|
|
|
}
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Convert old bits to new bits and add result to final update bits. */
|
|
|
|
/* NOTE: This might be overkill since all lights are tagged to refresh if
|
|
|
|
* the light count changes. */
|
|
|
|
lightbits_convert(&curr_bits, &past_bits, linfo->new_shadow_id, MAX_LIGHT);
|
|
|
|
lightbits_or(&update_bits, &curr_bits);
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Search for updates in current shadow casters. */
|
|
|
|
shcaster = frontbuffer->shadow_casters;
|
|
|
|
flag = frontbuffer->flags;
|
|
|
|
for (i = 0; i < frontbuffer->count; i++, flag++, shcaster++) {
|
|
|
|
/* Run intersection checks to fill the bitfields. */
|
|
|
|
bsphere = linfo->shadow_bounds;
|
2018-07-08 12:45:53 +02:00
|
|
|
for (int j = 0; j < linfo->cpu_cube_len; j++, bsphere++) {
|
2018-01-11 14:08:21 +01:00
|
|
|
bool iter = sphere_bbox_intersect(bsphere, &shcaster->bbox);
|
|
|
|
lightbits_set_single(&shcaster->bits, j, iter);
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Only add to final bits if objects has been updated. */
|
|
|
|
if (*flag != 0) {
|
|
|
|
lightbits_or(&update_bits, &shcaster->bits);
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Setup shadow cube in UBO and tag for update if necessary. */
|
|
|
|
for (i = 0; (i < MAX_SHADOW_CUBE) && (ob = linfo->shadow_cube_ref[i]); i++) {
|
|
|
|
EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
|
2017-06-01 18:20:44 +02:00
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
eevee_shadow_cube_setup(ob, linfo, led, effects->taa_current_sample - 1);
|
|
|
|
if (lightbits_get(&update_bits, i) != 0 || linfo->soft_shadows) {
|
2017-06-01 18:20:44 +02:00
|
|
|
led->need_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
/* Resize shcasters buffers if too big. */
|
|
|
|
if (frontbuffer->alloc_count - frontbuffer->count > SHADOW_CASTER_ALLOC_CHUNK) {
|
|
|
|
frontbuffer->alloc_count = (frontbuffer->count / SHADOW_CASTER_ALLOC_CHUNK) * SHADOW_CASTER_ALLOC_CHUNK;
|
|
|
|
frontbuffer->alloc_count += (frontbuffer->count % SHADOW_CASTER_ALLOC_CHUNK != 0) ? SHADOW_CASTER_ALLOC_CHUNK : 0;
|
|
|
|
frontbuffer->shadow_casters = MEM_reallocN(frontbuffer->shadow_casters, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
|
|
|
|
frontbuffer->flags = MEM_reallocN(frontbuffer->flags, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this refresh lamps shadow buffers */
|
2018-10-28 21:41:40 +01:00
|
|
|
void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
|
2017-04-10 12:06:17 +02:00
|
|
|
{
|
2018-10-28 21:41:40 +01:00
|
|
|
EEVEE_PassList *psl = vedata->psl;
|
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_LampsInfo *linfo = sldata->lamps;
|
2018-11-15 14:44:45 +01:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
const float light_threshold = draw_ctx->scene->eevee.light_threshold;
|
2017-04-10 12:06:17 +02:00
|
|
|
Object *ob;
|
|
|
|
int i;
|
|
|
|
|
2018-03-02 18:35:25 +01:00
|
|
|
DRWMatrixState saved_mats;
|
2018-11-08 19:17:41 +01:00
|
|
|
int saved_ray_type = sldata->common_data.ray_type;
|
|
|
|
|
|
|
|
/* TODO: make it optionnal if we don't draw shadows. */
|
|
|
|
sldata->common_data.ray_type = EEVEE_RAY_SHADOW;
|
|
|
|
DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
|
2018-03-02 18:35:25 +01:00
|
|
|
|
2018-05-03 15:44:19 +02:00
|
|
|
/* Precompute all shadow/view test before rendering and trashing the culling cache. */
|
|
|
|
bool cube_visible[MAX_SHADOW_CUBE];
|
|
|
|
for (i = 0; (ob = linfo->shadow_cube_ref[i]) && (i < MAX_SHADOW_CUBE); i++) {
|
|
|
|
Lamp *la = (Lamp *)ob->data;
|
|
|
|
BoundSphere bsphere = {
|
|
|
|
.center = {ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]},
|
2019-01-07 00:06:58 +11:00
|
|
|
.radius = light_attenuation_radius_get(la, light_threshold),
|
2018-05-03 15:44:19 +02:00
|
|
|
};
|
|
|
|
cube_visible[i] = DRW_culling_sphere_test(&bsphere);
|
|
|
|
}
|
|
|
|
bool cascade_visible[MAX_SHADOW_CASCADE];
|
|
|
|
for (i = 0; (ob = linfo->shadow_cascade_ref[i]) && (i < MAX_SHADOW_CASCADE); i++) {
|
|
|
|
EEVEE_LampEngineData *led = EEVEE_lamp_data_get(ob);
|
|
|
|
EEVEE_ShadowCascadeData *sh_data = &led->data.scad;
|
|
|
|
float plane[4];
|
|
|
|
normalize_m4_m4(sh_data->viewmat, ob->obmat);
|
2018-10-28 21:41:40 +01:00
|
|
|
|
2018-05-03 15:44:19 +02:00
|
|
|
plane_from_point_normal_v3(plane, sh_data->viewmat[3], sh_data->viewmat[2]);
|
|
|
|
/* TODO: check against near/far instead of "local Z = 0" plane.
|
|
|
|
* Or even the cascades AABB. */
|
|
|
|
cascade_visible[i] = DRW_culling_plane_test(plane);
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:35:25 +01:00
|
|
|
/* We need to save the Matrices before overidding them */
|
|
|
|
DRW_viewport_matrix_get_all(&saved_mats);
|
|
|
|
|
2017-04-10 12:06:17 +02:00
|
|
|
/* Cube Shadow Maps */
|
2017-09-10 03:07:55 +02:00
|
|
|
DRW_stats_group_start("Cube Shadow Maps");
|
2017-04-10 12:06:17 +02:00
|
|
|
/* Render each shadow to one layer of the array */
|
|
|
|
for (i = 0; (ob = linfo->shadow_cube_ref[i]) && (i < MAX_SHADOW_CUBE); i++) {
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
|
2017-06-02 20:50:04 +02:00
|
|
|
Lamp *la = (Lamp *)ob->data;
|
2017-06-01 18:20:44 +02:00
|
|
|
|
2018-05-03 15:44:19 +02:00
|
|
|
if (!led->need_update || !cube_visible[i]) {
|
2017-11-29 11:59:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-01 18:20:44 +02:00
|
|
|
|
2018-04-15 22:22:50 +02:00
|
|
|
DRWMatrixState render_mats;
|
|
|
|
float (*winmat)[4] = render_mats.mat[DRW_MAT_WIN];
|
|
|
|
float (*viewmat)[4] = render_mats.mat[DRW_MAT_VIEW];
|
|
|
|
float (*persmat)[4] = render_mats.mat[DRW_MAT_PERS];
|
|
|
|
|
2017-11-29 11:59:15 +01:00
|
|
|
EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
|
2018-01-11 14:08:21 +01:00
|
|
|
EEVEE_ShadowCubeData *evscd = &led->data.scd;
|
2018-10-28 21:41:40 +01:00
|
|
|
EEVEE_ShadowCube *cube_data = linfo->shadow_cube_data + evscd->cube_id;
|
2017-07-11 01:10:57 +02:00
|
|
|
|
2017-11-29 11:59:15 +01:00
|
|
|
srd->clip_near = la->clipsta;
|
2018-11-15 14:44:45 +01:00
|
|
|
srd->clip_far = light_attenuation_radius_get(la, light_threshold);
|
2018-05-04 15:59:01 +02:00
|
|
|
srd->stored_texel_size = 1.0 / (float)linfo->shadow_cube_store_size;
|
2018-11-11 17:45:29 +01:00
|
|
|
srd->exponent = la->bleedexp;
|
2018-11-15 14:44:45 +01:00
|
|
|
copy_v3_v3(srd->position, cube_data->position);
|
|
|
|
|
|
|
|
perspective_m4(winmat, -srd->clip_near, srd->clip_near, -srd->clip_near, srd->clip_near, srd->clip_near, srd->clip_far);
|
2018-05-04 14:39:05 +02:00
|
|
|
|
2017-11-29 11:59:15 +01:00
|
|
|
DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
|
2017-09-09 21:11:22 +02:00
|
|
|
|
2017-11-29 11:59:15 +01:00
|
|
|
/* Render shadow cube */
|
2018-07-03 09:08:00 +02:00
|
|
|
/* Render 6 faces separately: seems to be faster for the general case.
|
2018-04-15 22:22:50 +02:00
|
|
|
* The only time it's more beneficial is when the CPU culling overhead
|
2018-09-19 18:19:49 +02:00
|
|
|
* outweigh the instancing overhead. which is rarely the case. */
|
2018-04-15 22:22:50 +02:00
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
/* TODO optimize */
|
|
|
|
float tmp[4][4];
|
|
|
|
unit_m4(tmp);
|
|
|
|
negate_v3_v3(tmp[3], srd->position);
|
|
|
|
mul_m4_m4m4(viewmat, cubefacemat[j], tmp);
|
|
|
|
mul_m4_m4m4(persmat, winmat, viewmat);
|
|
|
|
invert_m4_m4(render_mats.mat[DRW_MAT_WININV], winmat);
|
|
|
|
invert_m4_m4(render_mats.mat[DRW_MAT_VIEWINV], viewmat);
|
|
|
|
invert_m4_m4(render_mats.mat[DRW_MAT_PERSINV], persmat);
|
|
|
|
|
|
|
|
DRW_viewport_matrix_override_set_all(&render_mats);
|
|
|
|
|
|
|
|
GPU_framebuffer_texture_cubeface_attach(sldata->shadow_cube_target_fb,
|
|
|
|
sldata->shadow_cube_target, 0, j, 0);
|
|
|
|
GPU_framebuffer_bind(sldata->shadow_cube_target_fb);
|
|
|
|
GPU_framebuffer_clear_depth(sldata->shadow_cube_target_fb, 1.0f);
|
|
|
|
DRW_draw_pass(psl->shadow_pass);
|
|
|
|
}
|
2017-09-09 21:11:22 +02:00
|
|
|
|
2017-11-29 11:59:15 +01:00
|
|
|
/* 0.001f is arbitrary, but it should be relatively small so that filter size is not too big. */
|
|
|
|
float filter_texture_size = la->soft * 0.001f;
|
2018-05-04 15:59:01 +02:00
|
|
|
float filter_pixel_size = ceil(filter_texture_size / srd->cube_texel_size);
|
|
|
|
linfo->filter_size = srd->cube_texel_size * ((filter_pixel_size > 1.0f) ? 1.5f : 0.0f);
|
2017-11-29 11:59:15 +01:00
|
|
|
|
|
|
|
/* TODO: OPTI: Filter all faces in one/two draw call */
|
2018-05-04 15:59:01 +02:00
|
|
|
/* TODO: OPTI: Don't do this intermediate step if no filter is needed. */
|
2017-11-29 11:59:15 +01:00
|
|
|
for (linfo->current_shadow_face = 0;
|
|
|
|
linfo->current_shadow_face < 6;
|
|
|
|
linfo->current_shadow_face++)
|
|
|
|
{
|
|
|
|
/* Copy using a small 3x3 box filter */
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_framebuffer_texture_cubeface_attach(sldata->shadow_cube_store_fb, sldata->shadow_cube_blur, 0,
|
2018-03-25 17:46:48 +02:00
|
|
|
linfo->current_shadow_face, 0);
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_framebuffer_bind(sldata->shadow_cube_store_fb);
|
2017-11-29 11:59:15 +01:00
|
|
|
DRW_draw_pass(psl->shadow_cube_copy_pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push it to shadowmap array */
|
|
|
|
|
|
|
|
/* Adjust constants if concentric samples change. */
|
|
|
|
const float max_filter_size = 7.5f;
|
2018-05-04 15:59:01 +02:00
|
|
|
const float magic = 4.5f; /* Dunno why but that works. */
|
2017-11-29 11:59:15 +01:00
|
|
|
const int max_sample = 256;
|
2017-05-20 13:16:14 +02:00
|
|
|
|
2017-11-29 11:59:15 +01:00
|
|
|
if (filter_pixel_size > 2.0f) {
|
2018-05-04 15:59:01 +02:00
|
|
|
linfo->filter_size = srd->cube_texel_size * max_filter_size * magic;
|
2017-11-29 11:59:15 +01:00
|
|
|
filter_pixel_size = max_ff(0.0f, filter_pixel_size - 3.0f);
|
|
|
|
/* Compute number of concentric samples. Depends directly on filter size. */
|
|
|
|
float pix_size_sqr = filter_pixel_size * filter_pixel_size;
|
2018-07-08 12:45:53 +02:00
|
|
|
srd->shadow_samples_len = min_ii(max_sample, 4 + 8 * (int)filter_pixel_size + 4 * (int)(pix_size_sqr));
|
2017-06-01 18:20:44 +02:00
|
|
|
}
|
2017-11-29 11:59:15 +01:00
|
|
|
else {
|
|
|
|
linfo->filter_size = 0.0f;
|
2018-07-08 12:45:53 +02:00
|
|
|
srd->shadow_samples_len = 4;
|
2017-11-29 11:59:15 +01:00
|
|
|
}
|
2018-07-08 12:45:53 +02:00
|
|
|
srd->shadow_samples_len_inv = 1.0f / (float)srd->shadow_samples_len;
|
2017-11-29 11:59:15 +01:00
|
|
|
DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
|
|
|
|
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_framebuffer_texture_layer_attach(sldata->shadow_cube_store_fb, sldata->shadow_cube_pool, 0, evscd->layer_id, 0);
|
|
|
|
GPU_framebuffer_bind(sldata->shadow_cube_store_fb);
|
2018-06-03 22:47:01 +02:00
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
DRWPass *store_pass = eevee_lights_cube_store_pass_get(psl, sldata, linfo->shadow_method, srd->shadow_samples_len);
|
2018-06-03 22:47:01 +02:00
|
|
|
DRW_draw_pass(store_pass);
|
2017-11-29 11:59:15 +01:00
|
|
|
|
2018-10-28 21:41:40 +01:00
|
|
|
if (linfo->soft_shadows == false) {
|
|
|
|
led->need_update = false;
|
|
|
|
}
|
2017-04-10 12:06:17 +02:00
|
|
|
}
|
2017-06-01 18:20:44 +02:00
|
|
|
linfo->update_flag &= ~LIGHT_UPDATE_SHADOW_CUBE;
|
2017-09-10 03:07:55 +02:00
|
|
|
DRW_stats_group_end();
|
2017-03-31 01:07:30 +02:00
|
|
|
|
2018-03-06 02:51:51 +01:00
|
|
|
DRW_viewport_matrix_override_set_all(&saved_mats);
|
2018-05-04 17:33:16 +02:00
|
|
|
float near = DRW_viewport_near_distance_get();
|
|
|
|
float far = DRW_viewport_far_distance_get();
|
2018-03-06 02:51:51 +01:00
|
|
|
|
2017-04-20 13:07:24 +02:00
|
|
|
/* Cascaded Shadow Maps */
|
2017-09-10 03:07:55 +02:00
|
|
|
DRW_stats_group_start("Cascaded Shadow Maps");
|
2017-09-05 21:02:17 +02:00
|
|
|
for (i = 0; (ob = linfo->shadow_cascade_ref[i]) && (i < MAX_SHADOW_CASCADE); i++) {
|
2018-05-03 15:44:19 +02:00
|
|
|
if (!cascade_visible[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
|
2017-09-05 21:02:17 +02:00
|
|
|
Lamp *la = (Lamp *)ob->data;
|
|
|
|
|
2018-01-11 14:08:21 +01:00
|
|
|
EEVEE_ShadowCascadeData *evscd = &led->data.scad;
|
2017-09-05 21:02:17 +02:00
|
|
|
EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
|
|
|
|
|
2018-04-15 22:22:50 +02:00
|
|
|
DRWMatrixState render_mats;
|
|
|
|
float (*winmat)[4] = render_mats.mat[DRW_MAT_WIN];
|
|
|
|
float (*viewmat)[4] = render_mats.mat[DRW_MAT_VIEW];
|
|
|
|
float (*persmat)[4] = render_mats.mat[DRW_MAT_PERS];
|
|
|
|
|
2018-10-29 16:02:13 +01:00
|
|
|
eevee_shadow_cascade_setup(ob, linfo, led, &saved_mats, near, far, effects->taa_current_sample - 1);
|
2017-09-10 03:07:55 +02:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
srd->clip_near = la->clipsta;
|
|
|
|
srd->clip_far = la->clipend;
|
2018-05-04 14:39:05 +02:00
|
|
|
srd->stored_texel_size = 1.0 / (float)linfo->shadow_cascade_size;
|
2018-04-15 22:22:50 +02:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
DRW_uniformbuffer_update(sldata->shadow_render_ubo, &linfo->shadow_render_data);
|
|
|
|
|
2018-04-15 22:22:50 +02:00
|
|
|
copy_m4_m4(viewmat, evscd->viewmat);
|
|
|
|
invert_m4_m4(render_mats.mat[DRW_MAT_VIEWINV], viewmat);
|
2018-03-02 18:35:25 +01:00
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
/* Render shadow cascades */
|
2018-07-03 09:08:00 +02:00
|
|
|
/* Render cascade separately: seems to be faster for the general case.
|
2018-04-15 22:22:50 +02:00
|
|
|
* The only time it's more beneficial is when the CPU culling overhead
|
2018-09-19 18:19:49 +02:00
|
|
|
* outweigh the instancing overhead. which is rarely the case. */
|
2018-04-15 22:22:50 +02:00
|
|
|
for (int j = 0; j < la->cascade_count; j++) {
|
|
|
|
copy_m4_m4(winmat, evscd->projmat[j]);
|
|
|
|
copy_m4_m4(persmat, evscd->viewprojmat[j]);
|
|
|
|
invert_m4_m4(render_mats.mat[DRW_MAT_WININV], winmat);
|
|
|
|
invert_m4_m4(render_mats.mat[DRW_MAT_PERSINV], persmat);
|
|
|
|
|
|
|
|
DRW_viewport_matrix_override_set_all(&render_mats);
|
|
|
|
|
|
|
|
GPU_framebuffer_texture_layer_attach(sldata->shadow_cascade_target_fb,
|
|
|
|
sldata->shadow_cascade_target, 0, j, 0);
|
|
|
|
GPU_framebuffer_bind(sldata->shadow_cascade_target_fb);
|
|
|
|
GPU_framebuffer_clear_depth(sldata->shadow_cascade_target_fb, 1.0f);
|
|
|
|
DRW_draw_pass(psl->shadow_pass);
|
|
|
|
}
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2017-09-09 21:11:22 +02:00
|
|
|
/* TODO: OPTI: Filter all cascade in one/two draw call */
|
2017-09-05 21:02:17 +02:00
|
|
|
for (linfo->current_shadow_cascade = 0;
|
2017-09-07 15:31:11 +02:00
|
|
|
linfo->current_shadow_cascade < la->cascade_count;
|
2017-09-05 21:02:17 +02:00
|
|
|
++linfo->current_shadow_cascade)
|
|
|
|
{
|
2017-09-09 21:11:22 +02:00
|
|
|
/* 0.01f factor to convert to percentage */
|
|
|
|
float filter_texture_size = la->soft * 0.01f / evscd->radius[linfo->current_shadow_cascade];
|
2018-05-04 14:39:05 +02:00
|
|
|
float filter_pixel_size = ceil(linfo->shadow_cascade_size * filter_texture_size);
|
2017-09-09 21:11:22 +02:00
|
|
|
|
2017-09-08 20:21:57 +02:00
|
|
|
/* Copy using a small 3x3 box filter */
|
2018-05-04 14:39:05 +02:00
|
|
|
/* NOTE: We always do it in the case of CSM because of artifacts in the farthest cascade. */
|
|
|
|
linfo->filter_size = srd->stored_texel_size;
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_texture_layer_attach(
|
2018-05-04 14:39:05 +02:00
|
|
|
sldata->shadow_cascade_store_fb, sldata->shadow_cascade_blur, 0, linfo->current_shadow_cascade, 0);
|
|
|
|
GPU_framebuffer_bind(sldata->shadow_cascade_store_fb);
|
2017-09-08 20:21:57 +02:00
|
|
|
DRW_draw_pass(psl->shadow_cascade_copy_pass);
|
2017-09-05 21:02:17 +02:00
|
|
|
|
2017-09-08 20:21:57 +02:00
|
|
|
/* Push it to shadowmap array and blur more */
|
2017-09-09 21:11:22 +02:00
|
|
|
|
|
|
|
/* Adjust constants if concentric samples change. */
|
|
|
|
const float max_filter_size = 7.5f;
|
2018-05-04 15:59:01 +02:00
|
|
|
const float magic = 3.2f; /* Arbitrary: less banding */
|
2017-09-09 21:11:22 +02:00
|
|
|
const int max_sample = 256;
|
|
|
|
|
|
|
|
if (filter_pixel_size > 2.0f) {
|
2018-05-04 15:59:01 +02:00
|
|
|
linfo->filter_size = srd->stored_texel_size * max_filter_size * magic;
|
2017-09-09 21:11:22 +02:00
|
|
|
filter_pixel_size = max_ff(0.0f, filter_pixel_size - 3.0f);
|
|
|
|
/* Compute number of concentric samples. Depends directly on filter size. */
|
|
|
|
float pix_size_sqr = filter_pixel_size * filter_pixel_size;
|
2018-07-08 12:45:53 +02:00
|
|
|
srd->shadow_samples_len = min_ii(max_sample, 4 + 8 * (int)filter_pixel_size + 4 * (int)(pix_size_sqr));
|
2017-09-09 21:11:22 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
linfo->filter_size = 0.0f;
|
2018-07-08 12:45:53 +02:00
|
|
|
srd->shadow_samples_len = 4;
|
2017-09-09 21:11:22 +02:00
|
|
|
}
|
2018-07-08 12:45:53 +02:00
|
|
|
srd->shadow_samples_len_inv = 1.0f / (float)srd->shadow_samples_len;
|
2017-09-09 21:11:22 +02:00
|
|
|
DRW_uniformbuffer_update(sldata->shadow_render_ubo, &linfo->shadow_render_data);
|
|
|
|
|
2017-09-05 21:02:17 +02:00
|
|
|
int layer = evscd->layer_id + linfo->current_shadow_cascade;
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_framebuffer_texture_layer_attach(sldata->shadow_cascade_store_fb, sldata->shadow_cascade_pool, 0, layer, 0);
|
|
|
|
GPU_framebuffer_bind(sldata->shadow_cascade_store_fb);
|
2018-06-03 22:47:01 +02:00
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
DRWPass *store_pass = eevee_lights_cascade_store_pass_get(psl, sldata, linfo->shadow_method, srd->shadow_samples_len);
|
2018-06-03 22:47:01 +02:00
|
|
|
DRW_draw_pass(store_pass);
|
2017-09-05 21:02:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 03:07:55 +02:00
|
|
|
DRW_stats_group_end();
|
|
|
|
|
2018-03-02 18:35:25 +01:00
|
|
|
DRW_viewport_matrix_override_set_all(&saved_mats);
|
|
|
|
|
2017-09-10 03:07:55 +02:00
|
|
|
DRW_uniformbuffer_update(sldata->light_ubo, &linfo->light_data);
|
|
|
|
DRW_uniformbuffer_update(sldata->shadow_ubo, &linfo->shadow_data); /* Update all data at once */
|
2018-11-08 19:17:41 +01:00
|
|
|
|
|
|
|
sldata->common_data.ray_type = saved_ray_type;
|
|
|
|
DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
2017-05-20 13:16:14 +02:00
|
|
|
|
|
|
|
void EEVEE_lights_free(void)
|
|
|
|
{
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_sh);
|
2017-09-01 18:39:39 +02:00
|
|
|
for (int i = 0; i < SHADOW_METHOD_MAX; ++i) {
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_store_cube_sh[i]);
|
2018-06-03 22:47:01 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_store_cube_high_sh[i]);
|
2017-09-01 18:39:39 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_store_cascade_sh[i]);
|
2018-06-03 22:47:01 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_store_cascade_high_sh[i]);
|
2017-09-08 20:21:57 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_copy_cube_sh[i]);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.shadow_copy_cascade_sh[i]);
|
2017-09-01 18:39:39 +02:00
|
|
|
}
|
2017-11-20 14:11:45 +11:00
|
|
|
}
|