[Bf-blender-cvs] [213e34a6c32] blender2.8: Eevee: Fix Hashed Alpha.
Clément Foucault
noreply at git.blender.org
Tue Jan 16 19:41:40 CET 2018
Commit: 213e34a6c32022836337c8bf181b4bbd69fa6097
Author: Clément Foucault
Date: Tue Jan 16 19:40:17 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB213e34a6c32022836337c8bf181b4bbd69fa6097
Eevee: Fix Hashed Alpha.
Now hashed alpha materials are stable when moving the camera/not using TAA.
It also converge to a noise free image when using TAA. No more numerical imprecision.
There still can be situations with multiple overlapping transparent surfaces that can lead to residual noise.
===================================================================
M source/blender/draw/engines/eevee/eevee_materials.c
M source/blender/draw/engines/eevee/shaders/prepass_frag.glsl
===================================================================
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index f4bef9afed1..8149c105a81 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -28,6 +28,7 @@
#include "BLI_dynstr.h"
#include "BLI_ghash.h"
#include "BLI_alloca.h"
+#include "BLI_rand.h"
#include "BKE_particle.h"
#include "BKE_paint.h"
@@ -61,6 +62,7 @@ static struct {
unsigned int sss_count;
float viewvecs[2][4];
+ float alpha_hash_offset;
} e_data = {NULL}; /* Engine data */
extern char datatoc_lamps_lib_glsl[];
@@ -548,6 +550,19 @@ void EEVEE_materials_init(EEVEE_StorageList *stl)
EEVEE_update_util_texture(offsets);
}
+ /* Alpha hash scale: Non-flickering size if we are not refining the render. */
+ if (!DRW_state_is_image_render() &&
+ (((stl->effects->enabled_effects & EFFECT_TAA) == 0) ||
+ (stl->effects->taa_current_sample == 1)))
+ {
+ e_data.alpha_hash_offset = 0.0f;
+ }
+ else {
+ double r;
+ BLI_halton_1D(5, 0.0, stl->effects->taa_current_sample, &r);
+ e_data.alpha_hash_offset = (float)r;
+ }
+
{
/* Update viewvecs */
const bool is_persp = DRW_viewport_is_persp_get();
@@ -1069,6 +1084,10 @@ static void material_opaque(
DRW_shgroup_uniform_float(*shgrp_depth, "alphaThreshold", &ma->alpha_threshold, 1);
DRW_shgroup_uniform_float(*shgrp_depth_clip, "alphaThreshold", &ma->alpha_threshold, 1);
}
+ 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);
+ }
}
}
}
diff --git a/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl b/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl
index f921d56e3bc..1c0e65f0613 100644
--- a/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl
@@ -10,14 +10,15 @@ float hash3d(vec3 a) {
return hash(vec2(hash(a.xy), a.z));
}
-//uniform float hashScale;
-float hashScale = 0.001;
+uniform float hashAlphaOffset;
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 / (hashScale * max_deriv);
+ float pix_scale = 1.0 / (hash_scale * max_deriv);
/* Find two nearest log-discretized noise scales. */
float pix_scale_log = log2(pix_scale);
@@ -53,7 +54,8 @@ float hashed_alpha_threshold(vec3 co)
/* Avoids threshold == 0. */
threshold = clamp(threshold, 1.0e-6, 1.0);
- return threshold;
+ /* Jitter the threshold for TAA accumulation. */
+ return fract(threshold + hashAlphaOffset);
}
#endif
More information about the Bf-blender-cvs
mailing list