| 
									
										
										
										
											2023-01-05 13:25:55 +01:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*  voxel_gi.h                                                            */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*                         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.                 */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | #ifndef VOXEL_GI_H
 | 
					
						
							|  |  |  | #define VOXEL_GI_H
 | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | #include "scene/3d/visual_instance_3d.h"
 | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-31 16:20:24 -07:00
										 |  |  | class CameraAttributes; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | class VoxelGIData : public Resource { | 
					
						
							|  |  |  | 	GDCLASS(VoxelGIData, Resource); | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RID probe; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void _set_data(const Dictionary &p_data); | 
					
						
							|  |  |  | 	Dictionary _get_data() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	Transform3D to_cell_xform; | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	AABB bounds; | 
					
						
							|  |  |  | 	Vector3 octree_size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-26 00:50:17 +01:00
										 |  |  | 	float dynamic_range = 2.0; | 
					
						
							| 
									
										
										
										
											2021-02-07 22:29:31 +01:00
										 |  |  | 	float energy = 1.0; | 
					
						
							|  |  |  | 	float bias = 1.5; | 
					
						
							|  |  |  | 	float normal_bias = 0.0; | 
					
						
							| 
									
										
										
										
											2021-12-05 21:28:03 +01:00
										 |  |  | 	float propagation = 0.5; | 
					
						
							| 
									
										
										
										
											2021-02-07 22:29:31 +01:00
										 |  |  | 	bool interior = false; | 
					
						
							| 
									
										
										
										
											2021-12-05 21:28:03 +01:00
										 |  |  | 	bool use_two_bounces = true; | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-23 00:37:38 -03:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	void allocate(const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3 &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts); | 
					
						
							| 
									
										
										
										
											2017-11-16 21:09:00 -05:00
										 |  |  | 	AABB get_bounds() const; | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	Vector3 get_octree_size() const; | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector<uint8_t> get_octree_cells() const; | 
					
						
							|  |  |  | 	Vector<uint8_t> get_data_cells() const; | 
					
						
							|  |  |  | 	Vector<uint8_t> get_distance_field() const; | 
					
						
							|  |  |  | 	Vector<int> get_level_counts() const; | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	Transform3D get_to_cell_xform() const; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void set_dynamic_range(float p_range); | 
					
						
							|  |  |  | 	float get_dynamic_range() const; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void set_propagation(float p_propagation); | 
					
						
							| 
									
										
										
										
											2017-02-06 05:12:15 -03:00
										 |  |  | 	float get_propagation() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void set_energy(float p_energy); | 
					
						
							| 
									
										
										
										
											2016-12-22 10:00:15 -03:00
										 |  |  | 	float get_energy() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void set_bias(float p_bias); | 
					
						
							| 
									
										
										
										
											2017-02-16 08:55:11 -03:00
										 |  |  | 	float get_bias() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void set_normal_bias(float p_normal_bias); | 
					
						
							| 
									
										
										
										
											2017-07-15 23:24:37 -03:00
										 |  |  | 	float get_normal_bias() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 10:00:15 -03:00
										 |  |  | 	void set_interior(bool p_enable); | 
					
						
							|  |  |  | 	bool is_interior() const; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-03 17:39:08 -03:00
										 |  |  | 	void set_use_two_bounces(bool p_enable); | 
					
						
							|  |  |  | 	bool is_using_two_bounces() const; | 
					
						
							| 
									
										
										
										
											2016-12-31 10:53:29 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-10 11:34:39 +01:00
										 |  |  | 	virtual RID get_rid() const override; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | 	VoxelGIData(); | 
					
						
							|  |  |  | 	~VoxelGIData(); | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | class VoxelGI : public VisualInstance3D { | 
					
						
							|  |  |  | 	GDCLASS(VoxelGI, VisualInstance3D); | 
					
						
							| 
									
										
										
										
											2016-12-23 00:37:38 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	enum Subdiv { | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 		SUBDIV_64, | 
					
						
							|  |  |  | 		SUBDIV_128, | 
					
						
							|  |  |  | 		SUBDIV_256, | 
					
						
							|  |  |  | 		SUBDIV_512, | 
					
						
							|  |  |  | 		SUBDIV_MAX | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-22 21:10:07 +02:00
										 |  |  | 	typedef void (*BakeBeginFunc)(); | 
					
						
							|  |  |  | 	typedef bool (*BakeStepFunc)(int, const String &); | 
					
						
							| 
									
										
										
										
											2017-10-30 16:33:07 -03:00
										 |  |  | 	typedef void (*BakeEndFunc)(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | 	Ref<VoxelGIData> probe_data; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | 	RID voxel_gi; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-07 22:29:31 +01:00
										 |  |  | 	Subdiv subdiv = SUBDIV_128; | 
					
						
							| 
									
										
										
										
											2022-07-12 08:43:01 +01:00
										 |  |  | 	Vector3 size = Vector3(20, 20, 20); | 
					
						
							| 
									
										
										
										
											2022-07-31 16:20:24 -07:00
										 |  |  | 	Ref<CameraAttributes> camera_attributes; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 08:59:46 -03:00
										 |  |  | 	struct PlotMesh { | 
					
						
							|  |  |  | 		Ref<Material> override_material; | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 		Vector<Ref<Material>> instance_materials; | 
					
						
							| 
									
										
										
										
											2017-12-14 08:59:46 -03:00
										 |  |  | 		Ref<Mesh> mesh; | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 		Transform3D local_xform; | 
					
						
							| 
									
										
										
										
											2017-12-14 08:59:46 -03:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 08:59:46 -03:00
										 |  |  | 	void _find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes); | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 	void _debug_bake(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 13:19:07 +03:00
										 |  |  | 	float _get_camera_exposure_normalization(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							| 
									
										
										
										
											2022-07-12 08:43:01 +01:00
										 |  |  | #ifndef DISABLE_DEPRECATED
 | 
					
						
							|  |  |  | 	bool _set(const StringName &p_name, const Variant &p_value); | 
					
						
							|  |  |  | 	bool _get(const StringName &p_name, Variant &r_property) const; | 
					
						
							|  |  |  | #endif // DISABLE_DEPRECATED
 | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-10-30 16:33:07 -03:00
										 |  |  | 	static BakeBeginFunc bake_begin_function; | 
					
						
							|  |  |  | 	static BakeStepFunc bake_step_function; | 
					
						
							|  |  |  | 	static BakeEndFunc bake_end_function; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | 	void set_probe_data(const Ref<VoxelGIData> &p_data); | 
					
						
							|  |  |  | 	Ref<VoxelGIData> get_probe_data() const; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void set_subdiv(Subdiv p_subdiv); | 
					
						
							|  |  |  | 	Subdiv get_subdiv() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-12 08:43:01 +01:00
										 |  |  | 	void set_size(const Vector3 &p_size); | 
					
						
							|  |  |  | 	Vector3 get_size() const; | 
					
						
							| 
									
										
										
										
											2022-07-31 16:20:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void set_camera_attributes(const Ref<CameraAttributes> &p_camera_attributes); | 
					
						
							|  |  |  | 	Ref<CameraAttributes> get_camera_attributes() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 19:54:21 -03:00
										 |  |  | 	Vector3i get_estimated_cell_size() const; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	void bake(Node *p_from_node = nullptr, bool p_create_visual_debug = false); | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-10 11:34:39 +01:00
										 |  |  | 	virtual AABB get_aabb() const override; | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-17 19:03:21 +01:00
										 |  |  | 	PackedStringArray get_configuration_warnings() const override; | 
					
						
							| 
									
										
										
										
											2019-03-02 15:45:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | 	VoxelGI(); | 
					
						
							|  |  |  | 	~VoxelGI(); | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | VARIANT_ENUM_CAST(VoxelGI::Subdiv) | 
					
						
							| 
									
										
										
										
											2016-12-20 00:21:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 19:47:26 -03:00
										 |  |  | #endif // VOXEL_GI_H
 |