diff options
Diffstat (limited to 'scene/resources/environment.cpp')
-rw-r--r-- | scene/resources/environment.cpp | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 3df539c86e..f4edab07b5 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -581,22 +581,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) { @@ -673,10 +679,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, @@ -1180,8 +1200,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); @@ -1201,13 +1223,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"); @@ -1351,6 +1374,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(); |