diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-11-28 23:07:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-28 23:07:52 +0100 |
commit | ef2d1f6d19f861f0f4d9cf7c581795bc7f4016d8 (patch) | |
tree | 40479be87ae79e6332d782ce9d03c036461ea44d /scene/resources | |
parent | 75e45e49787e332d91f35aee3e0451f66f97a353 (diff) | |
parent | 076908bed940adac80ab0a058e8a6d6b2583d84e (diff) |
Merge pull request #42761 from fire/color-grading-3d
Environment brightness, contrast, saturation restore with 3d LUT.
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/environment.cpp | 26 | ||||
-rw-r--r-- | scene/resources/environment.h | 7 |
2 files changed, 25 insertions, 8 deletions
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<Texture2D> &p_ramp) { - adjustment_color_correction = p_ramp; +void Environment::set_adjustment_color_correction(Ref<Texture> p_color_correction) { + adjustment_color_correction = p_color_correction; + Ref<GradientTexture> 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<Texture2D> 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<Texture2D> Environment::get_adjustment_color_correction() const { +Ref<Texture> 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<Texture2D> adjustment_color_correction; + bool use_1d_color_correction = true; + Ref<Texture> 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<Texture2D> &p_ramp); - Ref<Texture2D> get_adjustment_color_correction() const; + void set_adjustment_color_correction(Ref<Texture> p_color_correction); + Ref<Texture> get_adjustment_color_correction() const; Environment(); ~Environment(); |