Skip to content

Commit

Permalink
Ensure post processing happens when adjustments are enabled in the Co…
Browse files Browse the repository at this point in the history
…mpatibility renderer
  • Loading branch information
clayjohn committed Jun 11, 2024
1 parent 292e50e commit 9000a9d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
1 change: 0 additions & 1 deletion doc/classes/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
</member>
<member name="adjustment_enabled" type="bool" setter="set_adjustment_enabled" getter="is_adjustment_enabled" default="false">
If [code]true[/code], enables the [code]adjustment_*[/code] properties provided by this resource. If [code]false[/code], modifications to the [code]adjustment_*[/code] properties will have no effect on the rendered scene.
[b]Note:[/b] Adjustments are only supported in the Forward+ and Mobile rendering methods, not Compatibility.
</member>
<member name="adjustment_saturation" type="float" setter="set_adjustment_saturation" getter="get_adjustment_saturation" default="1.0">
The global color saturation value of the rendered scene (default value is 1). Effective only if [member adjustment_enabled] is [code]true[/code].
Expand Down
5 changes: 3 additions & 2 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,9 +2245,9 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
}

bool glow_enabled = false;
if (p_environment.is_valid() && rb.is_valid()) {
if (p_environment.is_valid()) {
glow_enabled = environment_get_glow_enabled(p_environment);
rb->set_glow_enabled(glow_enabled); // ensure our intermediate buffer is available if glow is enabled
rb->ensure_internal_buffers(); // Ensure our intermediate buffer is available if glow is enabled
if (glow_enabled) {
// If glow is enabled, we apply tonemapping etc. in post, so disable it during rendering
apply_color_adjustments_in_post = true;
Expand Down Expand Up @@ -2339,6 +2339,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
if (render_data.environment.is_valid()) {
bool use_bcs = environment_get_adjustments_enabled(render_data.environment);
if (use_bcs) {
rb->ensure_internal_buffers();
apply_color_adjustments_in_post = true;
}

Expand Down
18 changes: 6 additions & 12 deletions drivers/gles3/storage/render_scene_buffers_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void RenderSceneBuffersGLES3::_check_render_buffers() {

ERR_FAIL_COND(view_count == 0);

bool use_internal_buffer = scaling_3d_mode != RS::VIEWPORT_SCALING_3D_MODE_OFF || glow.glow_enabled;
bool use_internal_buffer = scaling_3d_mode != RS::VIEWPORT_SCALING_3D_MODE_OFF || needs_internal_buffers;
uint32_t depth_format_size = 3;
bool use_multiview = view_count > 1;

Expand All @@ -203,7 +203,7 @@ void RenderSceneBuffersGLES3::_check_render_buffers() {
return;
}

if (use_internal_buffer) {
if (use_internal_buffer && internal3d.color == 0) {
// Setup our internal buffer.
GLenum texture_target = use_multiview ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;

Expand Down Expand Up @@ -261,14 +261,14 @@ void RenderSceneBuffersGLES3::_check_render_buffers() {
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
_clear_intermediate_buffers();
WARN_PRINT("Could not create 3D buffers, status: " + texture_storage->get_framebuffer_error(status));
WARN_PRINT("Could not create 3D internal buffers, status: " + texture_storage->get_framebuffer_error(status));
}

glBindTexture(texture_target, 0);
glBindFramebuffer(GL_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
}

if (msaa3d.mode != RS::VIEWPORT_MSAA_DISABLED) {
if (msaa3d.mode != RS::VIEWPORT_MSAA_DISABLED && msaa3d.color == 0) {
// Setup MSAA.
const GLsizei samples[] = { 1, 2, 4, 8 };
msaa3d.samples = samples[msaa3d.mode];
Expand Down Expand Up @@ -558,14 +558,8 @@ void RenderSceneBuffersGLES3::_clear_back_buffers() {
}
}

void RenderSceneBuffersGLES3::set_glow_enabled(bool p_glow_enabled) {
if (glow.glow_enabled != p_glow_enabled) {
glow.glow_enabled = p_glow_enabled;

// Clear our main buffers, this can impact them.
_clear_msaa3d_buffers();
_clear_intermediate_buffers();
}
void RenderSceneBuffersGLES3::ensure_internal_buffers() {
needs_internal_buffers = true;
}

void RenderSceneBuffersGLES3::check_glow_buffers() {
Expand Down
5 changes: 2 additions & 3 deletions drivers/gles3/storage/render_scene_buffers_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {
//bool use_taa = false;
//bool use_debanding = false;
uint32_t view_count = 1;
bool needs_internal_buffers = false;

RID render_target;

Expand Down Expand Up @@ -83,7 +84,6 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {

// Buffers for our glow implementation
struct GLOW {
bool glow_enabled = false;
GLES3::Glow::GLOWLEVEL levels[4];
} glow;

Expand Down Expand Up @@ -111,6 +111,7 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {

void check_backbuffer(bool p_need_color, bool p_need_depth); // Check if we need to initialize our backbuffer.
void check_glow_buffers(); // Check if we need to initialize our glow buffers.
void ensure_internal_buffers();

GLuint get_render_fbo();
GLuint get_msaa3d_fbo() {
Expand Down Expand Up @@ -145,8 +146,6 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {
GLuint get_backbuffer() const { return backbuffer3d.color; }
GLuint get_backbuffer_depth() const { return backbuffer3d.depth; }

bool get_glow_enabled() const { return glow.glow_enabled; }
void set_glow_enabled(bool p_glow_enabled);
const GLES3::Glow::GLOWLEVEL *get_glow_buffers() const { return &glow.levels[0]; }

// Getters
Expand Down

0 comments on commit 9000a9d

Please sign in to comment.