Commit: d16342e5fd1f51c01bc1f9becc6ec0704d783de8
Author: Clément Foucault
Date:   Wed Aug 9 16:54:18 2017 +0200
Branches: blender2.8
https://developer.blender.org/rBd16342e5fd1f51c01bc1f9becc6ec0704d783de8

Eevee: Add Screen Space Refraction.

For the moment the only way to enable this is to:
- enable Screen Space REFLECTIONS.
- enable Screen Space Refraction in the SSR parameters.
- enable Screen Space Refraction in the material tab.

===================================================================

M       release/scripts/startup/bl_ui/properties_material.py
M       release/scripts/startup/bl_ui/properties_render.py
M       release/scripts/startup/bl_ui/properties_render_layer.py
M       source/blender/draw/CMakeLists.txt
M       source/blender/draw/engines/eevee/eevee_effects.c
M       source/blender/draw/engines/eevee/eevee_engine.c
M       source/blender/draw/engines/eevee/eevee_materials.c
M       source/blender/draw/engines/eevee/eevee_private.h
M       source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
A       source/blender/draw/engines/eevee/shaders/ssr_lib.glsl
M       source/blender/makesdna/DNA_material_types.h
M       source/blender/makesrna/intern/rna_material.c
M       source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_material.py 
b/release/scripts/startup/bl_ui/properties_material.py
index e513fb1b7a2..1ad4a5160ce 100644
--- a/release/scripts/startup/bl_ui/properties_material.py
+++ b/release/scripts/startup/bl_ui/properties_material.py
@@ -1182,6 +1182,7 @@ class EEVEE_MATERIAL_PT_options(MaterialButtonsPanel, 
Panel):
 
         if mat.blend_method not in {"OPAQUE", "CLIP", "HASHED"}:
             layout.prop(mat, "transparent_hide_backside")
+            layout.prop(mat, "transparent_refraction")
 
 
 
diff --git a/release/scripts/startup/bl_ui/properties_render.py 
b/release/scripts/startup/bl_ui/properties_render.py
index fdc98e4ad25..70db35c8c56 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -730,6 +730,7 @@ class 
RENDER_PT_eevee_screen_space_reflections(RenderButtonsPanel, Panel):
         props = scene.layer_properties['BLENDER_EEVEE']
 
         col = layout.column()
+        col.prop(props, "ssr_refraction")
         col.prop(props, "ssr_halfres")
         col.prop(props, "ssr_ray_count")
         col.prop(props, "ssr_quality")
