Skip to content

Commit

Permalink
Fix transparent viewport backgrounds with custom clear color
Browse files Browse the repository at this point in the history
(cherry picked from commit 6effd3c)
  • Loading branch information
LRFLEW authored and YuriSizov committed Jan 23, 2024
1 parent 5115b11 commit 38037ba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
3 changes: 2 additions & 1 deletion drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
RenderDataGLES3 render_data;
{
render_data.render_buffers = rb;
render_data.transparent_bg = rb.is_valid() ? rb->is_transparent : false;
render_data.transparent_bg = rb.is_valid() ? rt->is_transparent : false;
// Our first camera is used by default
render_data.cam_transform = p_camera_data->main_transform;
render_data.inv_cam_transform = render_data.cam_transform.affine_inverse();
Expand Down Expand Up @@ -1980,6 +1980,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
}

if (!keep_color) {
clear_color.a = render_data.transparent_bg ? 0.0f : 1.0f;
glClearBufferfv(GL_COLOR, 0, clear_color.components);
}
RENDER_TIMESTAMP("Render Opaque Pass");
Expand Down
6 changes: 0 additions & 6 deletions drivers/gles3/storage/render_scene_buffers_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ RenderSceneBuffersGLES3::~RenderSceneBuffersGLES3() {
}

void RenderSceneBuffersGLES3::configure(RID p_render_target, const Size2i p_internal_size, const Size2i p_target_size, RS::ViewportScaling3DMode p_scaling_3d_mode, float p_fsr_sharpness, float p_texture_mipmap_bias, RS::ViewportMSAA p_msaa, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_taa, bool p_use_debanding, uint32_t p_view_count) {
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();

//internal_size.x = p_internal_size.x; // ignore for now
//internal_size.y = p_internal_size.y;
width = p_target_size.x;
Expand All @@ -54,10 +52,6 @@ void RenderSceneBuffersGLES3::configure(RID p_render_target, const Size2i p_inte
view_count = p_view_count;

free_render_buffer_data();

GLES3::RenderTarget *rt = texture_storage->get_render_target(p_render_target);

is_transparent = rt->is_transparent;
}

void RenderSceneBuffersGLES3::free_render_buffer_data() {
Expand Down
2 changes: 0 additions & 2 deletions drivers/gles3/storage/render_scene_buffers_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {
//bool use_debanding = false;
uint32_t view_count = 1;

bool is_transparent = false;

RID render_target;

//built-in textures used for ping pong image processing and blurring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,19 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color
{
// regular forward for now
Vector<Color> c;
c.push_back(clear_color.srgb_to_linear()); // our render buffer
if (rb_data.is_valid()) {
if (p_render_data->render_buffers->get_msaa_3d() != RS::VIEWPORT_MSAA_DISABLED) {
c.push_back(clear_color.srgb_to_linear()); // our resolve buffer
{
Color cc = clear_color.srgb_to_linear();
if (rb_data.is_valid()) {
cc.a = 0; // For transparent viewport backgrounds.
}
if (using_subpass_post_process) {
c.push_back(Color()); // our 2D buffer we're copying into
c.push_back(cc); // Our render buffer.
if (rb_data.is_valid()) {
if (p_render_data->render_buffers->get_msaa_3d() != RS::VIEWPORT_MSAA_DISABLED) {
c.push_back(clear_color.srgb_to_linear()); // Our resolve buffer.
}
if (using_subpass_post_process) {
c.push_back(Color()); // Our 2D buffer we're copying into.
}
}
}

Expand Down

0 comments on commit 38037ba

Please sign in to comment.