From 076908bed940adac80ab0a058e8a6d6b2583d84e Mon Sep 17 00:00:00 2001 From: clayjohn Date: Sun, 22 Nov 2020 17:51:31 -0800 Subject: Environment brightness, contrast, saturation restore with color correction. Allow gradients and 2d images. Use shader versions for LUT in tonemap Co-authored-by: alex-poe <3957610+CptPotato@users.noreply.github.com> Co-authored-by: QbieShay Co-authored-by: Clay John --- scene/resources/environment.cpp | 26 +++++++++++++++++++++----- scene/resources/environment.h | 7 ++++--- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'scene/resources') diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index bacdb6be54..2ed5953b8f 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -31,6 +31,7 @@ #include "environment.h" #include "core/config/project_settings.h" +#include "core/core_string_names.h" #include "servers/rendering_server.h" #include "texture.h" @@ -891,23 +892,38 @@ float Environment::get_adjustment_saturation() const { return adjustment_saturation; } -void Environment::set_adjustment_color_correction(const Ref &p_ramp) { - adjustment_color_correction = p_ramp; +void Environment::set_adjustment_color_correction(Ref p_color_correction) { + adjustment_color_correction = p_color_correction; + Ref grad_tex = p_color_correction; + if (grad_tex.is_valid()) { + if (!grad_tex->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &Environment::_update_adjustment))) { + grad_tex->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Environment::_update_adjustment)); + } + } + Ref adjustment_texture_2d = adjustment_color_correction; + if (adjustment_texture_2d.is_valid()) { + use_1d_color_correction = true; + } else { + use_1d_color_correction = false; + } _update_adjustment(); } -Ref Environment::get_adjustment_color_correction() const { +Ref Environment::get_adjustment_color_correction() const { return adjustment_color_correction; } void Environment::_update_adjustment() { + RID color_correction = adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID(); + RS::get_singleton()->environment_set_adjustment( environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, - adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + use_1d_color_correction, + color_correction); } // Private methods, constructor and destructor @@ -1319,7 +1335,7 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "adjustment_brightness", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_brightness", "get_adjustment_brightness"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "adjustment_contrast", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_contrast", "get_adjustment_contrast"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "adjustment_saturation", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_saturation", "get_adjustment_saturation"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "adjustment_color_correction", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_adjustment_color_correction", "get_adjustment_color_correction"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "adjustment_color_correction", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D,Texture3D"), "set_adjustment_color_correction", "get_adjustment_color_correction"); // Constants diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 23c7f5180c..106ba92bfe 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -211,7 +211,8 @@ private: float adjustment_brightness = 1.0; float adjustment_contrast = 1.0; float adjustment_saturation = 1.0; - Ref adjustment_color_correction; + bool use_1d_color_correction = true; + Ref adjustment_color_correction; void _update_adjustment(); protected: @@ -402,8 +403,8 @@ public: float get_adjustment_contrast() const; void set_adjustment_saturation(float p_saturation); float get_adjustment_saturation() const; - void set_adjustment_color_correction(const Ref &p_ramp); - Ref get_adjustment_color_correction() const; + void set_adjustment_color_correction(Ref p_color_correction); + Ref get_adjustment_color_correction() const; Environment(); ~Environment(); -- cgit v1.2.3