Eevee: AO: Removes samples and denoise options.
This comes with a lot of code simplification that leads to a small performance improvement.
This commit is contained in:
parent
c372113489
commit
9fd28c7769
|
@ -633,9 +633,7 @@ class RENDER_PT_eevee_ambient_occlusion(RenderButtonsPanel, Panel):
|
|||
layout.active = props.gtao_enable
|
||||
col = layout.column()
|
||||
col.prop(props, "gtao_use_bent_normals")
|
||||
col.prop(props, "gtao_denoise")
|
||||
col.prop(props, "gtao_bounce")
|
||||
col.prop(props, "gtao_samples")
|
||||
col.prop(props, "gtao_distance")
|
||||
col.prop(props, "gtao_factor")
|
||||
col.prop(props, "gtao_quality")
|
||||
|
|
|
@ -178,9 +178,7 @@ class VIEWLAYER_PT_eevee_ambient_occlusion(ViewLayerButtonsPanel, Panel):
|
|||
|
||||
col = layout.column()
|
||||
col.template_override_property(layer_props, scene_props, "gtao_use_bent_normals")
|
||||
col.template_override_property(layer_props, scene_props, "gtao_denoise")
|
||||
col.template_override_property(layer_props, scene_props, "gtao_bounce")
|
||||
col.template_override_property(layer_props, scene_props, "gtao_samples")
|
||||
col.template_override_property(layer_props, scene_props, "gtao_distance")
|
||||
col.template_override_property(layer_props, scene_props, "gtao_factor")
|
||||
col.template_override_property(layer_props, scene_props, "gtao_quality")
|
||||
|
|
|
@ -456,6 +456,9 @@ void EEVEE_draw_effects(EEVEE_Data *vedata)
|
|||
if (stl->g_data->gtao_horizons_debug) DRW_transform_to_display(stl->g_data->gtao_horizons_debug);
|
||||
break;
|
||||
case 7:
|
||||
if (txl->gtao_horizons) DRW_transform_to_display(txl->gtao_horizons);
|
||||
break;
|
||||
case 8:
|
||||
if (txl->sss_data) DRW_transform_to_display(txl->sss_data);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -381,12 +381,10 @@ static void eevee_view_layer_settings_create(RenderEngine *UNUSED(engine), IDPro
|
|||
|
||||
BKE_collection_engine_property_add_bool(props, "gtao_enable", false);
|
||||
BKE_collection_engine_property_add_bool(props, "gtao_use_bent_normals", true);
|
||||
BKE_collection_engine_property_add_bool(props, "gtao_denoise", true);
|
||||
BKE_collection_engine_property_add_bool(props, "gtao_bounce", true);
|
||||
BKE_collection_engine_property_add_float(props, "gtao_distance", 0.2f);
|
||||
BKE_collection_engine_property_add_float(props, "gtao_factor", 1.0f);
|
||||
BKE_collection_engine_property_add_float(props, "gtao_quality", 0.25f);
|
||||
BKE_collection_engine_property_add_int(props, "gtao_samples", 2);
|
||||
|
||||
BKE_collection_engine_property_add_bool(props, "dof_enable", false);
|
||||
BKE_collection_engine_property_add_float(props, "bokeh_max_size", 100.0f);
|
||||
|
|
|
@ -1113,7 +1113,7 @@ static void render_scene_to_probe(
|
|||
EEVEE_StorageList *stl = vedata->stl;
|
||||
EEVEE_LightProbesInfo *pinfo = sldata->probes;
|
||||
|
||||
float winmat[4][4], wininv[4][4], posmat[4][4], tmp_ao_dist, tmp_ao_samples, tmp_ao_settings;
|
||||
float winmat[4][4], wininv[4][4], posmat[4][4], tmp_ao_dist, tmp_ao_settings;
|
||||
|
||||
unit_m4(posmat);
|
||||
|
||||
|
@ -1127,7 +1127,6 @@ static void render_scene_to_probe(
|
|||
|
||||
/* Disable AO until we find a way to hide really bad discontinuities between cubefaces. */
|
||||
tmp_ao_dist = stl->effects->ao_dist;
|
||||
tmp_ao_samples = stl->effects->ao_samples;
|
||||
tmp_ao_settings = stl->effects->ao_settings;
|
||||
stl->effects->ao_settings = 0.0f; /* Disable AO */
|
||||
|
||||
|
@ -1214,7 +1213,6 @@ static void render_scene_to_probe(
|
|||
stl->g_data->minzbuffer = tmp_minz;
|
||||
txl->maxzbuffer = tmp_maxz;
|
||||
stl->effects->ao_dist = tmp_ao_dist;
|
||||
stl->effects->ao_samples = tmp_ao_samples;
|
||||
stl->effects->ao_settings = tmp_ao_settings;
|
||||
}
|
||||
|
||||
|
|
|
@ -395,11 +395,10 @@ static void add_standard_uniforms(
|
|||
|
||||
if (vedata->stl->effects->use_ao) {
|
||||
DRW_shgroup_uniform_buffer(shgrp, "horizonBuffer", &vedata->txl->gtao_horizons);
|
||||
DRW_shgroup_uniform_ivec2(shgrp, "aoHorizonTexSize", (int *)vedata->stl->effects->ao_texsize, 1);
|
||||
}
|
||||
else {
|
||||
/* Use shadow_pool as fallback to avoid sampling problem on certain platform, see: T52593 */
|
||||
DRW_shgroup_uniform_buffer(shgrp, "horizonBuffer", &sldata->shadow_pool);
|
||||
/* Use maxzbuffer as fallback to avoid sampling problem on certain platform, see: T52593 */
|
||||
DRW_shgroup_uniform_buffer(shgrp, "horizonBuffer", &vedata->txl->maxzbuffer);
|
||||
}
|
||||
|
||||
if (vedata->stl->effects->use_volumetrics && use_alpha_blend) {
|
||||
|
|
|
@ -72,7 +72,9 @@ int EEVEE_occlusion_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata
|
|||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
ViewLayer *view_layer = draw_ctx->view_layer;
|
||||
IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_EEVEE);
|
||||
IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer,
|
||||
COLLECTION_MODE_NONE,
|
||||
RE_engine_id_BLENDER_EEVEE);
|
||||
|
||||
if (BKE_collection_engine_property_value_get_bool(props, "gtao_enable")) {
|
||||
const float *viewport_size = DRW_viewport_size_get();
|
||||
|
@ -85,8 +87,6 @@ int EEVEE_occlusion_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata
|
|||
effects->ao_dist = BKE_collection_engine_property_value_get_float(props, "gtao_distance");
|
||||
effects->ao_factor = BKE_collection_engine_property_value_get_float(props, "gtao_factor");
|
||||
effects->ao_quality = 1.0f - BKE_collection_engine_property_value_get_float(props, "gtao_quality");
|
||||
effects->ao_samples = BKE_collection_engine_property_value_get_int(props, "gtao_samples");
|
||||
effects->ao_samples_inv = 1.0f / effects->ao_samples;
|
||||
|
||||
effects->ao_settings = 1.0; /* USE_AO */
|
||||
if (BKE_collection_engine_property_value_get_bool(props, "gtao_use_bent_normals")) {
|
||||
|
@ -101,29 +101,10 @@ int EEVEE_occlusion_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata
|
|||
effects->ao_texsize[0] = ((int)viewport_size[0]);
|
||||
effects->ao_texsize[1] = ((int)viewport_size[1]);
|
||||
|
||||
/* Round up to multiple of 2 */
|
||||
if ((effects->ao_texsize[0] & 0x1) != 0) {
|
||||
effects->ao_texsize[0] += 1;
|
||||
}
|
||||
if ((effects->ao_texsize[1] & 0x1) != 0) {
|
||||
effects->ao_texsize[1] += 1;
|
||||
}
|
||||
|
||||
CLAMP(effects->ao_samples, 1, 32);
|
||||
|
||||
if (effects->hori_tex_layers != effects->ao_samples) {
|
||||
DRW_TEXTURE_FREE_SAFE(txl->gtao_horizons);
|
||||
}
|
||||
|
||||
if (txl->gtao_horizons == NULL) {
|
||||
effects->hori_tex_layers = effects->ao_samples;
|
||||
txl->gtao_horizons = DRW_texture_create_2D_array((int)viewport_size[0], (int)viewport_size[1], effects->hori_tex_layers, DRW_TEX_RG_8, 0, NULL);
|
||||
}
|
||||
|
||||
DRWFboTexture tex = {&txl->gtao_horizons, DRW_TEX_RG_8, 0};
|
||||
DRWFboTexture tex = {&txl->gtao_horizons, DRW_TEX_RGBA_8, 0};
|
||||
|
||||
DRW_framebuffer_init(&fbl->gtao_fb, &draw_engine_eevee_type,
|
||||
effects->ao_texsize[0], effects->ao_texsize[1],
|
||||
(int)viewport_size[0], (int)viewport_size[1],
|
||||
&tex, 1);
|
||||
|
||||
if (G.debug_value == 6) {
|
||||
|
@ -174,8 +155,6 @@ void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data
|
|||
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);
|
||||
|
||||
|
@ -187,8 +166,6 @@ void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data
|
|||
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);
|
||||
|
||||
|
@ -202,7 +179,6 @@ void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data
|
|||
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_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);
|
||||
}
|
||||
|
@ -213,7 +189,6 @@ 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;
|
||||
EEVEE_FramebufferList *fbl = vedata->fbl;
|
||||
EEVEE_StorageList *stl = vedata->stl;
|
||||
EEVEE_EffectsInfo *effects = stl->effects;
|
||||
|
@ -223,20 +198,13 @@ void EEVEE_occlusion_compute(
|
|||
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)
|
||||
{
|
||||
DRW_framebuffer_texture_detach(txl->gtao_horizons);
|
||||
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_framebuffer_bind(fbl->gtao_fb);
|
||||
|
||||
if (layer >= 0) {
|
||||
DRW_draw_pass(psl->ao_horizon_search_layer);
|
||||
}
|
||||
else {
|
||||
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 */
|
||||
|
|
|
@ -521,7 +521,7 @@ typedef struct EEVEE_EffectsInfo {
|
|||
|
||||
/* Ambient Occlusion */
|
||||
bool use_ao, use_bent_normals;
|
||||
float ao_dist, ao_samples, ao_factor, ao_samples_inv;
|
||||
float ao_dist, pad1, ao_factor, pad2;
|
||||
float ao_offset, ao_bounce_fac, ao_quality, ao_settings;
|
||||
float ao_sample_nbr;
|
||||
int ao_texsize[2], hori_tex_layers;
|
||||
|
|
|
@ -260,11 +260,10 @@ void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *v
|
|||
DRW_shgroup_uniform_vec4(grp, "aoParameters[0]", &effects->ao_dist, 2);
|
||||
if (effects->use_ao) {
|
||||
DRW_shgroup_uniform_buffer(grp, "horizonBuffer", &vedata->txl->gtao_horizons);
|
||||
DRW_shgroup_uniform_ivec2(grp, "aoHorizonTexSize", (int *)vedata->stl->effects->ao_texsize, 1);
|
||||
}
|
||||
else {
|
||||
/* Use shadow_pool as fallback to avoid sampling problem on certain platform, see: T52593 */
|
||||
DRW_shgroup_uniform_buffer(grp, "horizonBuffer", &sldata->shadow_pool);
|
||||
/* Use ssr_specrough_input as fallback to avoid sampling problem on certain platform, see: T52593 */
|
||||
DRW_shgroup_uniform_buffer(grp, "horizonBuffer", &txl->ssr_specrough_input);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_add(grp, quad, NULL);
|
||||
|
|
|
@ -30,87 +30,29 @@
|
|||
#ifndef UTIL_TEX
|
||||
#define UTIL_TEX
|
||||
uniform sampler2DArray utilTex;
|
||||
#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
|
||||
#endif /* UTIL_TEX */
|
||||
|
||||
uniform vec4 aoParameters[2];
|
||||
uniform sampler2DArray horizonBuffer;
|
||||
|
||||
/* Cannot use textureSize(horizonBuffer) when rendering to it */
|
||||
uniform ivec2 aoHorizonTexSize;
|
||||
uniform sampler2D horizonBuffer;
|
||||
|
||||
#define aoDistance aoParameters[0].x
|
||||
#define aoSamples aoParameters[0].y
|
||||
#define aoSamples aoParameters[0].y /* UNUSED */
|
||||
#define aoFactor aoParameters[0].z
|
||||
#define aoInvSamples aoParameters[0].w
|
||||
#define aoInvSamples aoParameters[0].w /* UNUSED */
|
||||
|
||||
#define aoOffset aoParameters[1].x /* UNUSED */
|
||||
#define aoBounceFac aoParameters[1].y
|
||||
#define aoQuality aoParameters[1].z
|
||||
#define aoSettings aoParameters[1].w
|
||||
|
||||
/* aoSettings flags */
|
||||
#define USE_AO 1
|
||||
#define USE_BENT_NORMAL 2
|
||||
#define USE_DENOISE 4
|
||||
|
||||
vec2 pack_horizons(vec2 v) { return v * 0.5 + 0.5; }
|
||||
vec2 unpack_horizons(vec2 v) { return v * 2.0 - 1.0; }
|
||||
|
||||
/* Returns the texel coordinate in horizonBuffer
|
||||
* for a given fullscreen coord */
|
||||
ivec2 get_hr_co(ivec2 fs_co)
|
||||
{
|
||||
bvec2 quarter = notEqual(fs_co & ivec2(1), ivec2(0));
|
||||
|
||||
ivec2 hr_co = fs_co / 2;
|
||||
hr_co += ivec2(quarter) * (aoHorizonTexSize / 2);
|
||||
|
||||
return hr_co;
|
||||
}
|
||||
|
||||
/* Returns the texel coordinate in fullscreen (depthBuffer)
|
||||
* for a given horizonBuffer coord */
|
||||
ivec2 get_fs_co(ivec2 hr_co)
|
||||
{
|
||||
hr_co *= 2;
|
||||
bvec2 quarter = greaterThanEqual(hr_co, aoHorizonTexSize);
|
||||
|
||||
hr_co -= ivec2(quarter) * (aoHorizonTexSize - 1);
|
||||
|
||||
return hr_co;
|
||||
}
|
||||
|
||||
/* Returns the phi angle in horizonBuffer
|
||||
* for a given horizonBuffer coord */
|
||||
float get_phi(ivec2 hr_co, ivec2 fs_co, float sample)
|
||||
{
|
||||
bvec2 quarter = greaterThanEqual(hr_co, aoHorizonTexSize / 2);
|
||||
ivec2 tex_co = ((int(aoSettings) & USE_DENOISE) != 0) ? hr_co - ivec2(quarter) * (aoHorizonTexSize / 2) : fs_co;
|
||||
float blue_noise = texture(utilTex, vec3((vec2(tex_co) + 0.5) / LUT_SIZE, 2.0)).r;
|
||||
|
||||
float phi = sample * aoInvSamples;
|
||||
|
||||
if ((int(aoSettings) & USE_DENOISE) != 0) {
|
||||
/* Interleaved jitter for spatial 2x2 denoising */
|
||||
phi += 0.25 * aoInvSamples * (float(quarter.x) + 2.0 * float(quarter.y));
|
||||
blue_noise *= 0.25;
|
||||
}
|
||||
/* Blue noise is scaled to cover the rest of the range. */
|
||||
phi += aoInvSamples * blue_noise;
|
||||
phi *= M_PI;
|
||||
|
||||
return phi;
|
||||
}
|
||||
|
||||
/* Returns direction jittered offset for a given fullscreen coord */
|
||||
float get_offset(ivec2 fs_co, float sample)
|
||||
{
|
||||
float offset = sample * aoInvSamples;
|
||||
|
||||
/* Interleaved jitter for spatial 2x2 denoising */
|
||||
offset += 0.25 * dot(vec2(1.0), vec2(fs_co & 1));
|
||||
offset += texture(utilTex, vec3((vec2(fs_co / 2) + 0.5 + 16.0) / LUT_SIZE, 2.0)).r;
|
||||
return offset;
|
||||
}
|
||||
vec4 pack_horizons(vec4 v) { return v * 0.5 + 0.5; }
|
||||
vec4 unpack_horizons(vec4 v) { return v * 2.0 - 1.0; }
|
||||
|
||||
/* Returns maximum screen distance an AO ray can travel for a given view depth */
|
||||
vec2 get_max_dir(float view_depth)
|
||||
|
@ -120,6 +62,13 @@ vec2 get_max_dir(float view_depth)
|
|||
return vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) * max_dist;
|
||||
}
|
||||
|
||||
vec2 get_ao_dir(float jitter)
|
||||
{
|
||||
/* Only half a turn because we integrate in slices. */
|
||||
jitter *= M_PI;
|
||||
return vec2(cos(jitter), sin(jitter));
|
||||
}
|
||||
|
||||
void get_max_horizon_grouped(vec4 co1, vec4 co2, vec3 x, float lod, inout float h)
|
||||
{
|
||||
co1 *= mipRatio[int(lod + 1.0)].xyxy; /* +1 because we are using half res top level */
|
||||
|
@ -161,10 +110,8 @@ void get_max_horizon_grouped(vec4 co1, vec4 co2, vec3 x, float lod, inout float
|
|||
h = mix(h, max(h, s_h.w), blend.w);
|
||||
}
|
||||
|
||||
vec2 search_horizon_sweep(float phi, vec3 pos, vec2 uvs, float jitter, vec2 max_dir)
|
||||
vec2 search_horizon_sweep(vec2 t_phi, vec3 pos, vec2 uvs, float jitter, vec2 max_dir)
|
||||
{
|
||||
vec2 t_phi = vec2(cos(phi), sin(phi)); /* Screen space direction */
|
||||
|
||||
max_dir *= max_v2(abs(t_phi));
|
||||
|
||||
/* Convert to pixel space. */
|
||||
|
@ -214,11 +161,8 @@ vec2 search_horizon_sweep(float phi, vec3 pos, vec2 uvs, float jitter, vec2 max_
|
|||
return h;
|
||||
}
|
||||
|
||||
void integrate_slice(vec3 normal, float phi, vec2 horizons, inout float visibility, inout vec3 bent_normal)
|
||||
void integrate_slice(vec3 normal, vec2 t_phi, vec2 horizons, inout float visibility, inout vec3 bent_normal)
|
||||
{
|
||||
/* TODO OPTI Could be precomputed. */
|
||||
vec2 t_phi = vec2(cos(phi), sin(phi)); /* Screen space direction */
|
||||
|
||||
/* Projecting Normal to Plane P defined by t_phi and omega_o */
|
||||
vec3 np = vec3(t_phi.y, -t_phi.x, 0.0); /* Normal vector to Integration plane */
|
||||
vec3 t = vec3(-t_phi, 0.0);
|
||||
|
@ -251,71 +195,43 @@ void integrate_slice(vec3 normal, float phi, vec2 horizons, inout float visibili
|
|||
bent_normal += vec3(sin(b_angle) * -t_phi, cos(b_angle) * 0.5);
|
||||
}
|
||||
|
||||
void denoise_ao(vec3 normal, float frag_depth, inout float visibility, inout vec3 bent_normal)
|
||||
void gtao_deferred(vec3 normal, vec3 position, vec4 noise, float frag_depth, out float visibility, out vec3 bent_normal)
|
||||
{
|
||||
vec2 d_sign = vec2(ivec2(gl_FragCoord.xy) & 1) - 0.5;
|
||||
/* Fetch early, hide latency! */
|
||||
vec4 horizons = texelFetch(horizonBuffer, ivec2(gl_FragCoord.xy), 0);
|
||||
|
||||
if ((int(aoSettings) & USE_DENOISE) == 0) {
|
||||
d_sign *= 0.0;
|
||||
}
|
||||
|
||||
/* 2x2 Bilateral Filter using derivatives. */
|
||||
vec2 n_step = step(-0.2, -abs(vec2(length(dFdx(normal)), length(dFdy(normal)))));
|
||||
vec2 z_step = step(-0.1, -abs(vec2(dFdx(frag_depth), dFdy(frag_depth))));
|
||||
|
||||
visibility -= dFdx(visibility) * d_sign.x * z_step.x * n_step.x;
|
||||
visibility -= dFdy(visibility) * d_sign.y * z_step.y * n_step.y;
|
||||
|
||||
bent_normal -= dFdx(bent_normal) * d_sign.x * z_step.x * n_step.x;
|
||||
bent_normal -= dFdy(bent_normal) * d_sign.y * z_step.y * n_step.y;
|
||||
}
|
||||
|
||||
void gtao_deferred(vec3 normal, vec3 position, float frag_depth, out float visibility, out vec3 bent_normal)
|
||||
{
|
||||
vec4 dirs;
|
||||
dirs.xy = get_ao_dir(noise.x * 0.5);
|
||||
dirs.zw = get_ao_dir(noise.x * 0.5 + 0.5);
|
||||
vec2 uvs = get_uvs_from_view(position);
|
||||
|
||||
vec4 texel_size = vec4(-1.0, -1.0, 1.0, 1.0) / vec2(textureSize(depthBuffer, 0)).xyxy;
|
||||
|
||||
ivec2 fs_co = ivec2(gl_FragCoord.xy);
|
||||
ivec2 hr_co = get_hr_co(fs_co);
|
||||
|
||||
bent_normal = vec3(0.0);
|
||||
visibility = 0.0;
|
||||
|
||||
for (float i = 0.0; i < MAX_PHI_STEP; i++) {
|
||||
if (i >= aoSamples) break;
|
||||
horizons = unpack_horizons(horizons);
|
||||
|
||||
vec2 horiz = unpack_horizons(texelFetch(horizonBuffer, ivec3(hr_co, int(i)), 0).rg);
|
||||
float phi = get_phi(hr_co, fs_co, i);
|
||||
integrate_slice(normal, dirs.xy, horizons.xy, visibility, bent_normal);
|
||||
integrate_slice(normal, dirs.zw, horizons.zw, visibility, bent_normal);
|
||||
|
||||
integrate_slice(normal, phi, horiz.xy, visibility, bent_normal);
|
||||
}
|
||||
visibility *= 0.5; /* We integrated 2 slices. */
|
||||
|
||||
visibility *= aoInvSamples;
|
||||
bent_normal = normalize(bent_normal);
|
||||
}
|
||||
|
||||
void gtao(vec3 normal, vec3 position, vec2 noise, out float visibility, out vec3 bent_normal)
|
||||
void gtao(vec3 normal, vec3 position, vec4 noise, out float visibility, out vec3 bent_normal)
|
||||
{
|
||||
vec2 uvs = get_uvs_from_view(position);
|
||||
|
||||
float homcco = ProjectionMatrix[2][3] * position.z + ProjectionMatrix[3][3];
|
||||
float max_dist = aoDistance / homcco; /* Search distance */
|
||||
vec2 max_dir = max_dist * vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]);
|
||||
vec2 max_dir = get_max_dir(position.z);
|
||||
vec2 dir = get_ao_dir(noise.x);
|
||||
|
||||
bent_normal = vec3(0.0);
|
||||
visibility = 0.0;
|
||||
|
||||
for (float i = 0.0; i < MAX_PHI_STEP; i++) {
|
||||
if (i >= aoSamples) break;
|
||||
/* Only trace in 2 directions. May lead to a darker result but since it's mostly for
|
||||
* alpha blended objects that will have overdraw, we limit the performance impact. */
|
||||
vec2 horizons = search_horizon_sweep(dir, position, uvs, noise.y, max_dir);
|
||||
integrate_slice(normal, dir, horizons, visibility, bent_normal);
|
||||
|
||||
float phi = M_PI * (i + noise.x) * aoInvSamples;
|
||||
vec2 horizons = search_horizon_sweep(phi, position, uvs, noise.g, max_dir);
|
||||
|
||||
integrate_slice(normal, phi, horizons, visibility, bent_normal);
|
||||
}
|
||||
|
||||
visibility *= aoInvSamples;
|
||||
bent_normal = normalize(bent_normal);
|
||||
}
|
||||
|
||||
|
@ -337,7 +253,7 @@ float gtao_multibounce(float visibility, vec3 albedo)
|
|||
}
|
||||
|
||||
/* Use the right occlusion */
|
||||
float occlusion_compute(vec3 N, vec3 vpos, float user_occlusion, vec2 randuv, out vec3 bent_normal)
|
||||
float occlusion_compute(vec3 N, vec3 vpos, float user_occlusion, vec4 rand, out vec3 bent_normal)
|
||||
{
|
||||
#ifndef USE_REFRACTION
|
||||
if ((int(aoSettings) & USE_AO) > 0) {
|
||||
|
@ -345,11 +261,10 @@ float occlusion_compute(vec3 N, vec3 vpos, float user_occlusion, vec2 randuv, ou
|
|||
vec3 vnor = mat3(ViewMatrix) * N;
|
||||
|
||||
#ifdef ENABLE_DEFERED_AO
|
||||
gtao_deferred(vnor, vpos, gl_FragCoord.z, visibility, bent_normal);
|
||||
gtao_deferred(vnor, vpos, rand, gl_FragCoord.z, visibility, bent_normal);
|
||||
#else
|
||||
gtao(vnor, vpos, randuv, visibility, bent_normal);
|
||||
gtao(vnor, vpos, rand, visibility, bent_normal);
|
||||
#endif
|
||||
denoise_ao(vnor, gl_FragCoord.z, visibility, bent_normal);
|
||||
|
||||
/* Prevent some problems down the road. */
|
||||
visibility = max(1e-3, visibility);
|
||||
|
|
|
@ -24,15 +24,14 @@ void main()
|
|||
vec3 bent_normal;
|
||||
float visibility;
|
||||
|
||||
gtao_deferred(normal, viewPosition, depth, visibility, bent_normal);
|
||||
vec4 noise = texelfetch_noise_tex(gl_FragCoord.xy);
|
||||
|
||||
denoise_ao(normal, depth, visibility, bent_normal);
|
||||
gtao_deferred(normal, viewPosition, noise, depth, visibility, bent_normal);
|
||||
|
||||
FragColor = vec4(visibility);
|
||||
}
|
||||
|
||||
#else
|
||||
uniform float sampleNbr;
|
||||
|
||||
#ifdef LAYERED_DEPTH
|
||||
uniform sampler2DArray depthBufferLayered;
|
||||
|
@ -48,10 +47,7 @@ uniform int layer;
|
|||
|
||||
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(gtao_depthBuffer, 0).xy));
|
||||
vec2 uvs = saturate(gl_FragCoord.xy / vec2(textureSize(gtao_depthBuffer, 0).xy));
|
||||
float depth = gtao_textureLod(gtao_depthBuffer, uvs, 0.0).r;
|
||||
|
||||
if (depth == 1.0) {
|
||||
|
@ -64,14 +60,17 @@ void main()
|
|||
depth = saturate(depth - 3e-6); /* Tweaked for 24bit depth buffer. */
|
||||
|
||||
vec3 viewPosition = get_view_space_from_depth(uvs, depth);
|
||||
|
||||
float phi = get_phi(hr_co, fs_co, sampleNbr);
|
||||
float offset = get_offset(fs_co, sampleNbr);
|
||||
vec4 noise = texelfetch_noise_tex(gl_FragCoord.xy);
|
||||
vec2 max_dir = get_max_dir(viewPosition.z);
|
||||
vec4 dirs;
|
||||
dirs.xy = get_ao_dir(noise.x * 0.5);
|
||||
dirs.zw = get_ao_dir(noise.x * 0.5 + 0.5);
|
||||
|
||||
FragColor.xy = search_horizon_sweep(phi, viewPosition, uvs, offset, max_dir);
|
||||
/* Search in 4 directions. */
|
||||
FragColor.xy = search_horizon_sweep(dirs.xy, viewPosition, uvs, noise.y, max_dir);
|
||||
FragColor.zw = search_horizon_sweep(dirs.zw, viewPosition, uvs, noise.y, max_dir);
|
||||
|
||||
/* Resize output for integer texture. */
|
||||
FragColor = pack_horizons(FragColor.xy).xyxy;
|
||||
FragColor = pack_horizons(FragColor);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -199,7 +199,7 @@ void fallback_cubemap(
|
|||
|
||||
vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy);
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, 1.0, rand.rg, bent_normal);
|
||||
float final_ao = occlusion_compute(N, viewPosition, 1.0, rand, bent_normal);
|
||||
final_ao = specular_occlusion(dot(N, V), final_ao, roughness);
|
||||
|
||||
/* Starts at 1 because 0 is world probe */
|
||||
|
|
|
@ -396,7 +396,7 @@ void CLOSURE_NAME(
|
|||
/* ---------------------------- */
|
||||
#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.zw, bent_normal);
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand, bent_normal);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -350,12 +350,10 @@ RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(hair_brightness_randomness)
|
|||
/* ViewLayer settings. */
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_enable)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_use_bent_normals)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_denoise)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_bounce)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_factor)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_quality)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_distance)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(gtao_samples)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(dof_enable)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_max_size)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_threshold)
|
||||
|
@ -1425,13 +1423,6 @@ static void rna_def_view_layer_engine_settings_eevee(BlenderRNA *brna)
|
|||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
|
||||
|
||||
prop = RNA_def_property(srna, "gtao_denoise", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_denoise_get",
|
||||
"rna_LayerEngineSettings_Eevee_gtao_denoise_set");
|
||||
RNA_def_property_ui_text(prop, "Denoise", "Use denoising to filter the resulting occlusion and bent normal but exhibit 2x2 pixel blocks");
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
|
||||
|
||||
prop = RNA_def_property(srna, "gtao_bounce", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_bounce_get",
|
||||
"rna_LayerEngineSettings_Eevee_gtao_bounce_set");
|
||||
|
@ -1463,14 +1454,6 @@ static void rna_def_view_layer_engine_settings_eevee(BlenderRNA *brna)
|
|||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
|
||||
|
||||
prop = RNA_def_property(srna, "gtao_samples", PROP_INT, PROP_UNSIGNED);
|
||||
RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_samples_get",
|
||||
"rna_LayerEngineSettings_Eevee_gtao_samples_set", NULL);
|
||||
RNA_def_property_ui_text(prop, "Samples", "Number of samples to take to compute occlusion");
|
||||
RNA_def_property_range(prop, 2, 32);
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
|
||||
|
||||
/* Depth of Field */
|
||||
prop = RNA_def_property(srna, "dof_enable", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_dof_enable_get",
|
||||
|
|
Loading…
Reference in New Issue