2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* reflection_probe.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-03-05 15:47:28 +01: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. */
|
|
|
|
/*************************************************************************/
|
2016-11-19 17:23:37 +01:00
|
|
|
#include "reflection_probe.h"
|
|
|
|
|
|
|
|
void ReflectionProbe::set_intensity(float p_intensity) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
intensity = p_intensity;
|
|
|
|
VS::get_singleton()->reflection_probe_set_intensity(probe, p_intensity);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float ReflectionProbe::get_intensity() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return intensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_interior_ambient(Color p_ambient) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
interior_ambient = p_ambient;
|
|
|
|
VS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_interior_ambient_energy(float p_energy) {
|
2017-03-05 16:44:50 +01:00
|
|
|
interior_ambient_energy = p_energy;
|
|
|
|
VS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float ReflectionProbe::get_interior_ambient_energy() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
return interior_ambient_energy;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Color ReflectionProbe::get_interior_ambient() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return interior_ambient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_interior_ambient_probe_contribution(float p_contribution) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
interior_ambient_probe_contribution = p_contribution;
|
|
|
|
VS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float ReflectionProbe::get_interior_ambient_probe_contribution() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return interior_ambient_probe_contribution;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ReflectionProbe::set_max_distance(float p_distance) {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
max_distance = p_distance;
|
|
|
|
VS::get_singleton()->reflection_probe_set_max_distance(probe, p_distance);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
float ReflectionProbe::get_max_distance() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return max_distance;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ReflectionProbe::set_extents(const Vector3 &p_extents) {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
extents = p_extents;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (extents[i] < 0.01) {
|
|
|
|
extents[i] = 0.01;
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (extents[i] - 0.01 < ABS(origin_offset[i])) {
|
|
|
|
origin_offset[i] = SGN(origin_offset[i]) * (extents[i] - 0.01);
|
2016-11-19 17:23:37 +01:00
|
|
|
_change_notify("origin_offset");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VS::get_singleton()->reflection_probe_set_extents(probe, extents);
|
|
|
|
VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
|
2016-11-19 17:23:37 +01:00
|
|
|
_change_notify("extents");
|
|
|
|
update_gizmo();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ReflectionProbe::get_extents() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ReflectionProbe::set_origin_offset(const Vector3 &p_extents) {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
origin_offset = p_extents;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (extents[i] - 0.01 < ABS(origin_offset[i])) {
|
|
|
|
origin_offset[i] = SGN(origin_offset[i]) * (extents[i] - 0.01);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
VS::get_singleton()->reflection_probe_set_extents(probe, extents);
|
|
|
|
VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
_change_notify("origin_offset");
|
|
|
|
update_gizmo();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ReflectionProbe::get_origin_offset() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return origin_offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ReflectionProbe::set_enable_box_projection(bool p_enable) {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
box_projection = p_enable;
|
|
|
|
VS::get_singleton()->reflection_probe_set_enable_box_projection(probe, p_enable);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ReflectionProbe::is_box_projection_enabled() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
|
|
|
return box_projection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_as_interior(bool p_enable) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
interior = p_enable;
|
|
|
|
VS::get_singleton()->reflection_probe_set_as_interior(probe, interior);
|
2016-11-19 17:23:37 +01:00
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReflectionProbe::is_set_as_interior() const {
|
|
|
|
|
|
|
|
return interior;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_enable_shadows(bool p_enable) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
enable_shadows = p_enable;
|
|
|
|
VS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_enable);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
bool ReflectionProbe::are_shadows_enabled() const {
|
|
|
|
|
|
|
|
return enable_shadows;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_cull_mask(uint32_t p_layers) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cull_mask = p_layers;
|
2017-07-15 23:40:47 +02:00
|
|
|
VS::get_singleton()->reflection_probe_set_cull_mask(probe, p_layers);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
uint32_t ReflectionProbe::get_cull_mask() const {
|
|
|
|
|
|
|
|
return cull_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::set_update_mode(UpdateMode p_mode) {
|
2017-03-05 16:44:50 +01:00
|
|
|
update_mode = p_mode;
|
|
|
|
VS::get_singleton()->reflection_probe_set_update_mode(probe, VS::ReflectionProbeUpdateMode(p_mode));
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReflectionProbe::UpdateMode ReflectionProbe::get_update_mode() const {
|
|
|
|
return update_mode;
|
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 ReflectionProbe::get_aabb() const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 aabb;
|
2017-06-06 20:33:51 +02:00
|
|
|
aabb.position = -origin_offset;
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb.size = origin_offset + extents;
|
2016-11-19 17:23:37 +01:00
|
|
|
return aabb;
|
|
|
|
}
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Face3> ReflectionProbe::get_faces(uint32_t p_usage_flags) const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
return PoolVector<Face3>();
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ReflectionProbe::_validate_property(PropertyInfo &property) const {
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (property.name == "interior/ambient_color" || property.name == "interior/ambient_energy" || property.name == "interior/ambient_contrib") {
|
2016-11-19 17:23:37 +01:00
|
|
|
if (!interior) {
|
2017-03-05 16:44:50 +01:00
|
|
|
property.usage = PROPERTY_USAGE_NOEDITOR;
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReflectionProbe::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &ReflectionProbe::set_intensity);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_intensity"), &ReflectionProbe::get_intensity);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_extents", "extents"), &ReflectionProbe::set_extents);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_extents"), &ReflectionProbe::get_extents);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_origin_offset", "origin_offset"), &ReflectionProbe::set_origin_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_origin_offset"), &ReflectionProbe::get_origin_offset);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_as_interior", "enable"), &ReflectionProbe::set_as_interior);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_set_as_interior"), &ReflectionProbe::is_set_as_interior);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_enable_box_projection", "enable"), &ReflectionProbe::set_enable_box_projection);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_box_projection_enabled"), &ReflectionProbe::is_box_projection_enabled);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_enable_shadows", "enable"), &ReflectionProbe::set_enable_shadows);
|
|
|
|
ClassDB::bind_method(D_METHOD("are_shadows_enabled"), &ReflectionProbe::are_shadows_enabled);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_cull_mask", "layers"), &ReflectionProbe::set_cull_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cull_mask"), &ReflectionProbe::get_cull_mask);
|
2017-01-04 05:16:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &ReflectionProbe::set_update_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_update_mode"), &ReflectionProbe::get_update_mode);
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Once,Always"), "set_update_mode", "get_update_mode");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "intensity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_intensity", "get_intensity");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,16384,0.1"), "set_max_distance", "get_max_distance");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "extents"), "set_extents", "get_extents");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "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, "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");
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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::REAL, "interior_ambient_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_interior_ambient_energy", "get_interior_ambient_energy");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "interior_ambient_contrib", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_interior_ambient_probe_contribution", "get_interior_ambient_probe_contribution");
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(UPDATE_ONCE);
|
|
|
|
BIND_ENUM_CONSTANT(UPDATE_ALWAYS);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReflectionProbe::ReflectionProbe() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
intensity = 1.0;
|
|
|
|
interior_ambient = Color(0, 0, 0);
|
|
|
|
interior_ambient_probe_contribution = 0;
|
|
|
|
interior_ambient_energy = 1.0;
|
|
|
|
max_distance = 0;
|
|
|
|
extents = Vector3(1, 1, 1);
|
|
|
|
origin_offset = Vector3(0, 0, 0);
|
|
|
|
box_projection = false;
|
|
|
|
interior = false;
|
|
|
|
enable_shadows = false;
|
|
|
|
cull_mask = (1 << 20) - 1;
|
|
|
|
update_mode = UPDATE_ONCE;
|
|
|
|
|
|
|
|
probe = VisualServer::get_singleton()->reflection_probe_create();
|
|
|
|
VS::get_singleton()->instance_set_base(get_instance(), probe);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReflectionProbe::~ReflectionProbe() {
|
|
|
|
|
|
|
|
VS::get_singleton()->free(probe);
|
|
|
|
}
|