Eevee: Fix refraction materials
authorClément Foucault <foucault.clem@gmail.com>
Thu, 8 Nov 2018 12:07:22 +0000 (13:07 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Thu, 8 Nov 2018 18:20:40 +0000 (19:20 +0100)
Fix refraction depth not working without ScreenSpace Refraction.
Fix ScreenSpace Refraction masking reflections.

source/blender/draw/engines/eevee/eevee_materials.c
source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl

index 212f89e72166a2aa2c4b80f5e5d93046dc7ee2e2..78d5231a7931a57888ccd268031f9b85432f651b 100644 (file)
@@ -407,10 +407,11 @@ static void add_standard_uniforms(
                DRW_shgroup_uniform_texture_ref(shgrp, "probePlanars", &vedata->txl->planar_pool);
                DRW_shgroup_uniform_int(shgrp, "outputSsrId", ssr_id, 1);
        }
-       if (use_refract && use_ssrefraction) {
-               BLI_assert(refract_depth != NULL);
-               DRW_shgroup_uniform_float(shgrp, "refractionDepth", refract_depth, 1);
-               DRW_shgroup_uniform_texture_ref(shgrp, "colorBuffer", &vedata->txl->refract_color);
+       if (use_refract) {
+               DRW_shgroup_uniform_float_copy(shgrp, "refractionDepth", (refract_depth) ? *refract_depth : 0.0 );
+               if (use_ssrefraction) {
+                       DRW_shgroup_uniform_texture_ref(shgrp, "colorBuffer", &vedata->txl->refract_color);
+               }
        }
 
        if ((vedata->stl->effects->enabled_effects & EFFECT_VOLUMETRIC) != 0 &&
index 164b6da68bf29c24672e0d150d5a7ca3210ba943..091709ebdd1f16f5909ca20a32ad241969c88f4b 100644 (file)
@@ -330,37 +330,55 @@ void CLOSURE_NAME(
        /* ---------------------------- */
 #if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
 
-       #ifdef CLOSURE_REFRACTION
-               #define ACCUM refr_accum
+       #if defined(CLOSURE_GLOSSY) && defined(CLOSURE_REFRACTION)
+               #define GLASS_ACCUM 1
+               #define ACCUM min(refr_accum.a, spec_accum.a)
+       #elif defined(CLOSURE_REFRACTION)
+               #define GLASS_ACCUM 0
+               #define ACCUM refr_accum.a
        #else
-               #define ACCUM spec_accum
+               #define GLASS_ACCUM 0
+               #define ACCUM spec_accum.a
        #endif
 
        /* Starts at 1 because 0 is world probe */
-       for (int i = 1; ACCUM.a < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; ++i) {
+       for (int i = 1; ACCUM < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; ++i) {
                float fade = probe_attenuation_cube(i, worldPosition);
 
                if (fade > 0.0) {
 
-       #ifdef CLOSURE_GLOSSY
-                       if (!(ssrToggle && ssr_id == outputSsrId)) {
-                               vec3 spec = probe_evaluate_cube(i, worldPosition, spec_dir, roughness);
-                               accumulate_light(spec, fade, spec_accum);
-                       }
+       #if GLASS_ACCUM
+                       if (spec_accum.a < 0.999) {
        #endif
+               #ifdef CLOSURE_GLOSSY
+                               if (!(ssrToggle && ssr_id == outputSsrId)) {
+                                       vec3 spec = probe_evaluate_cube(i, worldPosition, spec_dir, roughness);
+                                       accumulate_light(spec, fade, spec_accum);
+                               }
+               #endif
 
-       #ifdef CLOSURE_CLEARCOAT
-                       vec3 C_spec = probe_evaluate_cube(i, worldPosition, C_spec_dir, C_roughness);
-                       accumulate_light(C_spec, fade, C_spec_accum);
+               #ifdef CLOSURE_CLEARCOAT
+                               vec3 C_spec = probe_evaluate_cube(i, worldPosition, C_spec_dir, C_roughness);
+                               accumulate_light(C_spec, fade, C_spec_accum);
+               #endif
+       #if GLASS_ACCUM
+                       }
        #endif
 
-       #ifdef CLOSURE_REFRACTION
-                       vec3 trans = probe_evaluate_cube(i, refr_pos, refr_dir, roughnessSquared);
-                       accumulate_light(trans, fade, refr_accum);
+       #if GLASS_ACCUM
+                       if (refr_accum.a < 0.999) {
+       #endif
+               #ifdef CLOSURE_REFRACTION
+                               vec3 trans = probe_evaluate_cube(i, refr_pos, refr_dir, roughnessSquared);
+                               accumulate_light(trans, fade, refr_accum);
+               #endif
+       #if GLASS_ACCUM
+                       }
        #endif
                }
        }
 
+       #undef GLASS_ACCUM
        #undef ACCUM
 
        /* ---------------------------- */