EEVEE Next: Volumes #107176

Merged
Miguel Pozo merged 126 commits from pragma37/blender:pull-eevee-next-volumes into main 2023-08-04 16:47:22 +02:00
4 changed files with 46 additions and 46 deletions
Showing only changes of commit b3c0550100 - Show all commits

View File

@ -89,6 +89,7 @@ void Volumes::init()
data_.tex_size = tex_size;
data_.inv_tex_size = 1.0f / float3(tex_size);
data_.history_alpha = 0.0f;
prev_view_projection_matrix = float4x4::identity();
}
else {
/* Like frostbite's paper, 5% blend of the new frame. */
@ -146,6 +147,9 @@ void Volumes::init()
void Volumes::begin_sync()
{
scatter_tx_.swap();
transmit_tx_.swap();
const DRWContextState *draw_ctx = DRW_context_state_get();
Scene *scene = draw_ctx->scene;
const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph);
@ -302,12 +306,10 @@ void Volumes::end_sync()
prop_extinction_tx_.free();
prop_emission_tx_.free();
prop_phase_tx_.free();
scatter_tx_.free();
transmit_tx_.free();
scatter_history_tx_.free();
transmit_history_tx_.free();
/* volumetric_fb_ */;
/* scatter_fb_ */;
scatter_tx_.current().free();
scatter_tx_.previous().free();
transmit_tx_.current().free();
transmit_tx_.previous().free();
return;
}
@ -322,15 +324,15 @@ void Volumes::end_sync()
/* Volume scattering: We compute for each froxel the
* Scattered light towards the view. We also resolve temporal
* super sampling during this stage. */
scatter_tx_.ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
transmit_tx_.ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
scatter_tx_.current().ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
transmit_tx_.current().ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
/* Final integration: We compute for each froxel the
* amount of scattered light and extinction coef at this
* given depth. We use these textures as double buffer
* for the volumetric history. */
scatter_history_tx_.ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
transmit_history_tx_.ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
scatter_tx_.previous().ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
transmit_tx_.previous().ensure_3d(GPU_R11F_G11F_B10F, data_.tex_size, usage);
float4 scatter = float4(0.0f);
float4 transmit = float4(1.0f);
@ -340,8 +342,8 @@ void Volumes::end_sync()
#if 0
/* TODO */
scatter_tx_ = dummy_scatter_tx_;
transmit_tx_ = dummy_transmit_tx_;
effects->volume_scatter = dummy_scatter_tx_;
effects->volume_scatter = dummy_transmit_tx_;
#endif
scatter_ps_.init();
@ -354,32 +356,33 @@ void Volumes::end_sync()
scatter_ps_.bind_texture("volumeExtinction", &prop_extinction_tx_);
scatter_ps_.bind_texture("volumeEmission", &prop_emission_tx_);
scatter_ps_.bind_texture("volumePhase", &prop_phase_tx_);
scatter_ps_.bind_texture("historyScattering", &scatter_history_tx_);
scatter_ps_.bind_texture("historyTransmittance", &transmit_history_tx_);
scatter_ps_.bind_texture("historyScattering", &scatter_tx_.previous());
scatter_ps_.bind_texture("historyTransmittance", &transmit_tx_.previous());
#if 0
/* TODO */
scatter_ps_.bind_texture("irradianceGrid", &lcache->grid_tx.tex);
scatter_ps_.bind_texture("shadowCubeTexture", &sldata->shadow_cube_pool);
scatter_ps_.bind_texture("shadowCascadeTexture", &sldata->shadow_cascade_pool);
#endif
scatter_ps_.push_constant("prev_view_projection_matrix", prev_view_projection_matrix);
scatter_ps_.draw_procedural(GPU_PRIM_TRIS, 1, data_.tex_size.z);
integration_ps_.init();
integration_ps_.state_set(DRW_STATE_WRITE_COLOR);
integration_ps_.shader_set(inst_.shaders.static_shader_get(VOLUME_INTEGRATION));
bind_common_resources(integration_ps_);
integration_ps_.bind_texture("volumeScattering", &scatter_tx_);
integration_ps_.bind_texture("volumeExtinction", &transmit_tx_);
integration_ps_.bind_image("finalScattering_img", &scatter_history_tx_);
integration_ps_.bind_image("finalTransmittance_img", &transmit_history_tx_);
integration_ps_.bind_texture("volumeScattering", &scatter_tx_.current());
integration_ps_.bind_texture("volumeExtinction", &transmit_tx_.current());
integration_ps_.bind_image("finalScattering_img", &scatter_tx_.previous());
integration_ps_.bind_image("finalTransmittance_img", &transmit_tx_.previous());
integration_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 1);
resolve_ps_.init();
resolve_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
resolve_ps_.shader_set(inst_.shaders.static_shader_get(VOLUME_RESOLVE));
bind_common_resources(integration_ps_);
resolve_ps_.bind_texture("inScattering", &scatter_tx_);
resolve_ps_.bind_texture("inTransmittance", &transmit_tx_);
resolve_ps_.bind_texture("inScattering", &scatter_tx_.current());
resolve_ps_.bind_texture("inTransmittance", &transmit_tx_.current());
resolve_ps_.bind_texture("inSceneDepth", &inst_.render_buffers.depth_tx);
resolve_ps_.draw_procedural(GPU_PRIM_TRIS, 1, data_.tex_size.z);
}
@ -407,8 +410,8 @@ void Volumes::draw_compute(View &view)
GPU_ATTACHMENT_TEXTURE(prop_phase_tx_));
scatter_fb_.ensure(GPU_ATTACHMENT_NONE,
GPU_ATTACHMENT_TEXTURE(scatter_tx_),
GPU_ATTACHMENT_TEXTURE(transmit_tx_));
GPU_ATTACHMENT_TEXTURE(scatter_tx_.current()),
GPU_ATTACHMENT_TEXTURE(transmit_tx_.current()));
volumetric_fb_.bind();
inst_.manager->submit(world_ps_, view);
@ -422,11 +425,9 @@ void Volumes::draw_compute(View &view)
#if 0
SWAP(struct GPUFrameBuffer *, fbl->scatter_fb_, fbl->integration_fb_);
SWAP(GPUTexture *, scatter_tx_, scatter_history_tx_);
SWAP(GPUTexture *, transmit_tx_, transmit_history_tx_);
effects->volume_scatter = scatter_tx_;
effects->volume_transmit = transmit_tx_;
effects->volume_scatter = scatter_tx_.current();
effects->volume_transmit = transmit_tx_.current();
#endif
DRW_stats_group_end();
@ -444,6 +445,9 @@ void Volumes::draw_resolve(View &view)
GPU_ATTACHMENT_TEXTURE(inst_.render_buffers.combined_tx));
integration_fb_.bind();
inst_.manager->submit(resolve_ps_, view);
/* TODO(Miguel Pozo): This should be stored per view. */
prev_view_projection_matrix = view.winmat() * view.viewmat();
}
/* -------------------------------------------------------------------- */
@ -477,8 +481,8 @@ void Volumes::draw_resolve(View &view)
if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
grp = DRW_shgroup_create(EEVEE_shaders_volumes_resolve_sh_get(true),
psl->volumetric_accum_ps);
DRW_shgroup_uniform_texture_ref(grp, "inScattering", &scatter_tx_);
DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &transmit_tx_);
DRW_shgroup_uniform_texture_ref(grp, "inScattering", &scatter_tx_.current());
DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &transmit_tx_.current());
DRW_shgroup_uniform_texture_ref(grp, "inSceneDepth", &e_data.depth_src);
DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);

