diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/environment.cpp | 70 | ||||
-rw-r--r-- | scene/resources/environment.h | 20 | ||||
-rw-r--r-- | scene/resources/sky_box.cpp | 119 | ||||
-rw-r--r-- | scene/resources/sky_box.h | 35 |
4 files changed, 88 insertions, 156 deletions
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 96871cc944..39943b99db 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -44,21 +44,21 @@ void Environment::set_background(BGMode p_bg) { _change_notify(); } -void Environment::set_skybox(const Ref<SkyBox> &p_skybox) { +void Environment::set_sky(const Ref<Sky> &p_sky) { - bg_skybox = p_skybox; + bg_sky = p_sky; RID sb_rid; - if (bg_skybox.is_valid()) - sb_rid = bg_skybox->get_rid(); + if (bg_sky.is_valid()) + sb_rid = bg_sky->get_rid(); - VS::get_singleton()->environment_set_skybox(environment, sb_rid); + VS::get_singleton()->environment_set_sky(environment, sb_rid); } -void Environment::set_skybox_scale(float p_scale) { +void Environment::set_sky_scale(float p_scale) { - bg_skybox_scale = p_scale; - VS::get_singleton()->environment_set_skybox_scale(environment, p_scale); + bg_sky_scale = p_scale; + VS::get_singleton()->environment_set_sky_scale(environment, p_scale); } void Environment::set_bg_color(const Color &p_color) { @@ -79,31 +79,31 @@ void Environment::set_canvas_max_layer(int p_max_layer) { void Environment::set_ambient_light_color(const Color &p_color) { ambient_color = p_color; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_skybox_contribution); + VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_sky_contribution); } void Environment::set_ambient_light_energy(float p_energy) { ambient_energy = p_energy; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_skybox_contribution); + VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_sky_contribution); } -void Environment::set_ambient_light_skybox_contribution(float p_energy) { +void Environment::set_ambient_light_sky_contribution(float p_energy) { - ambient_skybox_contribution = p_energy; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_skybox_contribution); + ambient_sky_contribution = p_energy; + VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_sky_contribution); } Environment::BGMode Environment::get_background() const { return bg_mode; } -Ref<SkyBox> Environment::get_skybox() const { +Ref<Sky> Environment::get_sky() const { - return bg_skybox; + return bg_sky; } -float Environment::get_skybox_scale() const { +float Environment::get_sky_scale() const { - return bg_skybox_scale; + return bg_sky_scale; } Color Environment::get_bg_color() const { @@ -126,9 +126,9 @@ float Environment::get_ambient_light_energy() const { return ambient_energy; } -float Environment::get_ambient_light_skybox_contribution() const { +float Environment::get_ambient_light_sky_contribution() const { - return ambient_skybox_contribution; + return ambient_sky_contribution; } void Environment::set_tonemapper(ToneMapper p_tone_mapper) { @@ -266,8 +266,8 @@ Ref<Texture> Environment::get_adjustment_color_correction() const { void Environment::_validate_property(PropertyInfo &property) const { - if (property.name == "background/skybox" || property.name == "background/skybox_scale" || property.name == "ambient_light/skybox_contribution") { - if (bg_mode != BG_SKYBOX) { + if (property.name == "background/sky" || property.name == "background/sky_scale" || property.name == "ambient_light/sky_contribution") { + if (bg_mode != BG_SKY) { property.usage = PROPERTY_USAGE_NOEDITOR; } } @@ -664,36 +664,36 @@ Environment::DOFBlurQuality Environment::get_dof_blur_near_quality() const { void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_background", "mode"), &Environment::set_background); - ClassDB::bind_method(D_METHOD("set_skybox", "skybox:CubeMap"), &Environment::set_skybox); - ClassDB::bind_method(D_METHOD("set_skybox_scale", "scale"), &Environment::set_skybox_scale); + ClassDB::bind_method(D_METHOD("set_sky", "sky:CubeMap"), &Environment::set_sky); + ClassDB::bind_method(D_METHOD("set_sky_scale", "scale"), &Environment::set_sky_scale); ClassDB::bind_method(D_METHOD("set_bg_color", "color"), &Environment::set_bg_color); ClassDB::bind_method(D_METHOD("set_bg_energy", "energy"), &Environment::set_bg_energy); ClassDB::bind_method(D_METHOD("set_canvas_max_layer", "layer"), &Environment::set_canvas_max_layer); ClassDB::bind_method(D_METHOD("set_ambient_light_color", "color"), &Environment::set_ambient_light_color); ClassDB::bind_method(D_METHOD("set_ambient_light_energy", "energy"), &Environment::set_ambient_light_energy); - ClassDB::bind_method(D_METHOD("set_ambient_light_skybox_contribution", "energy"), &Environment::set_ambient_light_skybox_contribution); + ClassDB::bind_method(D_METHOD("set_ambient_light_sky_contribution", "energy"), &Environment::set_ambient_light_sky_contribution); ClassDB::bind_method(D_METHOD("get_background"), &Environment::get_background); - ClassDB::bind_method(D_METHOD("get_skybox:CubeMap"), &Environment::get_skybox); - ClassDB::bind_method(D_METHOD("get_skybox_scale"), &Environment::get_skybox_scale); + ClassDB::bind_method(D_METHOD("get_sky:CubeMap"), &Environment::get_sky); + ClassDB::bind_method(D_METHOD("get_sky_scale"), &Environment::get_sky_scale); ClassDB::bind_method(D_METHOD("get_bg_color"), &Environment::get_bg_color); ClassDB::bind_method(D_METHOD("get_bg_energy"), &Environment::get_bg_energy); ClassDB::bind_method(D_METHOD("get_canvas_max_layer"), &Environment::get_canvas_max_layer); ClassDB::bind_method(D_METHOD("get_ambient_light_color"), &Environment::get_ambient_light_color); ClassDB::bind_method(D_METHOD("get_ambient_light_energy"), &Environment::get_ambient_light_energy); - ClassDB::bind_method(D_METHOD("get_ambient_light_skybox_contribution"), &Environment::get_ambient_light_skybox_contribution); + ClassDB::bind_method(D_METHOD("get_ambient_light_sky_contribution"), &Environment::get_ambient_light_sky_contribution); ADD_GROUP("Background", "background_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "background_mode", PROPERTY_HINT_ENUM, "Clear Color,Custom Color,Skybox,Canvas,Keep"), "set_background", "get_background"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "background_skybox", PROPERTY_HINT_RESOURCE_TYPE, "SkyBox"), "set_skybox", "get_skybox"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_skybox_scale", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_skybox_scale", "get_skybox_scale"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "background_mode", PROPERTY_HINT_ENUM, "Clear Color,Custom Color,Sky,Canvas,Keep"), "set_background", "get_background"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "background_sky", PROPERTY_HINT_RESOURCE_TYPE, "Sky"), "set_sky", "get_sky"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_sky_scale", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_sky_scale", "get_sky_scale"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "background_color"), "set_bg_color", "get_bg_color"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_bg_energy", "get_bg_energy"); ADD_PROPERTY(PropertyInfo(Variant::INT, "background_canvas_max_layer", PROPERTY_HINT_RANGE, "-1000,1000,1"), "set_canvas_max_layer", "get_canvas_max_layer"); ADD_GROUP("Ambient Light", "ambient_light_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ambient_light_color"), "set_ambient_light_color", "get_ambient_light_color"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_ambient_light_energy", "get_ambient_light_energy"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_skybox_contribution", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ambient_light_skybox_contribution", "get_ambient_light_skybox_contribution"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_sky_contribution", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ambient_light_sky_contribution", "get_ambient_light_sky_contribution"); ClassDB::bind_method(D_METHOD("set_ssr_enabled", "enabled"), &Environment::set_ssr_enabled); ClassDB::bind_method(D_METHOD("is_ssr_enabled"), &Environment::is_ssr_enabled); @@ -909,12 +909,12 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "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, "Texture"), "set_adjustment_color_correction", "get_adjustment_color_correction"); - GLOBAL_DEF("rendering/skybox/irradiance_cube_resolution", 256); + GLOBAL_DEF("rendering/sky/irradiance_cube_resolution", 256); BIND_CONSTANT(BG_KEEP); BIND_CONSTANT(BG_CLEAR_COLOR); BIND_CONSTANT(BG_COLOR); - BIND_CONSTANT(BG_SKYBOX); + BIND_CONSTANT(BG_SKY); BIND_CONSTANT(BG_CANVAS); BIND_CONSTANT(BG_MAX); BIND_CONSTANT(GLOW_BLEND_MODE_ADDITIVE); @@ -933,11 +933,11 @@ void Environment::_bind_methods() { Environment::Environment() { bg_mode = BG_CLEAR_COLOR; - bg_skybox_scale = 1.0; + bg_sky_scale = 1.0; bg_energy = 1.0; bg_canvas_max_layer = 0; ambient_energy = 1.0; - ambient_skybox_contribution = 0; + ambient_sky_contribution = 0; tone_mapper = TONE_MAPPER_LINEAR; tonemap_exposure = 1.0; diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 9014a9f5c2..d9141ccd9c 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -44,7 +44,7 @@ public: BG_CLEAR_COLOR, BG_COLOR, - BG_SKYBOX, + BG_SKY, BG_CANVAS, BG_KEEP, BG_MAX @@ -74,14 +74,14 @@ private: RID environment; BGMode bg_mode; - Ref<SkyBox> bg_skybox; - float bg_skybox_scale; + Ref<Sky> bg_sky; + float bg_sky_scale; Color bg_color; float bg_energy; int bg_canvas_max_layer; Color ambient_color; float ambient_energy; - float ambient_skybox_contribution; + float ambient_sky_contribution; ToneMapper tone_mapper; float tonemap_exposure; @@ -144,24 +144,24 @@ protected: public: void set_background(BGMode p_bg); - void set_skybox(const Ref<SkyBox> &p_skybox); - void set_skybox_scale(float p_scale); + void set_sky(const Ref<Sky> &p_sky); + void set_sky_scale(float p_scale); void set_bg_color(const Color &p_color); void set_bg_energy(float p_energy); void set_canvas_max_layer(int p_max_layer); void set_ambient_light_color(const Color &p_color); void set_ambient_light_energy(float p_energy); - void set_ambient_light_skybox_contribution(float p_energy); + void set_ambient_light_sky_contribution(float p_energy); BGMode get_background() const; - Ref<SkyBox> get_skybox() const; - float get_skybox_scale() const; + Ref<Sky> get_sky() const; + float get_sky_scale() const; Color get_bg_color() const; float get_bg_energy() const; int get_canvas_max_layer() const; Color get_ambient_light_color() const; float get_ambient_light_energy() const; - float get_ambient_light_skybox_contribution() const; + float get_ambient_light_sky_contribution() const; void set_tonemapper(ToneMapper p_tone_mapper); ToneMapper get_tonemapper() const; diff --git a/scene/resources/sky_box.cpp b/scene/resources/sky_box.cpp index 2fd074de0f..59ade4a729 100644 --- a/scene/resources/sky_box.cpp +++ b/scene/resources/sky_box.cpp @@ -30,22 +30,22 @@ #include "sky_box.h" #include "io/image_loader.h" -void SkyBox::set_radiance_size(RadianceSize p_size) { +void Sky::set_radiance_size(RadianceSize p_size) { ERR_FAIL_INDEX(p_size, RADIANCE_SIZE_MAX); radiance_size = p_size; _radiance_changed(); } -SkyBox::RadianceSize SkyBox::get_radiance_size() const { +Sky::RadianceSize Sky::get_radiance_size() const { return radiance_size; } -void SkyBox::_bind_methods() { +void Sky::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &SkyBox::set_radiance_size); - ClassDB::bind_method(D_METHOD("get_radiance_size"), &SkyBox::get_radiance_size); + ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &Sky::set_radiance_size); + ClassDB::bind_method(D_METHOD("get_radiance_size"), &Sky::get_radiance_size); ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "256,512,1024,2048"), "set_radiance_size", "get_radiance_size"); @@ -56,124 +56,59 @@ void SkyBox::_bind_methods() { BIND_CONSTANT(RADIANCE_SIZE_MAX); } -SkyBox::SkyBox() { +Sky::Sky() { radiance_size = RADIANCE_SIZE_512; } ///////////////////////////////////////// -void ImageSkyBox::_radiance_changed() { +void PanoramaSky::_radiance_changed() { - if (cube_map_valid) { + if (panorama.is_valid()) { static const int size[RADIANCE_SIZE_MAX] = { 256, 512, 1024, 2048 }; - VS::get_singleton()->skybox_set_texture(sky_box, cube_map, size[get_radiance_size()]); + VS::get_singleton()->sky_set_texture(sky, panorama->get_rid(), size[get_radiance_size()]); } } -void ImageSkyBox::set_image_path(ImagePath p_image, const String &p_path) { +void PanoramaSky::set_panorama(const Ref<Texture> &p_panorama) { - ERR_FAIL_INDEX(p_image, IMAGE_PATH_MAX); - image_path[p_image] = p_path; + panorama = p_panorama; - bool all_ok = true; - for (int i = 0; i < IMAGE_PATH_MAX; i++) { - if (image_path[i] == String()) { - all_ok = false; - } - } + if (panorama.is_valid()) { - cube_map_valid = false; - - if (all_ok) { - - Ref<Image> images[IMAGE_PATH_MAX]; - int w = 0, h = 0; - Image::Format format; - - for (int i = 0; i < IMAGE_PATH_MAX; i++) { - images[i].instance(); - Error err = ImageLoader::load_image(image_path[i], images[i]); - if (err) { - ERR_PRINTS("Error loading image for skybox: " + image_path[i]); - return; - } - - if (i == 0) { - w = images[0]->get_width(); - h = images[0]->get_height(); - format = images[0]->get_format(); - } else { - if (images[i]->get_width() != w || images[i]->get_height() != h || images[i]->get_format() != format) { - ERR_PRINTS("Image size mismatch (" + itos(images[i]->get_width()) + "," + itos(images[i]->get_height()) + ":" + Image::get_format_name(images[i]->get_format()) + " when it should be " + itos(w) + "," + itos(h) + ":" + Image::get_format_name(format) + "): " + image_path[i]); - return; - } - } - } - - VS::get_singleton()->texture_allocate(cube_map, w, h, format, VS::TEXTURE_FLAG_FILTER | VS::TEXTURE_FLAG_CUBEMAP | VS::TEXTURE_FLAG_MIPMAPS); - for (int i = 0; i < IMAGE_PATH_MAX; i++) { - VS::get_singleton()->texture_set_data(cube_map, images[i], VS::CubeMapSide(i)); - } - - cube_map_valid = true; _radiance_changed(); + + } else { + VS::get_singleton()->sky_set_texture(sky, RID(), 0); } } -String ImageSkyBox::get_image_path(ImagePath p_image) const { +Ref<Texture> PanoramaSky::get_panorama() const { - ERR_FAIL_INDEX_V(p_image, IMAGE_PATH_MAX, String()); - return image_path[p_image]; + return panorama; } -RID ImageSkyBox::get_rid() const { +RID PanoramaSky::get_rid() const { - return sky_box; + return sky; } -void ImageSkyBox::_bind_methods() { +void PanoramaSky::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_image_path", "image", "path"), &ImageSkyBox::set_image_path); - ClassDB::bind_method(D_METHOD("get_image_path", "image"), &ImageSkyBox::get_image_path); - - List<String> extensions; - ImageLoader::get_recognized_extensions(&extensions); - String hints; - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (hints != String()) { - hints += ","; - } - hints += "*." + E->get(); - } + ClassDB::bind_method(D_METHOD("set_panorama", "texture:Texture"), &PanoramaSky::set_panorama); + ClassDB::bind_method(D_METHOD("get_panorama:Texture"), &PanoramaSky::get_panorama); - ADD_GROUP("Image Path", "image_path_"); - ADD_PROPERTYI(PropertyInfo(Variant::STRING, "image_path_negative_x", PROPERTY_HINT_FILE, hints), "set_image_path", "get_image_path", IMAGE_PATH_NEGATIVE_X); - ADD_PROPERTYI(PropertyInfo(Variant::STRING, "image_path_positive_x", PROPERTY_HINT_FILE, hints), "set_image_path", "get_image_path", IMAGE_PATH_POSITIVE_X); - ADD_PROPERTYI(PropertyInfo(Variant::STRING, "image_path_negative_y", PROPERTY_HINT_FILE, hints), "set_image_path", "get_image_path", IMAGE_PATH_NEGATIVE_Y); - ADD_PROPERTYI(PropertyInfo(Variant::STRING, "image_path_positive_y", PROPERTY_HINT_FILE, hints), "set_image_path", "get_image_path", IMAGE_PATH_POSITIVE_Y); - ADD_PROPERTYI(PropertyInfo(Variant::STRING, "image_path_negative_z", PROPERTY_HINT_FILE, hints), "set_image_path", "get_image_path", IMAGE_PATH_NEGATIVE_Z); - ADD_PROPERTYI(PropertyInfo(Variant::STRING, "image_path_positive_z", PROPERTY_HINT_FILE, hints), "set_image_path", "get_image_path", IMAGE_PATH_POSITIVE_Z); - - BIND_CONSTANT(IMAGE_PATH_NEGATIVE_X); - BIND_CONSTANT(IMAGE_PATH_POSITIVE_X); - BIND_CONSTANT(IMAGE_PATH_NEGATIVE_Y); - BIND_CONSTANT(IMAGE_PATH_POSITIVE_Y); - BIND_CONSTANT(IMAGE_PATH_NEGATIVE_Z); - BIND_CONSTANT(IMAGE_PATH_POSITIVE_Z); - BIND_CONSTANT(IMAGE_PATH_MAX); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "panorama", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_panorama", "get_panorama"); } -ImageSkyBox::ImageSkyBox() { +PanoramaSky::PanoramaSky() { - cube_map = VS::get_singleton()->texture_create(); - sky_box = VS::get_singleton()->skybox_create(); - cube_map_valid = false; + sky = VS::get_singleton()->sky_create(); } -ImageSkyBox::~ImageSkyBox() { +PanoramaSky::~PanoramaSky() { - VS::get_singleton()->free(cube_map); - VS::get_singleton()->free(sky_box); + VS::get_singleton()->free(sky); } diff --git a/scene/resources/sky_box.h b/scene/resources/sky_box.h index f748ac1e2d..afbfb3019e 100644 --- a/scene/resources/sky_box.h +++ b/scene/resources/sky_box.h @@ -27,13 +27,13 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SKYBOX_H -#define SKYBOX_H +#ifndef Sky_H +#define Sky_H #include "scene/resources/texture.h" -class SkyBox : public Resource { - GDCLASS(SkyBox, Resource); +class Sky : public Resource { + GDCLASS(Sky, Resource); public: enum RadianceSize { @@ -54,13 +54,13 @@ protected: public: void set_radiance_size(RadianceSize p_size); RadianceSize get_radiance_size() const; - SkyBox(); + Sky(); }; -VARIANT_ENUM_CAST(SkyBox::RadianceSize) +VARIANT_ENUM_CAST(Sky::RadianceSize) -class ImageSkyBox : public SkyBox { - GDCLASS(ImageSkyBox, SkyBox); +class PanoramaSky : public Sky { + GDCLASS(PanoramaSky, Sky); public: enum ImagePath { @@ -74,26 +74,23 @@ public: }; private: - RID cube_map; - RID sky_box; - bool cube_map_valid; - - String image_path[IMAGE_PATH_MAX]; + RID sky; + Ref<Texture> panorama; protected: static void _bind_methods(); virtual void _radiance_changed(); public: - void set_image_path(ImagePath p_image, const String &p_path); - String get_image_path(ImagePath p_image) const; + void set_panorama(const Ref<Texture> &p_panorama); + Ref<Texture> get_panorama() const; virtual RID get_rid() const; - ImageSkyBox(); - ~ImageSkyBox(); + PanoramaSky(); + ~PanoramaSky(); }; -VARIANT_ENUM_CAST(ImageSkyBox::ImagePath) +VARIANT_ENUM_CAST(PanoramaSky::ImagePath) -#endif // SKYBOX_H +#endif // Sky_H |