From 213e34a6c32022836337c8bf181b4bbd69fa6097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 16 Jan 2018 19:40:17 +0100 Subject: 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. --- source/blender/draw/engines/eevee/eevee_materials.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/blender/draw/engines/eevee/eevee_materials.c') 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); + } } } } -- cgit v1.2.3