2017-03-05 22:47:28 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* gi_probe.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 22:47:28 +08:00
|
|
|
/*************************************************************************/
|
2019-01-01 19:53:14 +08:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-03-05 22:47:28 +08:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2016-12-20 11:21:07 +08:00
|
|
|
#include "gi_probe.h"
|
2017-03-05 22:47:28 +08:00
|
|
|
|
2019-03-03 07:45:14 +08:00
|
|
|
#include "core/os/os.h"
|
|
|
|
|
2016-12-20 11:21:07 +08:00
|
|
|
#include "mesh_instance.h"
|
2017-12-14 19:59:46 +08:00
|
|
|
#include "voxel_light_baker.h"
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
void GIProbeData::set_bounds(const AABB &p_bounds) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_bounds(probe, p_bounds);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
AABB GIProbeData::get_bounds() const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_bounds(probe);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GIProbeData::set_cell_size(float p_size) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_cell_size(probe, p_size);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float GIProbeData::get_cell_size() const {
|
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_cell_size(probe);
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void GIProbeData::set_to_cell_xform(const Transform &p_xform) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_to_cell_xform(probe, p_xform);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Transform GIProbeData::get_to_cell_xform() const {
|
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_to_cell_xform(probe);
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void GIProbeData::set_dynamic_data(const PoolVector<int> &p_data) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_dynamic_data(probe, p_data);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
2017-03-05 23:44:50 +08:00
|
|
|
PoolVector<int> GIProbeData::get_dynamic_data() const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_dynamic_data(probe);
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void GIProbeData::set_dynamic_range(int p_range) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
2016-12-22 21:00:15 +08:00
|
|
|
|
|
|
|
void GIProbeData::set_energy(float p_range) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_energy(probe, p_range);
|
2016-12-22 21:00:15 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
float GIProbeData::get_energy() const {
|
2016-12-22 21:00:15 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_energy(probe);
|
|
|
|
}
|
|
|
|
|
2017-02-16 19:55:11 +08:00
|
|
|
void GIProbeData::set_bias(float p_range) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_bias(probe, p_range);
|
2017-02-16 19:55:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
float GIProbeData::get_bias() const {
|
2017-02-16 19:55:11 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_bias(probe);
|
|
|
|
}
|
|
|
|
|
2017-07-16 10:24:37 +08:00
|
|
|
void GIProbeData::set_normal_bias(float p_range) {
|
|
|
|
|
|
|
|
VS::get_singleton()->gi_probe_set_normal_bias(probe, p_range);
|
|
|
|
}
|
|
|
|
|
|
|
|
float GIProbeData::get_normal_bias() const {
|
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_normal_bias(probe);
|
|
|
|
}
|
|
|
|
|
2017-02-06 16:12:15 +08:00
|
|
|
void GIProbeData::set_propagation(float p_range) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_propagation(probe, p_range);
|
2017-02-06 16:12:15 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
float GIProbeData::get_propagation() const {
|
2017-02-06 16:12:15 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_propagation(probe);
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:00:15 +08:00
|
|
|
void GIProbeData::set_interior(bool p_enable) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_interior(probe, p_enable);
|
2016-12-22 21:00:15 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool GIProbeData::is_interior() const {
|
2016-12-22 21:00:15 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_is_interior(probe);
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool GIProbeData::is_compressed() const {
|
2016-12-31 21:53:29 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_is_compressed(probe);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GIProbeData::set_compress(bool p_enable) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->gi_probe_set_compress(probe, p_enable);
|
2016-12-31 21:53:29 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
int GIProbeData::get_dynamic_range() const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
return VS::get_singleton()->gi_probe_get_dynamic_range(probe);
|
|
|
|
}
|
|
|
|
|
2016-12-23 11:37:38 +08:00
|
|
|
RID GIProbeData::get_rid() const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2016-12-23 11:37:38 +08:00
|
|
|
return probe;
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
2016-12-23 11:37:38 +08:00
|
|
|
void GIProbeData::_bind_methods() {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bounds", "bounds"), &GIProbeData::set_bounds);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bounds"), &GIProbeData::get_bounds);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &GIProbeData::set_cell_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cell_size"), &GIProbeData::get_cell_size);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_to_cell_xform", "to_cell_xform"), &GIProbeData::set_to_cell_xform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_to_cell_xform"), &GIProbeData::get_to_cell_xform);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_dynamic_data", "dynamic_data"), &GIProbeData::set_dynamic_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_dynamic_data"), &GIProbeData::get_dynamic_data);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_dynamic_range", "dynamic_range"), &GIProbeData::set_dynamic_range);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_dynamic_range"), &GIProbeData::get_dynamic_range);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_energy", "energy"), &GIProbeData::set_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_energy"), &GIProbeData::get_energy);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bias", "bias"), &GIProbeData::set_bias);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bias"), &GIProbeData::get_bias);
|
2017-02-16 19:55:11 +08:00
|
|
|
|
2017-07-16 10:24:37 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_normal_bias", "bias"), &GIProbeData::set_normal_bias);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_normal_bias"), &GIProbeData::get_normal_bias);
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &GIProbeData::set_propagation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbeData::get_propagation);
|
2017-02-06 16:12:15 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_interior", "interior"), &GIProbeData::set_interior);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_interior"), &GIProbeData::is_interior);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_compress", "compress"), &GIProbeData::set_compress);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_compressed"), &GIProbeData::is_compressed);
|
2016-12-31 21:53:29 +08:00
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::AABB, "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bounds", "get_bounds");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_size", "get_cell_size");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "to_cell_xform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_to_cell_xform", "get_to_cell_xform");
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "dynamic_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_dynamic_data", "get_dynamic_data");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_dynamic_range", "get_dynamic_range");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_energy", "get_energy");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bias", "get_bias");
|
2017-07-16 10:24:37 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "normal_bias", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_normal_bias", "get_normal_bias");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_propagation", "get_propagation");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_interior", "is_interior");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_compress", "is_compressed");
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GIProbeData::GIProbeData() {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
probe = VS::get_singleton()->gi_probe_create();
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GIProbeData::~GIProbeData() {
|
|
|
|
|
|
|
|
VS::get_singleton()->free(probe);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
//////////////////////
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void GIProbe::set_probe_data(const Ref<GIProbeData> &p_data) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
if (p_data.is_valid()) {
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid());
|
2016-12-20 11:21:07 +08:00
|
|
|
} else {
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->instance_set_base(get_instance(), RID());
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
probe_data = p_data;
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<GIProbeData> GIProbe::get_probe_data() const {
|
|
|
|
|
|
|
|
return probe_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GIProbe::set_subdiv(Subdiv p_subdiv) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ERR_FAIL_INDEX(p_subdiv, SUBDIV_MAX);
|
|
|
|
subdiv = p_subdiv;
|
2016-12-20 11:21:07 +08:00
|
|
|
update_gizmo();
|
|
|
|
}
|
|
|
|
|
|
|
|
GIProbe::Subdiv GIProbe::get_subdiv() const {
|
|
|
|
|
|
|
|
return subdiv;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void GIProbe::set_extents(const Vector3 &p_extents) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
extents = p_extents;
|
2016-12-20 11:21:07 +08:00
|
|
|
update_gizmo();
|
2019-07-11 02:06:59 +08:00
|
|
|
_change_notify("extents");
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 GIProbe::get_extents() const {
|
|
|
|
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:00:15 +08:00
|
|
|
void GIProbe::set_dynamic_range(int p_dynamic_range) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
dynamic_range = p_dynamic_range;
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
2016-12-22 21:00:15 +08:00
|
|
|
int GIProbe::get_dynamic_range() const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
return dynamic_range;
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:00:15 +08:00
|
|
|
void GIProbe::set_energy(float p_energy) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
energy = p_energy;
|
2016-12-22 21:00:15 +08:00
|
|
|
if (probe_data.is_valid()) {
|
|
|
|
probe_data->set_energy(energy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float GIProbe::get_energy() const {
|
|
|
|
|
|
|
|
return energy;
|
|
|
|
}
|
|
|
|
|
2017-02-16 19:55:11 +08:00
|
|
|
void GIProbe::set_bias(float p_bias) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bias = p_bias;
|
2017-02-16 19:55:11 +08:00
|
|
|
if (probe_data.is_valid()) {
|
|
|
|
probe_data->set_bias(bias);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float GIProbe::get_bias() const {
|
|
|
|
|
|
|
|
return bias;
|
|
|
|
}
|
|
|
|
|
2017-07-16 10:24:37 +08:00
|
|
|
void GIProbe::set_normal_bias(float p_normal_bias) {
|
|
|
|
|
|
|
|
normal_bias = p_normal_bias;
|
|
|
|
if (probe_data.is_valid()) {
|
|
|
|
probe_data->set_normal_bias(normal_bias);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float GIProbe::get_normal_bias() const {
|
|
|
|
|
|
|
|
return normal_bias;
|
|
|
|
}
|
|
|
|
|
2017-02-06 16:12:15 +08:00
|
|
|
void GIProbe::set_propagation(float p_propagation) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
propagation = p_propagation;
|
2017-02-06 16:12:15 +08:00
|
|
|
if (probe_data.is_valid()) {
|
|
|
|
probe_data->set_propagation(propagation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float GIProbe::get_propagation() const {
|
|
|
|
|
|
|
|
return propagation;
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:00:15 +08:00
|
|
|
void GIProbe::set_interior(bool p_enable) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
interior = p_enable;
|
2016-12-22 21:00:15 +08:00
|
|
|
if (probe_data.is_valid()) {
|
|
|
|
probe_data->set_interior(p_enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GIProbe::is_interior() const {
|
|
|
|
|
|
|
|
return interior;
|
|
|
|
}
|
|
|
|
|
2016-12-31 21:53:29 +08:00
|
|
|
void GIProbe::set_compress(bool p_enable) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
compress = p_enable;
|
2016-12-31 21:53:29 +08:00
|
|
|
if (probe_data.is_valid()) {
|
|
|
|
probe_data->set_compress(p_enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GIProbe::is_compressed() const {
|
|
|
|
|
|
|
|
return compress;
|
|
|
|
}
|
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-08-25 04:58:51 +08:00
|
|
|
MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node);
|
2017-09-07 05:24:29 +08:00
|
|
|
if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) {
|
2017-07-29 11:03:54 +08:00
|
|
|
Ref<Mesh> mesh = mi->get_mesh();
|
2016-12-20 11:21:07 +08:00
|
|
|
if (mesh.is_valid()) {
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
AABB aabb = mesh->get_aabb();
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
|
2017-12-14 19:59:46 +08:00
|
|
|
PlotMesh pm;
|
2017-03-05 23:44:50 +08:00
|
|
|
pm.local_xform = xf;
|
|
|
|
pm.mesh = mesh;
|
|
|
|
for (int i = 0; i < mesh->get_surface_count(); i++) {
|
2017-02-06 11:38:39 +08:00
|
|
|
pm.instance_materials.push_back(mi->get_surface_material(i));
|
|
|
|
}
|
2017-03-05 23:44:50 +08:00
|
|
|
pm.override_material = mi->get_material_override();
|
2017-12-14 19:59:46 +08:00
|
|
|
plot_meshes.push_back(pm);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 05:50:18 +08:00
|
|
|
Spatial *s = Object::cast_to<Spatial>(p_at_node);
|
|
|
|
if (s) {
|
2017-02-15 19:29:46 +08:00
|
|
|
|
2017-09-07 05:24:29 +08:00
|
|
|
if (s->is_visible_in_tree()) {
|
2017-02-15 19:29:46 +08:00
|
|
|
|
2017-09-07 05:24:29 +08:00
|
|
|
Array meshes = p_at_node->call("get_meshes");
|
|
|
|
for (int i = 0; i < meshes.size(); i += 2) {
|
2017-02-15 19:29:46 +08:00
|
|
|
|
2017-09-07 05:24:29 +08:00
|
|
|
Transform mxf = meshes[i];
|
|
|
|
Ref<Mesh> mesh = meshes[i + 1];
|
|
|
|
if (!mesh.is_valid())
|
|
|
|
continue;
|
2017-02-15 19:29:46 +08:00
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
AABB aabb = mesh->get_aabb();
|
2017-02-15 19:29:46 +08:00
|
|
|
|
2017-09-07 05:24:29 +08:00
|
|
|
Transform xf = get_global_transform().affine_inverse() * (s->get_global_transform() * mxf);
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
|
2017-12-14 19:59:46 +08:00
|
|
|
PlotMesh pm;
|
2017-09-07 05:24:29 +08:00
|
|
|
pm.local_xform = xf;
|
|
|
|
pm.mesh = mesh;
|
2017-12-14 19:59:46 +08:00
|
|
|
plot_meshes.push_back(pm);
|
2017-09-07 05:24:29 +08:00
|
|
|
}
|
2017-02-15 19:29:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
for (int i = 0; i < p_at_node->get_child_count(); i++) {
|
2016-12-20 11:21:07 +08:00
|
|
|
Node *child = p_at_node->get_child(i);
|
2017-12-14 19:59:46 +08:00
|
|
|
_find_meshes(child, plot_meshes);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 03:33:07 +08:00
|
|
|
GIProbe::BakeBeginFunc GIProbe::bake_begin_function = NULL;
|
|
|
|
GIProbe::BakeStepFunc GIProbe::bake_step_function = NULL;
|
|
|
|
GIProbe::BakeEndFunc GIProbe::bake_end_function = NULL;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
static const int subdiv_value[SUBDIV_MAX] = { 7, 8, 9, 10 };
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
VoxelLightBaker baker;
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
baker.begin_bake(subdiv_value[subdiv], AABB(-extents, extents * 2.0));
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
List<PlotMesh> mesh_list;
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
_find_meshes(p_from_node ? p_from_node : get_parent(), mesh_list);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-10-31 03:33:07 +08:00
|
|
|
if (bake_begin_function) {
|
2017-12-14 19:59:46 +08:00
|
|
|
bake_begin_function(mesh_list.size() + 1);
|
2017-10-31 03:33:07 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
int pmc = 0;
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-10-31 03:33:07 +08:00
|
|
|
if (bake_step_function) {
|
2017-12-14 19:59:46 +08:00
|
|
|
bake_step_function(pmc, RTR("Plotting Meshes") + " " + itos(pmc) + "/" + itos(mesh_list.size()));
|
2017-10-31 03:33:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pmc++;
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
baker.plot_mesh(E->get().local_xform, E->get().mesh, E->get().instance_materials, E->get().override_material);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
2017-10-31 03:33:07 +08:00
|
|
|
if (bake_step_function) {
|
|
|
|
bake_step_function(pmc++, RTR("Finishing Plot"));
|
|
|
|
}
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
baker.end_bake();
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
//create the data for visual server
|
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
PoolVector<int> data = baker.create_gi_probe_data();
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-14 19:59:46 +08:00
|
|
|
if (p_create_visual_debug) {
|
|
|
|
MultiMeshInstance *mmi = memnew(MultiMeshInstance);
|
|
|
|
mmi->set_multimesh(baker.create_debug_multimesh());
|
|
|
|
add_child(mmi);
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (get_tree()->get_edited_scene_root() == this) {
|
|
|
|
mmi->set_owner(this);
|
|
|
|
} else {
|
|
|
|
mmi->set_owner(get_owner());
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
2017-12-14 19:59:46 +08:00
|
|
|
#else
|
|
|
|
mmi->set_owner(get_owner());
|
|
|
|
#endif
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-02-16 19:55:11 +08:00
|
|
|
} else {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-12-10 01:48:02 +08:00
|
|
|
Ref<GIProbeData> probe_data = get_probe_data();
|
|
|
|
|
2017-12-10 08:27:02 +08:00
|
|
|
if (probe_data.is_null())
|
2017-12-10 01:48:02 +08:00
|
|
|
probe_data.instance();
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
probe_data->set_bounds(AABB(-extents, extents * 2.0));
|
2017-12-14 19:59:46 +08:00
|
|
|
probe_data->set_cell_size(baker.get_cell_size());
|
2017-02-16 19:55:11 +08:00
|
|
|
probe_data->set_dynamic_data(data);
|
|
|
|
probe_data->set_dynamic_range(dynamic_range);
|
|
|
|
probe_data->set_energy(energy);
|
|
|
|
probe_data->set_bias(bias);
|
2017-07-16 10:24:37 +08:00
|
|
|
probe_data->set_normal_bias(normal_bias);
|
2017-02-16 19:55:11 +08:00
|
|
|
probe_data->set_propagation(propagation);
|
|
|
|
probe_data->set_interior(interior);
|
|
|
|
probe_data->set_compress(compress);
|
2017-12-14 19:59:46 +08:00
|
|
|
probe_data->set_to_cell_xform(baker.get_to_cell_space_xform());
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-02-16 19:55:11 +08:00
|
|
|
set_probe_data(probe_data);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
2017-10-31 03:33:07 +08:00
|
|
|
|
|
|
|
if (bake_end_function) {
|
|
|
|
bake_end_function();
|
|
|
|
}
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GIProbe::_debug_bake() {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bake(NULL, true);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
AABB GIProbe::get_aabb() const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
return AABB(-extents, extents * 2);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
2017-01-08 05:25:37 +08:00
|
|
|
PoolVector<Face3> GIProbe::get_faces(uint32_t p_usage_flags) const {
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-01-08 05:25:37 +08:00
|
|
|
return PoolVector<Face3>();
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 07:45:14 +08:00
|
|
|
String GIProbe::get_configuration_warning() const {
|
|
|
|
|
|
|
|
if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) {
|
|
|
|
return TTR("GIProbes are not supported by the GLES2 video driver.\nUse a BakedLightmap instead.");
|
|
|
|
}
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2016-12-20 11:21:07 +08:00
|
|
|
void GIProbe::_bind_methods() {
|
|
|
|
|
2017-08-09 19:19:41 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_probe_data", "data"), &GIProbe::set_probe_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_probe_data"), &GIProbe::get_probe_data);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_subdiv", "subdiv"), &GIProbe::set_subdiv);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_subdiv"), &GIProbe::get_subdiv);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GIProbe::set_extents);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_extents"), &GIProbe::get_extents);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_dynamic_range", "max"), &GIProbe::set_dynamic_range);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_dynamic_range"), &GIProbe::get_dynamic_range);
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_energy", "max"), &GIProbe::set_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_energy"), &GIProbe::get_energy);
|
2016-12-22 21:00:15 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bias", "max"), &GIProbe::set_bias);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bias"), &GIProbe::get_bias);
|
2017-02-16 19:55:11 +08:00
|
|
|
|
2017-07-16 10:24:37 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_normal_bias", "max"), &GIProbe::set_normal_bias);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_normal_bias"), &GIProbe::get_normal_bias);
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_propagation", "max"), &GIProbe::set_propagation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbe::get_propagation);
|
2017-02-06 16:12:15 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_interior", "enable"), &GIProbe::set_interior);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_interior"), &GIProbe::is_interior);
|
2016-12-22 21:00:15 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_compress", "enable"), &GIProbe::set_compress);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_compressed"), &GIProbe::is_compressed);
|
2016-12-31 21:53:29 +08:00
|
|
|
|
2017-08-09 19:19:41 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("bake", "from_node", "create_visual_debug"), &GIProbe::bake, DEFVAL(Variant()), DEFVAL(false));
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("debug_bake"), &GIProbe::_debug_bake);
|
|
|
|
ClassDB::set_method_flags(get_class_static(), _scs_create("debug_bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
|
2017-02-12 08:11:37 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "subdiv", PROPERTY_HINT_ENUM, "64,128,256,512"), "set_subdiv", "get_subdiv");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_RANGE, "1,16,1"), "set_dynamic_range", "get_dynamic_range");
|
2019-06-17 05:47:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_energy", "get_energy");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_RANGE, "0,4,0.001"), "set_bias", "get_bias");
|
2017-07-16 10:24:37 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "normal_bias", PROPERTY_HINT_RANGE, "0,4,0.001"), "set_normal_bias", "get_normal_bias");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compress"), "set_compress", "is_compressed");
|
2018-01-12 02:50:33 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "GIProbeData", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_probe_data", "get_probe_data");
|
2016-12-20 11:21:07 +08:00
|
|
|
|
2017-08-20 23:45:01 +08:00
|
|
|
BIND_ENUM_CONSTANT(SUBDIV_64);
|
|
|
|
BIND_ENUM_CONSTANT(SUBDIV_128);
|
|
|
|
BIND_ENUM_CONSTANT(SUBDIV_256);
|
2017-10-22 02:58:02 +08:00
|
|
|
BIND_ENUM_CONSTANT(SUBDIV_512);
|
2017-08-20 23:45:01 +08:00
|
|
|
BIND_ENUM_CONSTANT(SUBDIV_MAX);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GIProbe::GIProbe() {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
subdiv = SUBDIV_128;
|
|
|
|
dynamic_range = 4;
|
|
|
|
energy = 1.0;
|
2017-10-04 20:31:51 +08:00
|
|
|
bias = 1.5;
|
|
|
|
normal_bias = 0.0;
|
2017-11-22 02:12:28 +08:00
|
|
|
propagation = 0.7;
|
2017-03-05 23:44:50 +08:00
|
|
|
extents = Vector3(10, 10, 10);
|
|
|
|
interior = false;
|
|
|
|
compress = false;
|
2016-12-20 11:21:07 +08:00
|
|
|
|
|
|
|
gi_probe = VS::get_singleton()->gi_probe_create();
|
2018-07-19 00:47:42 +08:00
|
|
|
set_disable_scale(true);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GIProbe::~GIProbe() {
|
2019-07-02 22:23:54 +08:00
|
|
|
VS::get_singleton()->free(gi_probe);
|
2016-12-20 11:21:07 +08:00
|
|
|
}
|