diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-10 00:51:50 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-10 00:52:31 +0300 |
commit | 35594f4b92fa4cbb5b848f447b7a3323e572b676 (patch) | |
tree | 2f5bcfdc0d4bd8ba87bfa6ffa6b89be17ff2fbc7 /source/blender/draw/engines | |
parent | 10865c8f349892cda4715cfe0b2e984c9a844deb (diff) |
Fix T97985 EEVEE: Shader mixing not working correctly when reusing shader nodes
This was caused by the `Closure` members being added to the final contribution
more than once. The workaround is to clear the members once a closure has
been added to the final contribution. I used `inout` on `Closure` inputs
so that the render engine implementation of mix and add closure nodes
can do its own thing. The nodegraph handling of inout was changed for this
to work.
Diffstat (limited to 'source/blender/draw/engines')
3 files changed, 9 insertions, 6 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl index f85ef4a89a4..0f5290a7c07 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl @@ -309,16 +309,19 @@ vec4 closure_to_rgba(Closure closure) return vec4(closure.radiance, 1.0 - saturate(avg(closure.transmittance))); } -Closure closure_add(Closure cl1, Closure cl2) +Closure closure_add(inout Closure cl1, inout Closure cl2) { Closure cl; cl.radiance = cl1.radiance + cl2.radiance; cl.transmittance = cl1.transmittance + cl2.transmittance; cl.holdout = cl1.holdout + cl2.holdout; + /* Make sure each closure is only added once to the result. */ + cl1 = CLOSURE_DEFAULT; + cl2 = CLOSURE_DEFAULT; return cl; } -Closure closure_mix(Closure cl1, Closure cl2, float fac) +Closure closure_mix(inout Closure cl1, inout Closure cl2, float fac) { /* Weights have already been applied. */ return closure_add(cl1, cl2); diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_volume_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_volume_lib.glsl index e450b8ad3c8..5e34d654cfd 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_eval_volume_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_eval_volume_lib.glsl @@ -92,7 +92,7 @@ vec4 closure_to_rgba(Closure closure) return vec4(0.0); } -Closure closure_mix(Closure cl1, Closure cl2, float fac) +Closure closure_mix(inout Closure cl1, inout Closure cl2, float fac) { Closure cl; cl.absorption = mix(cl1.absorption, cl2.absorption, fac); @@ -102,7 +102,7 @@ Closure closure_mix(Closure cl1, Closure cl2, float fac) return cl; } -Closure closure_add(Closure cl1, Closure cl2) +Closure closure_add(inout Closure cl1, inout Closure cl2) { Closure cl; cl.absorption = cl1.absorption + cl2.absorption; diff --git a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl index 9698b5ea6f5..21d347942ca 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl @@ -87,8 +87,8 @@ Closure closure_eval(ClosureDiffuse diffuse, ClosureReflection clearcoat, ClosureRefraction refraction); -Closure closure_add(Closure cl1, Closure cl2); -Closure closure_mix(Closure cl1, Closure cl2, float fac); +Closure closure_add(inout Closure cl1, inout Closure cl2); +Closure closure_mix(inout Closure cl1, inout Closure cl2, float fac); float ambient_occlusion_eval(vec3 normal, float distance, |