EEVEE-Next: Add back transparent render pass

Straight forward implementation.
This commit is contained in:
Clément Foucault
2023-11-22 17:48:58 +01:00
parent 6f1ed59c4d
commit 14d4da7555
9 changed files with 50 additions and 25 deletions
@@ -295,11 +295,13 @@ void Film::init(const int2 &extent, const rcti *output_rect)
EEVEE_RENDER_PASS_ENVIRONMENT |
EEVEE_RENDER_PASS_MIST |
EEVEE_RENDER_PASS_SHADOW | EEVEE_RENDER_PASS_AO;
const eViewLayerEEVEEPassType color_passes_3 = EEVEE_RENDER_PASS_TRANSPARENT;
data_.exposure_scale = pow2f(scene.view_settings.exposure);
data_.has_data = (enabled_passes_ & data_passes) != 0;
data_.any_render_pass_1 = (enabled_passes_ & color_passes_1) != 0;
data_.any_render_pass_2 = (enabled_passes_ & color_passes_2) != 0;
data_.any_render_pass_3 = (enabled_passes_ & color_passes_3) != 0;
}
{
/* Set pass offsets. */
@@ -341,6 +343,7 @@ void Film::init(const int2 &extent, const rcti *output_rect)
data_.environment_id = pass_index_get(EEVEE_RENDER_PASS_ENVIRONMENT);
data_.shadow_id = pass_index_get(EEVEE_RENDER_PASS_SHADOW);
data_.ambient_occlusion_id = pass_index_get(EEVEE_RENDER_PASS_AO);
data_.transparent_id = pass_index_get(EEVEE_RENDER_PASS_TRANSPARENT);
data_.aov_color_id = data_.color_len;
data_.aov_value_id = data_.value_len;
@@ -180,6 +180,8 @@ class Film {
return data_.shadow_id;
case EEVEE_RENDER_PASS_AO:
return data_.ambient_occlusion_id;
case EEVEE_RENDER_PASS_TRANSPARENT:
return data_.transparent_id;
case EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT:
return data_.cryptomatte_object_id;
case EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET:
@@ -382,24 +382,14 @@ PassMain::Sub *ForwardPipeline::material_transparent_add(const Object *ob,
return pass;
}
void ForwardPipeline::render(View &view,
Framebuffer &prepass_fb,
Framebuffer &combined_fb,
GPUTexture * /*combined_tx*/)
void ForwardPipeline::render(View &view, Framebuffer &prepass_fb, Framebuffer &combined_fb)
{
DRW_stats_group_start("Forward.Opaque");
prepass_fb.bind();
inst_.manager->submit(prepass_ps_, view);
// if (!DRW_pass_is_empty(prepass_ps_)) {
inst_.hiz_buffer.set_dirty();
// }
// if (inst_.raytracing.enabled()) {
// rt_buffer.radiance_copy(combined_tx);
// inst_.hiz_buffer.update();
// }
inst_.shadows.set_view(view);
inst_.irradiance_cache.set_view(view);
@@ -413,10 +403,6 @@ void ForwardPipeline::render(View &view,
combined_fb.bind();
inst_.manager->submit(transparent_ps_, view);
// if (inst_.raytracing.enabled()) {
// gbuffer.ray_radiance_tx.release();
// }
}
/** \} */
@@ -148,8 +148,6 @@ class ForwardPipeline {
PassSortable transparent_ps_ = {"Forward.Transparent"};
float3 camera_forward_;
// GPUTexture *input_screen_radiance_tx_ = nullptr;
public:
ForwardPipeline(Instance &inst) : inst_(inst){};
@@ -165,10 +163,7 @@ class ForwardPipeline {
::Material *blender_mat,
GPUMaterial *gpumat);
void render(View &view,
Framebuffer &prepass_fb,
Framebuffer &combined_fb,
GPUTexture *combined_tx);
void render(View &view, Framebuffer &prepass_fb, Framebuffer &combined_fb);
};
/** \} */
@@ -50,6 +50,7 @@ void RenderBuffers::sync()
data.environment_id = pass_index_get(EEVEE_RENDER_PASS_ENVIRONMENT);
data.shadow_id = pass_index_get(EEVEE_RENDER_PASS_SHADOW);
data.ambient_occlusion_id = pass_index_get(EEVEE_RENDER_PASS_AO);
data.transparent_id = pass_index_get(EEVEE_RENDER_PASS_TRANSPARENT);
data.aovs = inst_.film.aovs_info;
}
@@ -268,9 +268,9 @@ struct FilmData {
/** Is true if accumulation of filtered passes is needed. */
bool1 any_render_pass_1;
bool1 any_render_pass_2;
bool1 any_render_pass_3;
/** Controlled by user in lookdev mode or by render settings. */
float background_opacity;
float _pad0, _pad1;
/** Output counts per type. */
int color_len, value_len;
/** Index in color_accum_img or value_accum_img of each pass. -1 if pass is not enabled. */
@@ -287,6 +287,7 @@ struct FilmData {
int environment_id;
int shadow_id;
int ambient_occlusion_id;
int transparent_id;
/** Not indexed but still not -1 if enabled. */
int depth_id;
int combined_id;
@@ -376,11 +377,12 @@ struct RenderBuffersInfoData {
int volume_light_id;
int emission_id;
int environment_id;
int transparent_id;
/* Value */
int value_len;
int shadow_id;
int ambient_occlusion_id;
int _pad0, _pad1, _pad2;
int _pad0, _pad1;
};
BLI_STATIC_ASSERT_ALIGN(RenderBuffersInfoData, 16)
@@ -144,7 +144,9 @@ void ShadingView::render()
// inst_.lookdev.render_overlay(view_fb_);
inst_.pipelines.forward.render(render_view_new_, prepass_fb_, combined_fb_, rbufs.combined_tx);
inst_.pipelines.forward.render(render_view_new_, prepass_fb_, combined_fb_);
render_transparent_pass(rbufs);
inst_.lights.debug_draw(render_view_new_, combined_fb_);
inst_.hiz_buffer.debug_draw(render_view_new_, combined_fb_);
@@ -164,6 +166,20 @@ void ShadingView::render()
DRW_stats_group_end();
}
void ShadingView::render_transparent_pass(RenderBuffers &rbufs)
{
if (rbufs.data.transparent_id != -1) {
transparent_fb_.ensure(
GPU_ATTACHMENT_TEXTURE(rbufs.depth_tx),
GPU_ATTACHMENT_TEXTURE_LAYER(rbufs.rp_color_tx, rbufs.data.transparent_id));
/* Alpha stores transmittance. So start at 1. */
float4 clear_color = {0.0f, 0.0f, 0.0f, 1.0f};
GPU_framebuffer_bind(transparent_fb_);
GPU_framebuffer_clear_color(transparent_fb_, clear_color);
inst_.pipelines.forward.render(render_view_new_, prepass_fb_, transparent_fb_);
}
}
GPUTexture *ShadingView::render_postfx(GPUTexture *input_tx)
{
if (!inst_.depth_of_field.postfx_enabled() && !inst_.motion_blur.postfx_enabled()) {
@@ -48,6 +48,7 @@ class ShadingView {
Framebuffer prepass_fb_;
Framebuffer combined_fb_;
Framebuffer transparent_fb_ = {"transparent"};
TextureFromPool postfx_tx_;
/** Main views is created from the camera (or is from the viewport). It is not jittered. */
@@ -76,9 +77,11 @@ class ShadingView {
void render();
private:
void render_transparent_pass(RenderBuffers &rbufs);
GPUTexture *render_postfx(GPUTexture *input_tx);
private:
void update_view();
};
@@ -759,6 +759,23 @@ void film_process_data(ivec2 texel_film, out vec4 out_color, out float out_depth
film_store_value(dst, uniform_buf.film.mist_id, mist_accum, out_color);
}
if (uniform_buf.film.any_render_pass_3) {
vec4 transparent_accum = vec4(0.0);
for (int i = 0; i < uniform_buf.film.samples_len; i++) {
FilmSample src = film_sample_get(i, texel_film);
film_sample_accum(src,
uniform_buf.film.transparent_id,
uniform_buf.render_pass.transparent_id,
rp_color_tx,
transparent_accum);
}
/* Alpha stores transmittance for transparent pass. */
transparent_accum.a = weight_accum - transparent_accum.a;
film_store_color(dst, uniform_buf.film.transparent_id, transparent_accum, out_color);
}
for (int aov = 0; aov < uniform_buf.film.aov_color_len; aov++) {
vec4 aov_accum = vec4(0.0);