| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/3d/visual_instance_3d.h" |
| 34 |
|
| 35 |
class CameraAttributes; |
| 36 |
|
| 37 |
class VoxelGIData : public Resource { |
| 38 |
GDCLASS(VoxelGIData, Resource); |
| 39 |
|
| 40 |
RID probe; |
| 41 |
|
| 42 |
void _set_data(const Dictionary &p_data); |
| 43 |
Dictionary _get_data() const; |
| 44 |
|
| 45 |
Transform3D to_cell_xform; |
| 46 |
AABB bounds; |
| 47 |
Vector3 octree_size; |
| 48 |
|
| 49 |
float dynamic_range = 2.0; |
| 50 |
float energy = 1.0; |
| 51 |
float bias = 1.5; |
| 52 |
float normal_bias = 0.0; |
| 53 |
float propagation = 0.5; |
| 54 |
bool interior = false; |
| 55 |
bool use_two_bounces = true; |
| 56 |
|
| 57 |
protected: |
| 58 |
static void _bind_methods(); |
| 59 |
|
| 60 |
public: |
| 61 |
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); |
| 62 |
AABB get_bounds() const; |
| 63 |
Vector3 get_octree_size() const; |
| 64 |
Vector<uint8_t> get_octree_cells() const; |
| 65 |
Vector<uint8_t> get_data_cells() const; |
| 66 |
Vector<uint8_t> get_distance_field() const; |
| 67 |
Vector<int> get_level_counts() const; |
| 68 |
Transform3D get_to_cell_xform() const; |
| 69 |
|
| 70 |
void set_dynamic_range(float p_range); |
| 71 |
float get_dynamic_range() const; |
| 72 |
|
| 73 |
void set_propagation(float p_propagation); |
| 74 |
float get_propagation() const; |
| 75 |
|
| 76 |
void set_energy(float p_energy); |
| 77 |
float get_energy() const; |
| 78 |
|
| 79 |
void set_bias(float p_bias); |
| 80 |
float get_bias() const; |
| 81 |
|
| 82 |
void set_normal_bias(float p_normal_bias); |
| 83 |
float get_normal_bias() const; |
| 84 |
|
| 85 |
void set_interior(bool p_enable); |
| 86 |
bool is_interior() const; |
| 87 |
|
| 88 |
void set_use_two_bounces(bool p_enable); |
| 89 |
bool is_using_two_bounces() const; |
| 90 |
|
| 91 |
virtual RID get_rid() const override; |
| 92 |
|
| 93 |
VoxelGIData(); |
| 94 |
~VoxelGIData(); |
| 95 |
}; |
| 96 |
|
| 97 |
class VoxelGI : public VisualInstance3D { |
| 98 |
GDCLASS(VoxelGI, VisualInstance3D); |
| 99 |
|
| 100 |
public: |
| 101 |
enum Subdiv { |
| 102 |
SUBDIV_64, |
| 103 |
SUBDIV_128, |
| 104 |
SUBDIV_256, |
| 105 |
SUBDIV_512, |
| 106 |
SUBDIV_MAX |
| 107 |
|
| 108 |
}; |
| 109 |
|
| 110 |
typedef void (*BakeBeginFunc)(); |
| 111 |
typedef bool (*BakeStepFunc)(int, const String &); |
| 112 |
typedef void (*BakeEndFunc)(); |
| 113 |
|
| 114 |
private: |
| 115 |
Ref<VoxelGIData> probe_data; |
| 116 |
|
| 117 |
RID voxel_gi; |
| 118 |
|
| 119 |
Subdiv subdiv = SUBDIV_128; |
| 120 |
Vector3 size = Vector3(20, 20, 20); |
| 121 |
Ref<CameraAttributes> camera_attributes; |
| 122 |
|
| 123 |
struct PlotMesh { |
| 124 |
Ref<Material> override_material; |
| 125 |
Vector<Ref<Material>> instance_materials; |
| 126 |
Ref<Mesh> mesh; |
| 127 |
Transform3D local_xform; |
| 128 |
}; |
| 129 |
|
| 130 |
void _find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes); |
| 131 |
void _debug_bake(); |
| 132 |
|
| 133 |
float _get_camera_exposure_normalization(); |
| 134 |
|
| 135 |
protected: |
| 136 |
static void _bind_methods(); |
| 137 |
#ifndef DISABLE_DEPRECATED |
| 138 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 139 |
bool _get(const StringName &p_name, Variant &r_property) const; |
| 140 |
#endif |
| 141 |
|
| 142 |
public: |
| 143 |
static BakeBeginFunc bake_begin_function; |
| 144 |
static BakeStepFunc bake_step_function; |
| 145 |
static BakeEndFunc bake_end_function; |
| 146 |
|
| 147 |
void set_probe_data(const Ref<VoxelGIData> &p_data); |
| 148 |
Ref<VoxelGIData> get_probe_data() const; |
| 149 |
|
| 150 |
void set_subdiv(Subdiv p_subdiv); |
| 151 |
Subdiv get_subdiv() const; |
| 152 |
|
| 153 |
void set_size(const Vector3 &p_size); |
| 154 |
Vector3 get_size() const; |
| 155 |
|
| 156 |
void set_camera_attributes(const Ref<CameraAttributes> &p_camera_attributes); |
| 157 |
Ref<CameraAttributes> get_camera_attributes() const; |
| 158 |
|
| 159 |
Vector3i get_estimated_cell_size() const; |
| 160 |
|
| 161 |
void bake(Node *p_from_node = nullptr, bool p_create_visual_debug = false); |
| 162 |
|
| 163 |
virtual AABB get_aabb() const override; |
| 164 |
|
| 165 |
PackedStringArray get_configuration_warnings() const override; |
| 166 |
|
| 167 |
VoxelGI(); |
| 168 |
~VoxelGI(); |
| 169 |
}; |
| 170 |
|
| 171 |
VARIANT_ENUM_CAST(VoxelGI::Subdiv) |