diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-06-26 12:11:54 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 12:11:54 -0300 |
commit | a4e200a47a151ed5ce1627a17ce694048987eadf (patch) | |
tree | 1bbd204d9375dfb3b0fe07fb66b787a5aa2e79e4 /scene/3d | |
parent | b92477d77e9a6f46e4276a20a451dfac9d485f47 (diff) | |
parent | 201d606b3d348c3287f3d57d25e6eced298c2df5 (diff) |
Merge pull request #39827 from reduz/sdfgi
Addition of SDFGI for open world global illumination
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/baked_lightmap.cpp | 6 | ||||
-rw-r--r-- | scene/3d/light_3d.cpp | 10 | ||||
-rw-r--r-- | scene/3d/light_3d.h | 4 | ||||
-rw-r--r-- | scene/3d/reflection_probe.cpp | 68 | ||||
-rw-r--r-- | scene/3d/reflection_probe.h | 24 |
5 files changed, 63 insertions, 49 deletions
diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index a41eaf9da0..e867891ec0 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -894,13 +894,13 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d if (Object::cast_to<DirectionalLight3D>(light)) { DirectionalLight3D *l = Object::cast_to<DirectionalLight3D>(light); - lightmapper->add_directional_light(light->get_bake_mode() == Light3D::BAKE_ALL, -xf.basis.get_axis(Vector3::AXIS_Z).normalized(), l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_SIZE)); + lightmapper->add_directional_light(light->get_bake_mode() == Light3D::BAKE_STATIC, -xf.basis.get_axis(Vector3::AXIS_Z).normalized(), l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_SIZE)); } else if (Object::cast_to<OmniLight3D>(light)) { OmniLight3D *l = Object::cast_to<OmniLight3D>(light); - lightmapper->add_omni_light(light->get_bake_mode() == Light3D::BAKE_ALL, xf.origin, l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_RANGE), l->get_param(Light3D::PARAM_ATTENUATION), l->get_param(Light3D::PARAM_SIZE)); + lightmapper->add_omni_light(light->get_bake_mode() == Light3D::BAKE_STATIC, xf.origin, l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_RANGE), l->get_param(Light3D::PARAM_ATTENUATION), l->get_param(Light3D::PARAM_SIZE)); } else if (Object::cast_to<SpotLight3D>(light)) { SpotLight3D *l = Object::cast_to<SpotLight3D>(light); - lightmapper->add_spot_light(light->get_bake_mode() == Light3D::BAKE_ALL, xf.origin, -xf.basis.get_axis(Vector3::AXIS_Z).normalized(), l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_RANGE), l->get_param(Light3D::PARAM_ATTENUATION), l->get_param(Light3D::PARAM_SPOT_ANGLE), l->get_param(Light3D::PARAM_SPOT_ATTENUATION), l->get_param(Light3D::PARAM_SIZE)); + lightmapper->add_spot_light(light->get_bake_mode() == Light3D::BAKE_STATIC, xf.origin, -xf.basis.get_axis(Vector3::AXIS_Z).normalized(), l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_RANGE), l->get_param(Light3D::PARAM_ATTENUATION), l->get_param(Light3D::PARAM_SPOT_ANGLE), l->get_param(Light3D::PARAM_SPOT_ATTENUATION), l->get_param(Light3D::PARAM_SIZE)); } } for (int i = 0; i < probes_found.size(); i++) { diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp index 9270b548b7..cc1622722e 100644 --- a/scene/3d/light_3d.cpp +++ b/scene/3d/light_3d.cpp @@ -144,7 +144,7 @@ Vector<Face3> Light3D::get_faces(uint32_t p_usage_flags) const { void Light3D::set_bake_mode(BakeMode p_mode) { bake_mode = p_mode; - RS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED); + RS::get_singleton()->light_set_bake_mode(light, RS::LightBakeMode(p_mode)); } Light3D::BakeMode Light3D::get_bake_mode() const { @@ -261,7 +261,7 @@ void Light3D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_angular_distance", PROPERTY_HINT_RANGE, "0,90,0.01"), "set_param", "get_param", PARAM_SIZE); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR); - ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disable,Indirect,All"), "set_bake_mode", "get_bake_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disabled,Dynamic,Static"), "set_bake_mode", "get_bake_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask"); ADD_GROUP("Shadow", "shadow_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow"); @@ -296,8 +296,8 @@ void Light3D::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_MAX); BIND_ENUM_CONSTANT(BAKE_DISABLED); - BIND_ENUM_CONSTANT(BAKE_INDIRECT); - BIND_ENUM_CONSTANT(BAKE_ALL); + BIND_ENUM_CONSTANT(BAKE_DYNAMIC); + BIND_ENUM_CONSTANT(BAKE_STATIC); } Light3D::Light3D(RenderingServer::LightType p_type) { @@ -319,7 +319,7 @@ Light3D::Light3D(RenderingServer::LightType p_type) { RS::get_singleton()->instance_set_base(get_instance(), light); reverse_cull = false; - bake_mode = BAKE_INDIRECT; + bake_mode = BAKE_DYNAMIC; editor_only = false; set_color(Color(1, 1, 1, 1)); diff --git a/scene/3d/light_3d.h b/scene/3d/light_3d.h index f16773f6ae..09fc81b216 100644 --- a/scene/3d/light_3d.h +++ b/scene/3d/light_3d.h @@ -64,8 +64,8 @@ public: enum BakeMode { BAKE_DISABLED, - BAKE_INDIRECT, - BAKE_ALL + BAKE_DYNAMIC, + BAKE_STATIC }; private: diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index b1f19053d9..c7948395d3 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -39,31 +39,32 @@ float ReflectionProbe::get_intensity() const { return intensity; } -void ReflectionProbe::set_interior_ambient(Color p_ambient) { - interior_ambient = p_ambient; - RS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient); +void ReflectionProbe::set_ambient_mode(AmbientMode p_mode) { + ambient_mode = p_mode; + RS::get_singleton()->reflection_probe_set_ambient_mode(probe, RS::ReflectionProbeAmbientMode(p_mode)); + _change_notify(); } -void ReflectionProbe::set_interior_ambient_energy(float p_energy) { - interior_ambient_energy = p_energy; - RS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy); +ReflectionProbe::AmbientMode ReflectionProbe::get_ambient_mode() const { + return ambient_mode; } -float ReflectionProbe::get_interior_ambient_energy() const { - return interior_ambient_energy; +void ReflectionProbe::set_ambient_color(Color p_ambient) { + ambient_color = p_ambient; + RS::get_singleton()->reflection_probe_set_ambient_color(probe, p_ambient); } -Color ReflectionProbe::get_interior_ambient() const { - return interior_ambient; +void ReflectionProbe::set_ambient_color_energy(float p_energy) { + ambient_color_energy = p_energy; + RS::get_singleton()->reflection_probe_set_ambient_energy(probe, p_energy); } -void ReflectionProbe::set_interior_ambient_probe_contribution(float p_contribution) { - interior_ambient_probe_contribution = p_contribution; - RS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution); +float ReflectionProbe::get_ambient_color_energy() const { + return ambient_color_energy; } -float ReflectionProbe::get_interior_ambient_probe_contribution() const { - return interior_ambient_probe_contribution; +Color ReflectionProbe::get_ambient_color() const { + return ambient_color; } void ReflectionProbe::set_max_distance(float p_distance) { @@ -130,7 +131,6 @@ bool ReflectionProbe::is_box_projection_enabled() const { void ReflectionProbe::set_as_interior(bool p_enable) { interior = p_enable; RS::get_singleton()->reflection_probe_set_as_interior(probe, interior); - _change_notify(); } bool ReflectionProbe::is_set_as_interior() const { @@ -176,8 +176,8 @@ Vector<Face3> ReflectionProbe::get_faces(uint32_t p_usage_flags) const { } void ReflectionProbe::_validate_property(PropertyInfo &property) const { - if (property.name == "interior/ambient_color" || property.name == "interior/ambient_energy" || property.name == "interior/ambient_contrib") { - if (!interior) { + if (property.name == "interior/ambient_color" || property.name == "interior/ambient_color_energy") { + if (ambient_mode != AMBIENT_COLOR) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; } } @@ -187,14 +187,14 @@ void ReflectionProbe::_bind_methods() { ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &ReflectionProbe::set_intensity); ClassDB::bind_method(D_METHOD("get_intensity"), &ReflectionProbe::get_intensity); - ClassDB::bind_method(D_METHOD("set_interior_ambient", "ambient"), &ReflectionProbe::set_interior_ambient); - ClassDB::bind_method(D_METHOD("get_interior_ambient"), &ReflectionProbe::get_interior_ambient); + ClassDB::bind_method(D_METHOD("set_ambient_mode", "ambient"), &ReflectionProbe::set_ambient_mode); + ClassDB::bind_method(D_METHOD("get_ambient_mode"), &ReflectionProbe::get_ambient_mode); - ClassDB::bind_method(D_METHOD("set_interior_ambient_energy", "ambient_energy"), &ReflectionProbe::set_interior_ambient_energy); - ClassDB::bind_method(D_METHOD("get_interior_ambient_energy"), &ReflectionProbe::get_interior_ambient_energy); + ClassDB::bind_method(D_METHOD("set_ambient_color", "ambient"), &ReflectionProbe::set_ambient_color); + ClassDB::bind_method(D_METHOD("get_ambient_color"), &ReflectionProbe::get_ambient_color); - ClassDB::bind_method(D_METHOD("set_interior_ambient_probe_contribution", "ambient_probe_contribution"), &ReflectionProbe::set_interior_ambient_probe_contribution); - ClassDB::bind_method(D_METHOD("get_interior_ambient_probe_contribution"), &ReflectionProbe::get_interior_ambient_probe_contribution); + ClassDB::bind_method(D_METHOD("set_ambient_color_energy", "ambient_energy"), &ReflectionProbe::set_ambient_color_energy); + ClassDB::bind_method(D_METHOD("get_ambient_color_energy"), &ReflectionProbe::get_ambient_color_energy); ClassDB::bind_method(D_METHOD("set_max_distance", "max_distance"), &ReflectionProbe::set_max_distance); ClassDB::bind_method(D_METHOD("get_max_distance"), &ReflectionProbe::get_max_distance); @@ -226,24 +226,28 @@ void ReflectionProbe::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "origin_offset"), "set_origin_offset", "get_origin_offset"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "box_projection"), "set_enable_box_projection", "is_box_projection_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_as_interior", "is_set_as_interior"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_shadows"), "set_enable_shadows", "are_shadows_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask"); - ADD_GROUP("Interior", "interior_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior_enable"), "set_as_interior", "is_set_as_interior"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "interior_ambient_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_interior_ambient", "get_interior_ambient"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interior_ambient_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_interior_ambient_energy", "get_interior_ambient_energy"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interior_ambient_contrib", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_interior_ambient_probe_contribution", "get_interior_ambient_probe_contribution"); + ADD_GROUP("Ambient", "ambient_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "ambient_mode", PROPERTY_HINT_ENUM, "Disabled,Environment,ConstantColor"), "set_ambient_mode", "get_ambient_mode"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ambient_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_ambient_color", "get_ambient_color"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ambient_color_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_ambient_color_energy", "get_ambient_color_energy"); BIND_ENUM_CONSTANT(UPDATE_ONCE); BIND_ENUM_CONSTANT(UPDATE_ALWAYS); + + BIND_ENUM_CONSTANT(AMBIENT_DISABLED); + BIND_ENUM_CONSTANT(AMBIENT_ENVIRONMENT); + BIND_ENUM_CONSTANT(AMBIENT_COLOR); } ReflectionProbe::ReflectionProbe() { intensity = 1.0; - interior_ambient = Color(0, 0, 0); - interior_ambient_probe_contribution = 0; - interior_ambient_energy = 1.0; + ambient_mode = AMBIENT_ENVIRONMENT; + ambient_color = Color(0, 0, 0); + ambient_color_energy = 1.0; max_distance = 0; extents = Vector3(1, 1, 1); origin_offset = Vector3(0, 0, 0); diff --git a/scene/3d/reflection_probe.h b/scene/3d/reflection_probe.h index 3867d13435..c708804f96 100644 --- a/scene/3d/reflection_probe.h +++ b/scene/3d/reflection_probe.h @@ -45,6 +45,12 @@ public: UPDATE_ALWAYS, }; + enum AmbientMode { + AMBIENT_DISABLED, + AMBIENT_ENVIRONMENT, + AMBIENT_COLOR + }; + private: RID probe; float intensity; @@ -54,9 +60,9 @@ private: bool box_projection; bool enable_shadows; bool interior; - Color interior_ambient; - float interior_ambient_energy; - float interior_ambient_probe_contribution; + AmbientMode ambient_mode; + Color ambient_color; + float ambient_color_energy; uint32_t cull_mask; UpdateMode update_mode; @@ -69,11 +75,14 @@ public: void set_intensity(float p_intensity); float get_intensity() const; - void set_interior_ambient(Color p_ambient); - Color get_interior_ambient() const; + void set_ambient_mode(AmbientMode p_mode); + AmbientMode get_ambient_mode() const; + + void set_ambient_color(Color p_ambient); + Color get_ambient_color() const; - void set_interior_ambient_energy(float p_energy); - float get_interior_ambient_energy() const; + void set_ambient_color_energy(float p_energy); + float get_ambient_color_energy() const; void set_interior_ambient_probe_contribution(float p_contribution); float get_interior_ambient_probe_contribution() const; @@ -109,6 +118,7 @@ public: ~ReflectionProbe(); }; +VARIANT_ENUM_CAST(ReflectionProbe::AmbientMode); VARIANT_ENUM_CAST(ReflectionProbe::UpdateMode); #endif // REFLECTIONPROBE_H |