diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-01-16 21:40:17 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-01-16 21:40:17 +0300 |
commit | 213e34a6c32022836337c8bf181b4bbd69fa6097 (patch) | |
tree | 28ab6eb80337475863031ffdf35cb295c8bb8c9e /source/blender/draw/engines/eevee/eevee_materials.c | |
parent | 9fd28c776938fe420782a6339e9da7c619724dae (diff) |
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.
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_materials.c')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_materials.c | 19 |
1 files changed, 19 insertions, 0 deletions
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); + } } } } |