Eevee: Volumetrics: Add Light contribution clamping.
This avoid too much variance at light centers and remove some noise.
This commit is contained in:
@@ -704,6 +704,7 @@ class RENDER_PT_eevee_volumetric(RenderButtonsPanel, Panel):
|
||||
col.prop(props, "volumetric_samples")
|
||||
col.prop(props, "volumetric_sample_distribution")
|
||||
col.prop(props, "volumetric_lights")
|
||||
col.prop(props, "volumetric_light_clamp")
|
||||
col.prop(props, "volumetric_shadows")
|
||||
col.prop(props, "volumetric_shadow_samples")
|
||||
col.prop(props, "volumetric_colored_transmittance")
|
||||
|
||||
@@ -434,6 +434,12 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
|
||||
volumetrics->sample_distribution = BKE_collection_engine_property_value_get_float(props, "volumetric_sample_distribution");
|
||||
volumetrics->integration_step_count = (float)BKE_collection_engine_property_value_get_int(props, "volumetric_samples");
|
||||
volumetrics->shadow_step_count = (float)BKE_collection_engine_property_value_get_int(props, "volumetric_shadow_samples");
|
||||
volumetrics->light_clamp = BKE_collection_engine_property_value_get_float(props, "volumetric_light_clamp");
|
||||
|
||||
/* Disable clamp if equal to 0. */
|
||||
if (volumetrics->light_clamp == 0.0) {
|
||||
volumetrics->light_clamp = FLT_MAX;
|
||||
}
|
||||
|
||||
volumetrics->use_lights = BKE_collection_engine_property_value_get_bool(props, "volumetric_lights");
|
||||
volumetrics->use_volume_shadows = BKE_collection_engine_property_value_get_bool(props, "volumetric_shadows");
|
||||
@@ -522,7 +528,7 @@ void EEVEE_effects_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
|
||||
DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
|
||||
DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)stl->g_data->viewvecs, 2);
|
||||
DRW_shgroup_uniform_vec2(grp, "volume_start_end", &sldata->volumetrics->integration_start, 1);
|
||||
DRW_shgroup_uniform_vec3(grp, "volume_samples", &sldata->volumetrics->integration_step_count, 1);
|
||||
DRW_shgroup_uniform_vec4(grp, "volume_samples_clamp", &sldata->volumetrics->integration_step_count, 1);
|
||||
DRW_shgroup_call_add(grp, quad, NULL);
|
||||
|
||||
if (volumetrics->use_colored_transmit == false) { /* Monochromatic transmittance */
|
||||
|
||||
@@ -196,6 +196,7 @@ static void EEVEE_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDPr
|
||||
BKE_collection_engine_property_add_int(props, "volumetric_samples", 64);
|
||||
BKE_collection_engine_property_add_float(props, "volumetric_sample_distribution", 0.8);
|
||||
BKE_collection_engine_property_add_bool(props, "volumetric_lights", true);
|
||||
BKE_collection_engine_property_add_float(props, "volumetric_light_clamp", 0.0f);
|
||||
BKE_collection_engine_property_add_bool(props, "volumetric_shadows", false);
|
||||
BKE_collection_engine_property_add_int(props, "volumetric_shadow_samples", 16);
|
||||
BKE_collection_engine_property_add_bool(props, "volumetric_colored_transmittance", true);
|
||||
|
||||
@@ -188,7 +188,7 @@ typedef struct EEVEE_ShadowRender {
|
||||
|
||||
/* ************ VOLUME DATA ************ */
|
||||
typedef struct EEVEE_VolumetricsInfo {
|
||||
float integration_step_count, shadow_step_count, sample_distribution;
|
||||
float integration_step_count, shadow_step_count, sample_distribution, light_clamp;
|
||||
float integration_start, integration_end;
|
||||
bool use_lights, use_volume_shadows, use_colored_transmit;
|
||||
} EEVEE_VolumetricsInfo;
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
|
||||
uniform int light_count;
|
||||
uniform vec2 volume_start_end;
|
||||
uniform vec3 volume_samples;
|
||||
uniform vec4 volume_samples_clamp;
|
||||
|
||||
#define volume_start volume_start_end.x
|
||||
#define volume_end volume_start_end.y
|
||||
|
||||
#define volume_integration_steps volume_samples.x
|
||||
#define volume_shadows_steps volume_samples.y
|
||||
#define volume_sample_distribution volume_samples.z
|
||||
#define volume_integration_steps volume_samples_clamp.x
|
||||
#define volume_shadows_steps volume_samples_clamp.y
|
||||
#define volume_sample_distribution volume_samples_clamp.z
|
||||
#define volume_light_clamp volume_samples_clamp.w
|
||||
|
||||
#ifdef COLOR_TRANSMITTANCE
|
||||
layout(location = 0) out vec4 outScattering;
|
||||
@@ -74,7 +75,7 @@ float phase_function(vec3 v, vec3 l, float g)
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 light_volume(LightData ld, vec4 l_vector)
|
||||
float light_volume(LightData ld, vec4 l_vector)
|
||||
{
|
||||
float power;
|
||||
float dist = max(1e-4, abs(l_vector.w - ld.l_radius));
|
||||
@@ -87,7 +88,7 @@ vec3 light_volume(LightData ld, vec4 l_vector)
|
||||
else {
|
||||
power = 0.0248 * (4.0 * ld.l_radius * ld.l_radius * M_PI * M_PI);
|
||||
}
|
||||
return ld.l_color * power / (l_vector.w * l_vector.w);
|
||||
return min(power / (l_vector.w * l_vector.w), volume_light_clamp);
|
||||
}
|
||||
|
||||
vec3 irradiance_volumetric(vec3 wpos)
|
||||
@@ -205,7 +206,7 @@ void main()
|
||||
|
||||
float Vis = light_visibility(ld, ray_wpos, l_vector);
|
||||
|
||||
vec3 Li = light_volume(ld, l_vector) * light_volume_shadow(ld, ray_wpos, l_vector, s_extinction);
|
||||
vec3 Li = ld.l_color * light_volume(ld, l_vector) * light_volume_shadow(ld, ray_wpos, l_vector, s_extinction);
|
||||
|
||||
Lscat += Li * Vis * s_scattering * phase_function(-wdir, l_vector.xyz / l_vector.w, s_anisotropy);
|
||||
}
|
||||
|
||||
@@ -2618,6 +2618,7 @@ RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_end)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_samples)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_sample_distribution)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_lights)
|
||||
RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_light_clamp)
|
||||
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)
|
||||
@@ -6223,6 +6224,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, "volumetric_light_clamp", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_light_clamp_get",
|
||||
"rna_LayerEngineSettings_Eevee_volumetric_light_clamp_set", NULL);
|
||||
RNA_def_property_range(prop, 0.0f, FLT_MAX);
|
||||
RNA_def_property_ui_text(prop, "Clamp", "Maximum light contribution, reducing noise");
|
||||
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, "volumetric_shadows", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_shadows_get",
|
||||
"rna_LayerEngineSettings_Eevee_volumetric_shadows_set");
|
||||
|
||||
Reference in New Issue
Block a user