2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* fog_volume.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2021-10-03 13:28:55 +02:00
|
|
|
|
|
|
|
#include "fog_volume.h"
|
2022-08-01 01:20:24 +02:00
|
|
|
#include "scene/resources/environment.h"
|
2021-10-03 13:28:55 +02:00
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
|
|
|
void FogVolume::_bind_methods() {
|
2022-07-12 09:43:01 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_size", "size"), &FogVolume::set_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_size"), &FogVolume::get_size);
|
2021-10-03 13:28:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &FogVolume::set_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shape"), &FogVolume::get_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_material", "material"), &FogVolume::set_material);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_material"), &FogVolume::get_material);
|
|
|
|
|
2022-07-12 09:43:01 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater,suffix:m"), "set_size", "get_size");
|
2022-05-21 12:17:49 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "shape", PROPERTY_HINT_ENUM, "Ellipsoid (Local),Cone (Local),Cylinder (Local),Box (Local),World (Global)"), "set_shape", "get_shape");
|
2021-10-03 13:28:55 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "FogMaterial,ShaderMaterial"), "set_material", "get_material");
|
|
|
|
}
|
|
|
|
|
2022-08-12 22:57:11 +02:00
|
|
|
void FogVolume::_validate_property(PropertyInfo &p_property) const {
|
2022-07-12 09:43:01 +02:00
|
|
|
if (p_property.name == "size" && shape == RS::FOG_VOLUME_SHAPE_WORLD) {
|
2022-08-12 22:57:11 +02:00
|
|
|
p_property.usage = PROPERTY_USAGE_NONE;
|
2021-10-03 13:28:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 09:43:01 +02:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool FogVolume::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
if (p_name == "extents") { // Compatibility with Godot 3.x.
|
|
|
|
set_size((Vector3)p_value * 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FogVolume::_get(const StringName &p_name, Variant &r_property) const {
|
|
|
|
if (p_name == "extents") { // Compatibility with Godot 3.x.
|
|
|
|
r_property = size / 2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // DISABLE_DEPRECATED
|
|
|
|
|
|
|
|
void FogVolume::set_size(const Vector3 &p_size) {
|
|
|
|
size = p_size;
|
2024-03-03 12:49:08 +01:00
|
|
|
size = size.max(Vector3());
|
2022-07-12 09:43:01 +02:00
|
|
|
RS::get_singleton()->fog_volume_set_size(_get_volume(), size);
|
2021-10-03 13:28:55 +02:00
|
|
|
update_gizmos();
|
|
|
|
}
|
|
|
|
|
2022-07-12 09:43:01 +02:00
|
|
|
Vector3 FogVolume::get_size() const {
|
|
|
|
return size;
|
2021-10-03 13:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FogVolume::set_shape(RS::FogVolumeShape p_type) {
|
|
|
|
shape = p_type;
|
|
|
|
RS::get_singleton()->fog_volume_set_shape(_get_volume(), shape);
|
|
|
|
RS::get_singleton()->instance_set_ignore_culling(get_instance(), shape == RS::FOG_VOLUME_SHAPE_WORLD);
|
|
|
|
update_gizmos();
|
|
|
|
notify_property_list_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
RS::FogVolumeShape FogVolume::get_shape() const {
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FogVolume::set_material(const Ref<Material> &p_material) {
|
|
|
|
material = p_material;
|
|
|
|
RID material_rid;
|
|
|
|
if (material.is_valid()) {
|
|
|
|
material_rid = material->get_rid();
|
|
|
|
}
|
|
|
|
RS::get_singleton()->fog_volume_set_material(_get_volume(), material_rid);
|
|
|
|
update_gizmos();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Material> FogVolume::get_material() const {
|
|
|
|
return material;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB FogVolume::get_aabb() const {
|
|
|
|
if (shape != RS::FOG_VOLUME_SHAPE_WORLD) {
|
2022-07-12 09:43:01 +02:00
|
|
|
return AABB(-size / 2, size);
|
2021-10-03 13:28:55 +02:00
|
|
|
}
|
|
|
|
return AABB();
|
|
|
|
}
|
|
|
|
|
2024-02-17 19:03:21 +01:00
|
|
|
PackedStringArray FogVolume::get_configuration_warnings() const {
|
|
|
|
PackedStringArray warnings = Node::get_configuration_warnings();
|
2021-10-03 13:28:55 +02:00
|
|
|
|
2021-10-29 12:38:00 +02:00
|
|
|
Ref<Environment> environment = get_viewport()->find_world_3d()->get_environment();
|
|
|
|
|
2023-02-26 01:24:41 +01:00
|
|
|
if (OS::get_singleton()->get_current_rendering_method() != "forward_plus") {
|
|
|
|
warnings.push_back(RTR("Fog Volumes are only visible when using the Forward+ backend."));
|
|
|
|
return warnings;
|
|
|
|
}
|
|
|
|
|
2021-10-29 12:38:00 +02:00
|
|
|
if (environment.is_valid() && !environment->is_volumetric_fog_enabled()) {
|
2023-02-26 01:24:41 +01:00
|
|
|
warnings.push_back(RTR("Fog Volumes need volumetric fog to be enabled in the scene's Environment in order to be visible."));
|
2021-10-03 13:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return warnings;
|
|
|
|
}
|
|
|
|
|
|
|
|
FogVolume::FogVolume() {
|
|
|
|
volume = RS::get_singleton()->fog_volume_create();
|
|
|
|
RS::get_singleton()->fog_volume_set_shape(volume, RS::FOG_VOLUME_SHAPE_BOX);
|
|
|
|
set_base(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
FogVolume::~FogVolume() {
|
2022-12-12 18:42:37 +01:00
|
|
|
ERR_FAIL_NULL(RenderingServer::get_singleton());
|
2021-10-03 13:28:55 +02:00
|
|
|
RS::get_singleton()->free(volume);
|
|
|
|
}
|