EEVEE Next: Volumes: Lighting integration improvements #110809

Merged
Clément Foucault merged 10 commits from pragma37/blender:pull-eevee-next-volumes-2-cleanup into main 2023-09-06 14:36:06 +02:00
3 changed files with 23 additions and 20 deletions
Showing only changes of commit cdb5567674 - Show all commits

View File

@ -257,12 +257,13 @@ void VolumeModule::end_sync()
inst_.sampling.bind_resources(&scatter_ps_);
scatter_ps_.bind_image("in_scattering_img", &prop_scattering_tx_);
scatter_ps_.bind_image("in_extinction_img", &prop_extinction_tx_);
scatter_ps_.bind_texture("extinction_tx", &prop_extinction_tx_);
scatter_ps_.bind_image("in_emission_img", &prop_emission_tx_);
scatter_ps_.bind_image("in_phase_img", &prop_phase_tx_);
scatter_ps_.bind_image("out_scattering_img", &scatter_tx_);
scatter_ps_.bind_image("out_extinction_img", &extinction_tx_);
/* Sync with the property pass. */
scatter_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
scatter_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS | GPU_BARRIER_TEXTURE_FETCH);
scatter_ps_.dispatch(math::divide_ceil(data_.tex_size, int3(VOLUME_GROUP_SIZE)));
integration_ps_.init();

View File

@ -106,22 +106,16 @@ vec3 volume_light(LightData ld, vec3 L, float l_dist)
#define VOLUMETRIC_SHADOW_MAX_STEP 128.0
vec3 volume_participating_media_extinction(vec3 wpos, sampler3D volume_extinction)
vec3 volume_shadow(LightData ld, vec3 ray_wpos, vec3 L, float l_dist, sampler3D extinction_tx)
{
/* Waiting for proper volume shadowmaps and out of frustum shadow map. */
vec3 ndc = project_point(ProjectionMatrix, transform_point(ViewMatrix, wpos));
vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5);
#if defined(VOLUME_SHADOW)
if (volumes_info_buf.shadow_steps == 0) {
return vec3(1.0);
}
/* Let the texture be clamped to edge. This reduce visual glitches. */
return texture(volume_extinction, volume_co).rgb;
}
vec3 volume_shadow(LightData ld, vec3 ray_wpos, vec3 L, float l_dist)
{
/* TODO (Miguel Pozo) */
#if 0 && defined(VOLUME_SHADOW)
vec4 l_vector = vec4(L * l_dist, l_dist);
# if 0
pragma37 marked this conversation as resolved Outdated

Always add comment on #if 0 block to state why it is commented.

Always add comment on `#if 0` block to state why it is commented.
/* If light is shadowed, use the shadow vector, if not, reuse the light vector. */
if (volumes_info_buf.use_soft_shadows && ld.shadowid >= 0.0) {
ShadowData sd = shadows_data[int(ld.shadowid)];
@ -135,12 +129,13 @@ vec3 volume_shadow(LightData ld, vec3 ray_wpos, vec3 L, float l_dist)
l_vector.w = length(l_vector.xyz);
}
}
# endif
/* Heterogeneous volume shadows. */
float dd = l_vector.w / volumes_info_buf.shadow_steps;
vec3 L = l_vector.xyz / volumes_info_buf.shadow_steps;
L = l_vector.xyz / volumes_info_buf.shadow_steps;
if (ld.type == LIGHT_SUN) {
if (ld.type <= LIGHT_SUN_ORTHO) {
pragma37 marked this conversation as resolved Outdated

use is_sun_light

use `is_sun_light`
/* For sun light we scan the whole frustum. So we need to get the correct endpoints. */
vec3 ndcP = project_point(ProjectionMatrix, transform_point(ViewMatrix, ray_wpos));
vec3 ndcL = project_point(ProjectionMatrix,
@ -155,15 +150,20 @@ vec3 volume_shadow(LightData ld, vec3 ray_wpos, vec3 L, float l_dist)
dd = length(L);
}
# if 0 /* TODO use shadow maps instead. */
/* TODO use shadow maps instead. */
vec3 shadow = vec3(1.0);
for (float s = 1.0; s < VOLUMETRIC_SHADOW_MAX_STEP && s <= volumes_info_buf.shadow_steps; s += 1.0) {
for (float s = 1.0; s < VOLUMETRIC_SHADOW_MAX_STEP && s <= volumes_info_buf.shadow_steps;
s += 1.0) {
vec3 pos = ray_wpos + L * s;
vec3 s_extinction = volume_participating_media_extinction(pos, volume_extinction);
vec3 ndc = project_point(ProjectionMatrix, transform_point(ViewMatrix, pos));
vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5);
/* Let the texture be clamped to edge. This reduce visual glitches. */
vec3 s_extinction = texture(extinction_tx, volume_co).rgb;
shadow *= exp(-s_extinction * dd);
}
return shadow;
# endif
#else
return vec3(1.0);
#endif /* VOLUME_SHADOW */

View File

@ -44,7 +44,6 @@ GPU_SHADER_CREATE_INFO(eevee_volume_scatter)
.additional_info("eevee_sampling_data")
.compute_source("eevee_volume_scatter_comp.glsl")
.local_group_size(VOLUME_GROUP_SIZE, VOLUME_GROUP_SIZE, VOLUME_GROUP_SIZE)
.define("VOLUME_SHADOW")
.uniform_buf(VOLUMES_INFO_BUF_SLOT, "VolumesInfoData", "volumes_info_buf")
.additional_info("eevee_volume_properties_data")
.image(4, GPU_R11F_G11F_B10F, Qualifier::WRITE, ImageType::FLOAT_3D, "out_scattering_img")
@ -54,6 +53,9 @@ GPU_SHADER_CREATE_INFO(eevee_volume_scatter)
GPU_SHADER_CREATE_INFO(eevee_volume_scatter_with_lights)
.additional_info("eevee_volume_scatter")
.define("VOLUME_LIGHTING")
.define("VOLUME_IRRADIANCE")
.define("VOLUME_SHADOW")
.sampler(0, ImageType::FLOAT_3D, "extinction_tx")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(eevee_volume_integration)