diff --git a/release/scripts/startup/bl_ui/properties_render_layer.py 
b/release/scripts/startup/bl_ui/properties_render_layer.py
index 168d1dcb242..edbaddc4f6c 100644
--- a/release/scripts/startup/bl_ui/properties_render_layer.py
+++ b/release/scripts/startup/bl_ui/properties_render_layer.py
@@ -276,6 +276,7 @@ class 
RENDERLAYER_PT_eevee_screen_space_reflections(RenderLayerButtonsPanel, Pan
 
         col = layout.column()
         col.template_override_property(layer_props, scene_props, "ssr_halfres")
+        col.template_override_property(layer_props, scene_props, 
"ssr_refraction")
         col.template_override_property(layer_props, scene_props, 
"ssr_ray_count")
         col.template_override_property(layer_props, scene_props, "ssr_quality")
         col.template_override_property(layer_props, scene_props, 
"ssr_max_roughness")
diff --git a/source/blender/draw/CMakeLists.txt 
b/source/blender/draw/CMakeLists.txt
index 3293b4d7241..d5e4a402330 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -163,6 +163,7 @@ data_to_c_simple(engines/eevee/shaders/octahedron_lib.glsl 
SRC)
 data_to_c_simple(engines/eevee/shaders/bsdf_sampling_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/raytrace_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/ltc_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/ssr_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/volumetric_frag.glsl SRC)
 
 data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
diff --git a/source/blender/draw/engines/eevee/eevee_effects.c 
b/source/blender/draw/engines/eevee/eevee_effects.c
index b01f46b1651..85bd15757dc 100644
--- a/source/blender/draw/engines/eevee/eevee_effects.c
+++ b/source/blender/draw/engines/eevee/eevee_effects.c
@@ -584,6 +584,14 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, 
EEVEE_Data *vedata)
        if (BKE_collection_engine_property_value_get_bool(props, "ssr_enable")) 
{
                effects->enabled_effects |= EFFECT_SSR;
 
+               if (BKE_collection_engine_property_value_get_bool(props, 
"ssr_refraction")) {
+                       effects->enabled_effects |= EFFECT_REFRACT;
+
+                       DRWFboTexture tex = {&txl->refract_color, 
DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
+
+                       DRW_framebuffer_init(&fbl->refract_fb, 
&draw_engine_eevee_type, (int)viewport_size[0], (int)viewport_size[1], &tex, 1);
+               }
+
                /* Enable double buffering to be able to read previous frame 
color */
                effects->enabled_effects |= EFFECT_DOUBLE_BUFFER;
 
@@ -1072,6 +1080,20 @@ void EEVEE_effects_do_volumetrics(EEVEE_SceneLayerData 
*sldata, EEVEE_Data *veda
        }
 }
 
+void EEVEE_effects_do_refraction(EEVEE_SceneLayerData *UNUSED(sldata), 
EEVEE_Data *vedata)
+{
+       EEVEE_FramebufferList *fbl = vedata->fbl;
+       EEVEE_TextureList *txl = vedata->txl;
+       EEVEE_StorageList *stl = vedata->stl;
+       EEVEE_EffectsInfo *effects = stl->effects;
+
+       if ((effects->enabled_effects & EFFECT_REFRACT) != 0) {
+               DRW_framebuffer_texture_attach(fbl->refract_fb, 
txl->refract_color, 0, 0);
+               DRW_framebuffer_blit(fbl->main, fbl->refract_fb, false);
+               EEVEE_downsample_buffer(vedata, fbl->downsample_fb, 
txl->refract_color, 9);
+       }
+}
+
 void EEVEE_effects_do_ssr(EEVEE_SceneLayerData *UNUSED(sldata), EEVEE_Data 
*vedata)
 {
        EEVEE_PassList *psl = vedata->psl;
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c 
b/source/blender/draw/engines/eevee/eevee_engine.c
index f2af9c53aa8..fd8c9c5ea4a 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -199,6 +199,12 @@ static void EEVEE_draw_scene(void *vedata)
                EEVEE_effects_do_volumetrics(sldata, vedata);
                DRW_stats_group_end();
 
+               /* Prepare Refraction */
+               EEVEE_effects_do_refraction(sldata, vedata);
+
+               /* Restore main FB */
+               DRW_framebuffer_bind(fbl->main);
+
                /* Transparent */
                DRW_pass_sort_shgroup_z(psl->transparent_pass);
                DRW_stats_group_start("Transparent");
@@ -235,7 +241,9 @@ static void EEVEE_scene_layer_settings_create(RenderEngine 
*UNUSED(engine), IDPr
                   props->type == IDP_GROUP &&
                   props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
 
+
        BKE_collection_engine_property_add_bool(props, "ssr_enable", false);
+       BKE_collection_engine_property_add_bool(props, "ssr_refraction", false);
        BKE_collection_engine_property_add_bool(props, "ssr_halfres", true);
        BKE_collection_engine_property_add_int(props, "ssr_ray_count", 1);
        BKE_collection_engine_property_add_float(props, "ssr_quality", 0.25f);
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c 
b/source/blender/draw/engines/eevee/eevee_materials.c
index 65e91a38053..b961591178a 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -98,6 +98,8 @@ extern char datatoc_irradiance_lib_glsl[];
 extern char datatoc_octahedron_lib_glsl[];
 extern char datatoc_lit_surface_frag_glsl[];
 extern char datatoc_lit_surface_vert_glsl[];
+extern char datatoc_raytrace_lib_glsl[];
+extern char datatoc_ssr_lib_glsl[];
 extern char datatoc_shadow_vert_glsl[];
 extern char datatoc_shadow_geom_glsl[];
 extern char datatoc_lightprobe_geom_glsl[];
@@ -307,6 +309,9 @@ static char *eevee_get_defines(int options)
        if ((options & VAR_MAT_MULT) != 0) {
                BLI_dynstr_appendf(ds, "#define USE_MULTIPLY\n");
        }
+       if ((options & VAR_MAT_REFRACT) != 0) {
+               BLI_dynstr_appendf(ds, "#define USE_REFRACTION\n");
+       }
 
        str = BLI_dynstr_get_cstring(ds);
        BLI_dynstr_free(ds);
@@ -346,7 +351,9 @@ static char *eevee_get_volume_defines(int options)
 /**
  * ssr_id can be null to disable ssr contribution.
  **/
-static void add_standard_uniforms(DRWShadingGroup *shgrp, EEVEE_SceneLayerData 
*sldata, EEVEE_Data *vedata, int *ssr_id)
+static void add_standard_uniforms(
+        DRWShadingGroup *shgrp, EEVEE_SceneLayerData *sldata, EEVEE_Data 
*vedata,
+        int *ssr_id, float *refract_thickness)
 {
        if (ssr_id == NULL) {
                static int no_ssr = -1.0f;
@@ -372,9 +379,20 @@ static void add_standard_uniforms(DRWShadingGroup *shgrp, 
EEVEE_SceneLayerData *
        DRW_shgroup_uniform_buffer(shgrp, "shadowCubes", 
&sldata->shadow_depth_cube_pool);
        DRW_shgroup_uniform_buffer(shgrp, "shadowCascades", 
&sldata->shadow_depth_cascade_pool);
        DRW_shgroup_uniform_int(shgrp, "outputSsrId", ssr_id, 1);
+       if (vedata->stl->effects->use_ao || refract_thickness) {
+               DRW_shgroup_uniform_vec4(shgrp, "viewvecs[0]", (float 
*)vedata->stl->g_data->viewvecs, 2);
+               DRW_shgroup_uniform_buffer(shgrp, "maxzBuffer", 
&vedata->txl->maxzbuffer);
+       }
+       if (refract_thickness) {
+               DRW_shgroup_uniform_buffer(shgrp, "colorBuffer", 
&vedata->txl->refract_color);
+               DRW_shgroup_uniform_float(shgrp, "refractionThickness", 
refract_thickness, 1);
+               DRW_shgroup_uniform_vec4(shgrp, "ssrParameters", 
&vedata->stl->effects->ssr_quality, 1);
+               DRW_shgroup_uniform_float(shgrp, "borderFadeFactor", 
&vedata->stl->effects->ssr_border_fac, 1);
+               DRW_shgroup_uniform_float(shgrp, "maxRoughness", 
&vedata->stl->effects->ssr_max_roughness, 1);
+               DRW_shgroup_uniform_vec2(shgrp, "mipRatio[0]", (float 
*)vedata->stl->g_data->mip_ratio, 10);
+               DRW_shgroup_uniform_int(shgrp, "rayCount", 
&vedata->stl->effects->ssr_ray_count, 1);
+       }
        if (vedata->stl->effects->use_ao) {
-               DRW_shgroup_uniform_vec4(shgrp, "viewvecs[0]", (float 
*)&vedata->stl->g_data->viewvecs, 2);
-               DRW_shgroup_uniform_buffer(shgrp, "minMaxDepthTex", 
&vedata->txl->maxzbuffer);
                DRW_shgroup_uniform_vec3(shgrp, "aoParameters", 
&vedata->stl->effects->ao_dist, 1);
        }
 }
@@ -403,7 +421,10 @@ void EEVEE_materials_init(EEVEE_StorageList *stl)
                /* Shaders */
                DynStr *ds_frag = BLI_dynstr_new();
                BLI_dynstr_append(ds_frag, datatoc_bsdf_common_lib_glsl);
+               BLI_dynstr_append(ds_frag, datatoc_bsdf_sampling_lib_glsl);
                BLI_dynstr_append(ds_frag, datatoc_ambient_occlusion_lib_glsl);
+               BLI_dynstr_append(ds_frag, datatoc_raytrace_lib_glsl);
+               BLI_dynstr_append(ds_frag, datatoc_ssr_lib_glsl);
                BLI_dynstr_append(ds_frag, datatoc_octahedron_lib_glsl);
                BLI_dynstr_append(ds_frag, datatoc_irradiance_lib_glsl);
                BLI_dynstr_append(ds_frag, datatoc_lightprobe_lib_glsl);
@@ -591,7 +612,8 @@ struct GPUMaterial *EEVEE_material_world_volume_get(
 
 struct GPUMaterial *EEVEE_material_mesh_get(
         struct Scene *scene, Material *ma,
-        bool use_ao, bool use_bent_normals, bool use_blend, bool use_multiply)
+        bool use_ao, bool use_bent_normals, bool use_blend,
+        bool use_multiply, bool use_refract)
 {
        const void *engine = &DRW_engine_viewport_eevee_type;
        int options = VAR_MAT_MESH;
@@ -600,6 +622,7 @@ struct GPUMaterial *EEVEE_material_mesh_get(
        if (use_bent_normals) options |= VAR_MAT_BENT;
        if (use_blend) options |= VAR_MAT_BLEND;
        if (use_multiply) options |= VAR_MAT_MULT;
+       if (use_refract) options |= VAR_MAT_REFRACT;
 
        GPUMaterial *mat = GPU_material_from_nodetree_find(&ma->gpumaterial, 
engine, options);
        if (mat) {
@@ -710,7 +733,7 @@ static struct DRWShadingGroup 
*EEVEE_default_shading_group_create(
        }
 
        DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.d

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to