Eevee: Fix AO in planar reflections.
This commit is contained in:
parent
8aaf7bc438
commit
a0655ed487
|
@ -236,7 +236,7 @@ static void eevee_draw_background(void *vedata)
|
|||
EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);
|
||||
DRW_stats_group_end();
|
||||
|
||||
EEVEE_occlusion_compute(sldata, vedata);
|
||||
EEVEE_occlusion_compute(sldata, vedata, dtxl->depth, -1);
|
||||
EEVEE_volumes_compute(sldata, vedata);
|
||||
|
||||
/* Shading pass */
|
||||
|
|
|
@ -1276,7 +1276,7 @@ static void render_scene_to_planar(
|
|||
EEVEE_create_minmax_buffer(vedata, tmp_planar_depth, layer);
|
||||
|
||||
/* Compute GTAO Horizons */
|
||||
EEVEE_occlusion_compute(sldata, vedata);
|
||||
EEVEE_occlusion_compute(sldata, vedata, tmp_planar_depth, layer);
|
||||
|
||||
/* Rebind Planar FB */
|
||||
DRW_framebuffer_bind(fbl->planarref_fb);
|
||||
|
|
|
@ -38,7 +38,9 @@
|
|||
static struct {
|
||||
/* Ground Truth Ambient Occlusion */
|
||||
struct GPUShader *gtao_sh;
|
||||
struct GPUShader *gtao_layer_sh;
|
||||
struct GPUShader *gtao_debug_sh;
|
||||
struct GPUTexture *src_depth;
|
||||
} e_data = {NULL}; /* Engine data */
|
||||
|
||||
extern char datatoc_ambient_occlusion_lib_glsl[];
|
||||
|
@ -55,6 +57,7 @@ static void eevee_create_shader_occlusion(void)
|
|||
BLI_dynstr_free(ds_frag);
|
||||
|
||||
e_data.gtao_sh = DRW_shader_create_fullscreen(frag_str, NULL);
|
||||
e_data.gtao_layer_sh = DRW_shader_create_fullscreen(frag_str, "#define LAYERED_DEPTH\n");
|
||||
e_data.gtao_debug_sh = DRW_shader_create_fullscreen(frag_str, "#define DEBUG_AO\n");
|
||||
|
||||
MEM_freeN(frag_str);
|
||||
|
@ -167,7 +170,20 @@ void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data
|
|||
psl->ao_horizon_search = DRW_pass_create("GTAO Horizon Search", DRW_STATE_WRITE_COLOR);
|
||||
DRWShadingGroup *grp = DRW_shgroup_create(e_data.gtao_sh, psl->ao_horizon_search);
|
||||
DRW_shgroup_uniform_buffer(grp, "maxzBuffer", &txl->maxzbuffer);
|
||||
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
|
||||
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &effects->ao_src_depth);
|
||||
DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)stl->g_data->viewvecs, 2);
|
||||
DRW_shgroup_uniform_vec2(grp, "mipRatio[0]", (float *)stl->g_data->mip_ratio, 10);
|
||||
DRW_shgroup_uniform_vec4(grp, "aoParameters[0]", &stl->effects->ao_dist, 2);
|
||||
DRW_shgroup_uniform_float(grp, "sampleNbr", &stl->effects->ao_sample_nbr, 1);
|
||||
DRW_shgroup_uniform_ivec2(grp, "aoHorizonTexSize", (int *)stl->effects->ao_texsize, 1);
|
||||
DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
|
||||
DRW_shgroup_call_add(grp, quad, NULL);
|
||||
|
||||
psl->ao_horizon_search_layer = DRW_pass_create("GTAO Horizon Search Layer", DRW_STATE_WRITE_COLOR);
|
||||
grp = DRW_shgroup_create(e_data.gtao_layer_sh, psl->ao_horizon_search_layer);
|
||||
DRW_shgroup_uniform_buffer(grp, "maxzBuffer", &txl->maxzbuffer);
|
||||
DRW_shgroup_uniform_buffer(grp, "depthBufferLayered", &effects->ao_src_depth);
|
||||
DRW_shgroup_uniform_int(grp, "layer", &stl->effects->ao_depth_layer, 1);
|
||||
DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)stl->g_data->viewvecs, 2);
|
||||
DRW_shgroup_uniform_vec2(grp, "mipRatio[0]", (float *)stl->g_data->mip_ratio, 10);
|
||||
DRW_shgroup_uniform_vec4(grp, "aoParameters[0]", &stl->effects->ao_dist, 2);
|
||||
|
@ -193,7 +209,8 @@ void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data
|
|||
}
|
||||
}
|
||||
|
||||
void EEVEE_occlusion_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
|
||||
void EEVEE_occlusion_compute(
|
||||
EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, struct GPUTexture *depth_src, int layer)
|
||||
{
|
||||
EEVEE_PassList *psl = vedata->psl;
|
||||
EEVEE_TextureList *txl = vedata->txl;
|
||||
|
@ -203,6 +220,9 @@ void EEVEE_occlusion_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *ve
|
|||
|
||||
if ((effects->enabled_effects & EFFECT_GTAO) != 0) {
|
||||
DRW_stats_group_start("GTAO Horizon Scan");
|
||||
effects->ao_src_depth = depth_src;
|
||||
effects->ao_depth_layer = layer;
|
||||
|
||||
for (effects->ao_sample_nbr = 0.0;
|
||||
effects->ao_sample_nbr < effects->ao_samples;
|
||||
++effects->ao_sample_nbr)
|
||||
|
@ -211,7 +231,12 @@ void EEVEE_occlusion_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *ve
|
|||
DRW_framebuffer_texture_layer_attach(fbl->gtao_fb, txl->gtao_horizons, 0, (int)effects->ao_sample_nbr, 0);
|
||||
DRW_framebuffer_bind(fbl->gtao_fb);
|
||||
|
||||
DRW_draw_pass(psl->ao_horizon_search);
|
||||
if (layer >= 0) {
|
||||
DRW_draw_pass(psl->ao_horizon_search_layer);
|
||||
}
|
||||
else {
|
||||
DRW_draw_pass(psl->ao_horizon_search);
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore */
|
||||
|
@ -247,5 +272,6 @@ void EEVEE_occlusion_draw_debug(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data
|
|||
void EEVEE_occlusion_free(void)
|
||||
{
|
||||
DRW_SHADER_FREE_SAFE(e_data.gtao_sh);
|
||||
DRW_SHADER_FREE_SAFE(e_data.gtao_layer_sh);
|
||||
DRW_SHADER_FREE_SAFE(e_data.gtao_debug_sh);
|
||||
}
|
||||
|
|
|
@ -148,6 +148,7 @@ typedef struct EEVEE_PassList {
|
|||
|
||||
/* Effects */
|
||||
struct DRWPass *ao_horizon_search;
|
||||
struct DRWPass *ao_horizon_search_layer;
|
||||
struct DRWPass *ao_horizon_debug;
|
||||
struct DRWPass *motion_blur;
|
||||
struct DRWPass *bloom_blit;
|
||||
|
@ -481,6 +482,8 @@ typedef struct EEVEE_EffectsInfo {
|
|||
float ao_offset, ao_bounce_fac, ao_quality, ao_settings;
|
||||
float ao_sample_nbr;
|
||||
int ao_texsize[2], hori_tex_layers;
|
||||
int ao_depth_layer;
|
||||
struct GPUTexture *ao_src_depth; /* pointer copy */
|
||||
|
||||
/* Motion Blur */
|
||||
float current_ndc_to_world[4][4];
|
||||
|
@ -717,7 +720,7 @@ void EEVEE_bloom_free(void);
|
|||
/* eevee_occlusion.c */
|
||||
int EEVEE_occlusion_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
|
||||
void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
|
||||
void EEVEE_occlusion_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
|
||||
void EEVEE_occlusion_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, struct GPUTexture *depth_src, int layer);
|
||||
void EEVEE_occlusion_draw_debug(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
|
||||
void EEVEE_occlusion_free(void);
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ uniform sampler2D normalBuffer;
|
|||
|
||||
void main()
|
||||
{
|
||||
vec4 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xyxy;
|
||||
vec2 uvs = saturate(gl_FragCoord.xy * texel_size.xy);
|
||||
vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
|
||||
vec2 uvs = saturate(gl_FragCoord.xy * texel_size);
|
||||
|
||||
float depth = textureLod(depthBuffer, uvs, 0.0).r;
|
||||
|
||||
|
@ -23,13 +23,9 @@ void main()
|
|||
|
||||
vec3 bent_normal;
|
||||
float visibility;
|
||||
#if 1
|
||||
|
||||
gtao_deferred(normal, viewPosition, depth, visibility, bent_normal);
|
||||
#else
|
||||
vec2 rand = vec2((1.0 / 4.0) * float((int(gl_FragCoord.y) & 0x1) * 2 + (int(gl_FragCoord.x) & 0x1)), 0.5);
|
||||
rand = fract(rand.x + texture(utilTex, vec3(floor(gl_FragCoord.xy * 0.5) / LUT_SIZE, 2.0)).rg);
|
||||
gtao(normal, viewPosition, rand, visibility, bent_normal);
|
||||
#endif
|
||||
|
||||
denoise_ao(normal, depth, visibility, bent_normal);
|
||||
|
||||
FragColor = vec4(visibility);
|
||||
|
@ -38,13 +34,25 @@ void main()
|
|||
#else
|
||||
uniform float sampleNbr;
|
||||
|
||||
#ifdef LAYERED_DEPTH
|
||||
uniform sampler2DArray depthBufferLayered;
|
||||
uniform int layer;
|
||||
# define gtao_depthBuffer depthBufferLayered
|
||||
# define gtao_textureLod(a, b, c) textureLod(a, vec3(b, layer), c)
|
||||
|
||||
#else
|
||||
# define gtao_depthBuffer depthBuffer
|
||||
# define gtao_textureLod(a, b, c) textureLod(a, b, c)
|
||||
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 hr_co = ivec2(gl_FragCoord.xy);
|
||||
ivec2 fs_co = get_fs_co(hr_co);
|
||||
|
||||
vec2 uvs = saturate((vec2(fs_co) + 0.5) / vec2(textureSize(depthBuffer, 0)));
|
||||
float depth = textureLod(depthBuffer, uvs, 0.0).r;
|
||||
vec2 uvs = saturate((vec2(fs_co) + 0.5) / vec2(textureSize(gtao_depthBuffer, 0).xy));
|
||||
float depth = gtao_textureLod(gtao_depthBuffer, uvs, 0.0).r;
|
||||
|
||||
if (depth == 1.0) {
|
||||
/* Do not trace for background */
|
||||
|
|
Loading…
Reference in New Issue