diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/environment.cpp | 69 | ||||
-rw-r--r-- | scene/resources/environment.h | 9 |
2 files changed, 57 insertions, 21 deletions
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index ee8e63266d..96bd5c4553 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -578,22 +578,28 @@ bool Environment::is_glow_enabled() const { return glow_enabled; } -void Environment::set_glow_level_enabled(int p_level, bool p_enabled) { +void Environment::set_glow_level(int p_level, float p_intensity) { ERR_FAIL_INDEX(p_level, RS::MAX_GLOW_LEVELS); - if (p_enabled) { - glow_levels |= (1 << p_level); - } else { - glow_levels &= ~(1 << p_level); - } + glow_levels.write[p_level] = p_intensity; _update_glow(); } -bool Environment::is_glow_level_enabled(int p_level) const { +float Environment::get_glow_level(int p_level) const { ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, false); - return glow_levels & (1 << p_level); + return glow_levels[p_level]; +} + +void Environment::set_glow_normalized(bool p_normalized) { + glow_normalize_levels = p_normalized; + + _update_glow(); +} + +bool Environment::is_glow_normalized() const { + return glow_normalize_levels; } void Environment::set_glow_intensity(float p_intensity) { @@ -670,10 +676,24 @@ float Environment::get_glow_hdr_luminance_cap() const { } void Environment::_update_glow() { + Vector<float> normalized_levels; + if (glow_normalize_levels) { + normalized_levels.resize(7); + float size = 0.0; + for (int i = 0; i < glow_levels.size(); i++) { + size += glow_levels[i]; + } + for (int i = 0; i < glow_levels.size(); i++) { + normalized_levels.write[i] = glow_levels[i] / size; + } + } else { + normalized_levels = glow_levels; + } + RS::get_singleton()->environment_set_glow( environment, glow_enabled, - glow_levels, + normalized_levels, glow_intensity, glow_strength, glow_mix, @@ -1162,8 +1182,10 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_glow_enabled", "enabled"), &Environment::set_glow_enabled); ClassDB::bind_method(D_METHOD("is_glow_enabled"), &Environment::is_glow_enabled); - ClassDB::bind_method(D_METHOD("set_glow_level_enabled", "idx", "enabled"), &Environment::set_glow_level_enabled); - ClassDB::bind_method(D_METHOD("is_glow_level_enabled", "idx"), &Environment::is_glow_level_enabled); + ClassDB::bind_method(D_METHOD("set_glow_level", "idx", "intensity"), &Environment::set_glow_level); + ClassDB::bind_method(D_METHOD("get_glow_level", "idx"), &Environment::get_glow_level); + ClassDB::bind_method(D_METHOD("set_glow_normalized", "normalize"), &Environment::set_glow_normalized); + ClassDB::bind_method(D_METHOD("is_glow_normalized"), &Environment::is_glow_normalized); ClassDB::bind_method(D_METHOD("set_glow_intensity", "intensity"), &Environment::set_glow_intensity); ClassDB::bind_method(D_METHOD("get_glow_intensity"), &Environment::get_glow_intensity); ClassDB::bind_method(D_METHOD("set_glow_strength", "strength"), &Environment::set_glow_strength); @@ -1183,13 +1205,14 @@ void Environment::_bind_methods() { ADD_GROUP("Glow", "glow_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_enabled"), "set_glow_enabled", "is_glow_enabled"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/1"), "set_glow_level_enabled", "is_glow_level_enabled", 0); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/2"), "set_glow_level_enabled", "is_glow_level_enabled", 1); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/3"), "set_glow_level_enabled", "is_glow_level_enabled", 2); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/4"), "set_glow_level_enabled", "is_glow_level_enabled", 3); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/5"), "set_glow_level_enabled", "is_glow_level_enabled", 4); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/6"), "set_glow_level_enabled", "is_glow_level_enabled", 5); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/7"), "set_glow_level_enabled", "is_glow_level_enabled", 6); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/1", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 0); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/2", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 1); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/3", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 2); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/4", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 3); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/5", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 4); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/6", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 5); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/7", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 6); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_normalized"), "set_glow_normalized", "is_glow_normalized"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_intensity", PROPERTY_HINT_RANGE, "0.0,8.0,0.01"), "set_glow_intensity", "get_glow_intensity"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_strength", PROPERTY_HINT_RANGE, "0.0,2.0,0.01"), "set_glow_strength", "get_glow_strength"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_mix", PROPERTY_HINT_RANGE, "0.0,1.0,0.001"), "set_glow_mix", "get_glow_mix"); @@ -1329,6 +1352,16 @@ Environment::Environment() { environment = RS::get_singleton()->environment_create(); set_camera_feed_id(bg_camera_feed_id); + + glow_levels.resize(7); + glow_levels.write[0] = 0.0; + glow_levels.write[1] = 0.0; + glow_levels.write[2] = 1.0; + glow_levels.write[3] = 0.0; + glow_levels.write[4] = 1.0; + glow_levels.write[5] = 0.0; + glow_levels.write[6] = 0.0; + _update_ambient_light(); _update_tonemap(); _update_ssr(); diff --git a/scene/resources/environment.h b/scene/resources/environment.h index d4d84f31aa..4361c54b06 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -171,7 +171,8 @@ private: // Glow bool glow_enabled = false; - int glow_levels = (1 << 2) | (1 << 4); + Vector<float> glow_levels; + bool glow_normalize_levels = false; float glow_intensity = 0.8; float glow_strength = 1.0; float glow_mix = 0.05; @@ -332,8 +333,10 @@ public: // Glow void set_glow_enabled(bool p_enabled); bool is_glow_enabled() const; - void set_glow_level_enabled(int p_level, bool p_enabled); - bool is_glow_level_enabled(int p_level) const; + void set_glow_level(int p_level, float p_intensity); + float get_glow_level(int p_level) const; + void set_glow_normalized(bool p_normalized); + bool is_glow_normalized() const; void set_glow_intensity(float p_intensity); float get_glow_intensity() const; void set_glow_strength(float p_strength); |