Eevee: SSR: Add fullscreen raytrace option and Screen border factor.
This commit is contained in:
@@ -726,6 +726,7 @@ class RENDER_PT_eevee_shading(RenderButtonsPanel, Panel):
|
||||
|
||||
col = layout.column()
|
||||
col.prop(props, "ssr_enable")
|
||||
col.prop(props, "ssr_halfres")
|
||||
col.prop(props, "ssr_stride")
|
||||
col.prop(props, "ssr_thickness")
|
||||
col.prop(props, "ssr_border_fade")
|
||||
|
||||
@@ -268,6 +268,7 @@ class RENDERLAYER_PT_eevee_shading(RenderLayerButtonsPanel, Panel):
|
||||
|
||||
col = layout.column()
|
||||
col.template_override_property(layer_props, scene_props, "ssr_enable")
|
||||
col.template_override_property(layer_props, scene_props, "ssr_halfres")
|
||||
col.template_override_property(layer_props, scene_props, "ssr_stride")
|
||||
col.template_override_property(layer_props, scene_props, "ssr_thickness")
|
||||
|
||||
|
||||
@@ -548,9 +548,10 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
|
||||
/* Enable double buffering to be able to read previous frame color */
|
||||
effects->enabled_effects |= EFFECT_DOUBLE_BUFFER;
|
||||
|
||||
effects->reflection_trace_full = true;
|
||||
effects->reflection_trace_full = !BKE_collection_engine_property_value_get_bool(props, "ssr_halfres");
|
||||
effects->ssr_stride = (float)BKE_collection_engine_property_value_get_int(props, "ssr_stride");
|
||||
effects->ssr_thickness = BKE_collection_engine_property_value_get_float(props, "ssr_thickness");
|
||||
effects->ssr_border_fac = BKE_collection_engine_property_value_get_float(props, "ssr_border_fade");
|
||||
|
||||
const int divisor = (effects->reflection_trace_full) ? 1 : 2;
|
||||
int tracing_res[2] = {(int)viewport_size[0] / divisor, (int)viewport_size[1] / divisor};
|
||||
@@ -578,8 +579,8 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
|
||||
|
||||
/* Raytracing output */
|
||||
/* TODO try integer format for hit coord to increase precision */
|
||||
DRWFboTexture tex_output[2] = {{&txl->ssr_hit_output, (record_two_hit) ? DRW_TEX_RGBA_16 : DRW_TEX_RG_16, 0},
|
||||
{&txl->ssr_pdf_output, (record_two_hit) ? DRW_TEX_RG_16 : DRW_TEX_R_16, 0}};
|
||||
DRWFboTexture tex_output[2] = {{&stl->g_data->ssr_hit_output, (record_two_hit) ? DRW_TEX_RGBA_16 : DRW_TEX_RG_16, DRW_TEX_TEMP},
|
||||
{&stl->g_data->ssr_pdf_output, (record_two_hit) ? DRW_TEX_RG_16 : DRW_TEX_R_16, DRW_TEX_TEMP}};
|
||||
|
||||
DRW_framebuffer_init(&fbl->screen_tracing_fb, &draw_engine_eevee_type, tracing_res[0], tracing_res[1], tex_output, 2);
|
||||
|
||||
@@ -605,8 +606,6 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
|
||||
/* Cleanup to release memory */
|
||||
DRW_TEXTURE_FREE_SAFE(txl->ssr_normal_input);
|
||||
DRW_TEXTURE_FREE_SAFE(txl->ssr_specrough_input);
|
||||
DRW_TEXTURE_FREE_SAFE(txl->ssr_hit_output);
|
||||
DRW_TEXTURE_FREE_SAFE(txl->ssr_pdf_output);
|
||||
DRW_FRAMEBUFFER_FREE_SAFE(fbl->screen_tracing_fb);
|
||||
}
|
||||
|
||||
@@ -736,11 +735,12 @@ void EEVEE_effects_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
|
||||
DRW_shgroup_uniform_buffer(grp, "specroughBuffer", &txl->ssr_specrough_input);
|
||||
DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
|
||||
DRW_shgroup_uniform_buffer(grp, "colorBuffer", &txl->color_double_buffer);
|
||||
DRW_shgroup_uniform_buffer(grp, "hitBuffer", &txl->ssr_hit_output);
|
||||
DRW_shgroup_uniform_buffer(grp, "pdfBuffer", &txl->ssr_pdf_output);
|
||||
DRW_shgroup_uniform_buffer(grp, "hitBuffer", &stl->g_data->ssr_hit_output);
|
||||
DRW_shgroup_uniform_buffer(grp, "pdfBuffer", &stl->g_data->ssr_pdf_output);
|
||||
DRW_shgroup_uniform_mat4(grp, "PastViewProjectionMatrix", (float *)stl->g_data->prev_persmat);
|
||||
DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)stl->g_data->viewvecs, 2);
|
||||
DRW_shgroup_uniform_int(grp, "probe_count", &sldata->probes->num_render_cube, 1);
|
||||
DRW_shgroup_uniform_float(grp, "borderFadeFactor", &effects->ssr_border_fac, 1);
|
||||
DRW_shgroup_uniform_float(grp, "lodCubeMax", &sldata->probes->lod_cube_max, 1);
|
||||
DRW_shgroup_uniform_float(grp, "lodPlanarMax", &sldata->probes->lod_planar_max, 1);
|
||||
DRW_shgroup_uniform_buffer(grp, "probeCubes", &sldata->probe_pool);
|
||||
@@ -998,21 +998,25 @@ void EEVEE_effects_do_ssr(EEVEE_SceneLayerData *UNUSED(sldata), EEVEE_Data *veda
|
||||
if ((effects->enabled_effects & EFFECT_SSR) != 0) {
|
||||
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
||||
|
||||
if (stl->g_data->valid_double_buffer) {
|
||||
EEVEE_downsample_buffer(vedata, fbl->downsample_fb, txl->color_double_buffer, 9);
|
||||
DRW_framebuffer_texture_attach(fbl->screen_tracing_fb, stl->g_data->ssr_hit_output, 0, 0);
|
||||
DRW_framebuffer_texture_attach(fbl->screen_tracing_fb, stl->g_data->ssr_pdf_output, 1, 0);
|
||||
DRW_framebuffer_bind(fbl->screen_tracing_fb);
|
||||
|
||||
if (stl->g_data->valid_double_buffer) {
|
||||
/* Raytrace at halfres. */
|
||||
e_data.depth_src = dtxl->depth;
|
||||
// e_data.depth_src = stl->g_data->minmaxz;
|
||||
DRW_framebuffer_bind(fbl->screen_tracing_fb);
|
||||
DRW_draw_pass(psl->ssr_raytrace);
|
||||
|
||||
EEVEE_downsample_buffer(vedata, fbl->downsample_fb, txl->color_double_buffer, 9);
|
||||
}
|
||||
else {
|
||||
float clear_col[4] = {-1.0f, -1.0f, -1.0f, -1.0f};
|
||||
DRW_framebuffer_bind(fbl->screen_tracing_fb);
|
||||
DRW_framebuffer_clear(true, false, false, clear_col, 0.0f);
|
||||
}
|
||||
|
||||
DRW_framebuffer_texture_detach(stl->g_data->ssr_hit_output);
|
||||
DRW_framebuffer_texture_detach(stl->g_data->ssr_pdf_output);
|
||||
|
||||
/* Resolve at fullres */
|
||||
e_data.depth_src = dtxl->depth;
|
||||
DRW_framebuffer_texture_detach(dtxl->depth);
|
||||
@@ -1187,10 +1191,10 @@ void EEVEE_draw_effects(EEVEE_Data *vedata)
|
||||
if (stl->g_data->minzbuffer) DRW_transform_to_display(stl->g_data->minzbuffer);
|
||||
break;
|
||||
case 2:
|
||||
if (txl->ssr_hit_output) DRW_transform_to_display(txl->ssr_hit_output);
|
||||
if (stl->g_data->ssr_hit_output) DRW_transform_to_display(stl->g_data->ssr_hit_output);
|
||||
break;
|
||||
case 3:
|
||||
if (txl->ssr_pdf_output) DRW_transform_to_display(txl->ssr_pdf_output);
|
||||
if (stl->g_data->ssr_pdf_output) DRW_transform_to_display(stl->g_data->ssr_pdf_output);
|
||||
break;
|
||||
case 4:
|
||||
if (txl->ssr_normal_input) DRW_transform_to_display(txl->ssr_normal_input);
|
||||
|
||||
@@ -212,8 +212,10 @@ static void EEVEE_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDPr
|
||||
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_halfres", true);
|
||||
BKE_collection_engine_property_add_int(props, "ssr_stride", 16);
|
||||
BKE_collection_engine_property_add_float(props, "ssr_thickness", 0.5f);
|
||||
BKE_collection_engine_property_add_float(props, "ssr_border_fade", 0.075f);
|
||||
|
||||
BKE_collection_engine_property_add_bool(props, "volumetric_enable", false);
|
||||
BKE_collection_engine_property_add_float(props, "volumetric_start", 0.1f);
|
||||
|
||||
@@ -161,8 +161,6 @@ typedef struct EEVEE_TextureList {
|
||||
|
||||
struct GPUTexture *ssr_normal_input;
|
||||
struct GPUTexture *ssr_specrough_input;
|
||||
struct GPUTexture *ssr_hit_output;
|
||||
struct GPUTexture *ssr_pdf_output;
|
||||
|
||||
struct GPUTexture *planar_pool;
|
||||
|
||||
@@ -321,6 +319,7 @@ typedef struct EEVEE_EffectsInfo {
|
||||
/* SSR */
|
||||
bool use_ssr;
|
||||
bool reflection_trace_full;
|
||||
float ssr_border_fac;
|
||||
float ssr_stride;
|
||||
float ssr_thickness;
|
||||
|
||||
@@ -455,6 +454,8 @@ typedef struct EEVEE_PrivateData {
|
||||
struct GHash *material_hash;
|
||||
struct GHash *hair_material_hash;
|
||||
struct GPUTexture *minzbuffer;
|
||||
struct GPUTexture *ssr_hit_output;
|
||||
struct GPUTexture *ssr_pdf_output;
|
||||
struct GPUTexture *volumetric;
|
||||
struct GPUTexture *volumetric_transmit;
|
||||
float background_alpha; /* TODO find a better place for this. */
|
||||
|
||||
@@ -113,6 +113,8 @@ uniform sampler2D pdfBuffer;
|
||||
|
||||
uniform int probe_count;
|
||||
|
||||
uniform float borderFadeFactor;
|
||||
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
uniform mat4 PastViewProjectionMatrix;
|
||||
|
||||
@@ -192,8 +194,8 @@ float screen_border_mask(vec2 past_hit_co, vec3 hit)
|
||||
hit_co.xy = (hit_co.xy / hit_co.w) * 0.5 + 0.5;
|
||||
hit_co.zw = past_hit_co;
|
||||
|
||||
const float margin = 0.01;
|
||||
const float atten = 0.075 + margin; /* Screen percentage */
|
||||
const float margin = 0.003;
|
||||
float atten = borderFadeFactor + margin; /* Screen percentage */
|
||||
hit_co = smoothstep(margin, atten, hit_co) * (1 - smoothstep(1.0 - atten, 1.0 - margin, hit_co));
|
||||
vec2 atten_fac = min(hit_co.xy, hit_co.zw);
|
||||
|
||||
|
||||
@@ -2623,8 +2623,10 @@ RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_shadows)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_shadow_samples)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_colored_transmittance)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_enable)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_halfres)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(ssr_stride)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_thickness)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_border_fade)
|
||||
|
||||
/* object engine */
|
||||
RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(show_wire)
|
||||
@@ -6183,7 +6185,14 @@ static void rna_def_scene_layer_engine_settings_eevee(BlenderRNA *brna)
|
||||
prop = RNA_def_property(srna, "ssr_enable", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_enable_get",
|
||||
"rna_LayerEngineSettings_Eevee_ssr_enable_set");
|
||||
RNA_def_property_ui_text(prop, "SSR", "Enable screen space reflection");
|
||||
RNA_def_property_ui_text(prop, "Screen Space Reflections", "Enable screen space reflection");
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_SceneLayerEngineSettings_update");
|
||||
|
||||
prop = RNA_def_property(srna, "ssr_halfres", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_halfres_get",
|
||||
"rna_LayerEngineSettings_Eevee_ssr_halfres_set");
|
||||
RNA_def_property_ui_text(prop, "Half Res Trace", "Raytrace at a lower resolution");
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_SceneLayerEngineSettings_update");
|
||||
|
||||
@@ -6204,6 +6213,14 @@ static void rna_def_scene_layer_engine_settings_eevee(BlenderRNA *brna)
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_SceneLayerEngineSettings_update");
|
||||
|
||||
prop = RNA_def_property(srna, "ssr_border_fade", PROP_FLOAT, PROP_FACTOR);
|
||||
RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_border_fade_get",
|
||||
"rna_LayerEngineSettings_Eevee_ssr_border_fade_set", NULL);
|
||||
RNA_def_property_ui_text(prop, "Edge Fading", "Screen percentage used to fade the SSR");
|
||||
RNA_def_property_range(prop, 0.0f, 0.5f);
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_SceneLayerEngineSettings_update");
|
||||
|
||||
/* Volumetrics */
|
||||
prop = RNA_def_property(srna, "volumetric_enable", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_enable_get",
|
||||
|
||||
Reference in New Issue
Block a user