Eevee: Improve Hashed Alpha transparency by reducing noise size

This only affect renders and static viewport accumulation.
It reduces helps reduce noise when lots of half transparent surfaces
overlaps.
This commit is contained in:
Clément Foucault
2018-11-06 16:49:05 +01:00
parent 8a204ccdb4
commit fac2cfdfa7
2 changed files with 7 additions and 3 deletions

View File

@@ -71,6 +71,7 @@ static struct {
uint sss_count;
float alpha_hash_offset;
float alpha_hash_scale;
float noise_offsets[3];
} e_data = {NULL}; /* Engine data */
@@ -635,11 +636,13 @@ void EEVEE_materials_init(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, E
((stl->effects->enabled_effects & EFFECT_TAA) == 0))
{
e_data.alpha_hash_offset = 0.0f;
e_data.alpha_hash_scale = 1.0f;
}
else {
double r;
BLI_halton_1D(5, 0.0, stl->effects->taa_current_sample - 1, &r);
e_data.alpha_hash_offset = (float)r;
e_data.alpha_hash_scale = 0.01f;
}
{
@@ -1206,6 +1209,8 @@ static void material_opaque(
else if (ma->blend_method == MA_BM_HASHED) {
DRW_shgroup_uniform_float(*shgrp_depth, "hashAlphaOffset", &e_data.alpha_hash_offset, 1);
DRW_shgroup_uniform_float(*shgrp_depth_clip, "hashAlphaOffset", &e_data.alpha_hash_offset, 1);
DRW_shgroup_uniform_float_copy(*shgrp_depth, "hashAlphaScale", e_data.alpha_hash_scale);
DRW_shgroup_uniform_float_copy(*shgrp_depth_clip, "hashAlphaScale", e_data.alpha_hash_scale);
}
}
}

View File

@@ -11,14 +11,13 @@ float hash3d(vec3 a) {
}
uniform float hashAlphaOffset;
uniform float hashAlphaScale = 1.0; /* Roughly in pixel */
float hashed_alpha_threshold(vec3 co)
{
const float hash_scale = 1.0; /* Roughly in pixel */
/* Find the discretized derivatives of our coordinates. */
float max_deriv = max(length(dFdx(co)), length(dFdy(co)));
float pix_scale = 1.0 / (hash_scale * max_deriv);
float pix_scale = 1.0 / (hashAlphaScale * max_deriv);
/* Find two nearest log-discretized noise scales. */
float pix_scale_log = log2(pix_scale);