View File

@ -28,10 +28,8 @@ class Volumes {
Texture prop_extinction_tx_;
Texture prop_emission_tx_;
Texture prop_phase_tx_;
Texture scatter_tx_;
Texture transmit_tx_;
Texture scatter_history_tx_;
Texture transmit_history_tx_;
SwapChain<Texture, 2> scatter_tx_;
SwapChain<Texture, 2> transmit_tx_;
/* EEVEE_FramebufferList */
Framebuffer volumetric_fb_;
Framebuffer scatter_fb_;
@ -40,7 +38,7 @@ class Volumes {
int current_sample_;
float light_clamp_;
#if 0
/* TODO (Miguel Pozo): Are these the same ones from EEVEE_TextureList ? */
/* TODO (Miguel Pozo): These ones were used for transparency */
struct GPUTexture *volume_scatter;
struct GPUTexture *volume_transmit;
#endif
@ -52,6 +50,8 @@ class Volumes {
PassSimple resolve_ps_ = {"Volumes.Resolve"};
PassSimple accum_ps_ = {"Volumes.Accum"};
float4x4 prev_view_projection_matrix;
template<typename PassType> void bind_common_resources(PassType &ps)
{
ps.bind_ubo(VOLUMES_BUF_SLOT, data_);

View File

@ -27,8 +27,7 @@ void main()
outScattering.rgb += irradiance_volumetric(P) * s_scattering * phase_function_isotropic();
/* TODO (Miguel Pozo) */
#if 0
# ifdef VOLUME_LIGHTING /* Lights */
#ifdef VOLUME_LIGHTING /* Lights */
for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) {
LightData ld = lights_data[i];
@ -51,17 +50,14 @@ void main()
outScattering.rgb += Li * vis * s_scattering *
phase_function(-V, l_vector.xyz / l_vector.w, s_anisotropy);
}
# endif
#endif
/* TODO (Miguel Pozo) */
#if 0
/* Temporal supersampling */
/* Note : this uses the cell non-jittered position (texel center). */
vec3 curr_ndc = volume_to_ndc(vec3(gl_FragCoord.xy, float(volume_geom_iface.slice) + 0.5) *
volumes_buf.inv_tex_size);
vec3 wpos = get_world_space_from_depth(curr_ndc.xy, curr_ndc.z);
vec3 prev_ndc = project_point(pastViewProjectionMatrix, wpos);
vec3 prev_ndc = project_point(prev_view_projection_matrix, wpos);
vec3 prev_volume = ndc_to_volume(prev_ndc * 0.5 + 0.5);
if ((volumes_buf.history_alpha > 0.0) && all(greaterThan(prev_volume, vec3(0.0))) &&
@ -71,7 +67,6 @@ void main()
outScattering = mix(outScattering, h_Scattering, volumes_buf.history_alpha);
outTransmittance = mix(outTransmittance, h_Transmittance, volumes_buf.history_alpha);
}
#endif
/* Catch NaNs */
if (any(isnan(outScattering)) || any(isnan(outTransmittance))) {

View File

@ -74,12 +74,13 @@ GPU_SHADER_CREATE_INFO(eevee_volume_scatter_common)
/* NOTE: Unique sampler IDs assigned for consistency between library includes,
* and to avoid unique assignment collision validation error.
* However, resources will be auto assigned locations within shader usage. */
.sampler(15, ImageType::FLOAT_3D, "volumeScattering")
.sampler(16, ImageType::FLOAT_3D, "volumeExtinction")
.sampler(17, ImageType::FLOAT_3D, "volumeEmission")
.sampler(18, ImageType::FLOAT_3D, "volumePhase")
.sampler(19, ImageType::FLOAT_3D, "historyScattering")
.sampler(20, ImageType::FLOAT_3D, "historyTransmittance")
.sampler(17, ImageType::FLOAT_3D, "volumeScattering")
.sampler(18, ImageType::FLOAT_3D, "volumeExtinction")
.sampler(19, ImageType::FLOAT_3D, "volumeEmission")
.sampler(20, ImageType::FLOAT_3D, "volumePhase")
.sampler(21, ImageType::FLOAT_3D, "historyScattering")
.sampler(22, ImageType::FLOAT_3D, "historyTransmittance")
.push_constant(Type::MAT4, "prev_view_projection_matrix")
.fragment_out(0, Type::VEC4, "outScattering")
.fragment_out(1, Type::VEC4, "outTransmittance")
.vertex_source("eevee_volume_vert.glsl")