| 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 "core/object/ref_counted.h" |
| 34 |
|
| 35 |
class Image; |
| 36 |
|
| 37 |
class LightmapDenoiser : public RefCounted { |
| 38 |
GDCLASS(LightmapDenoiser, RefCounted) |
| 39 |
protected: |
| 40 |
static LightmapDenoiser *(*create_function)(); |
| 41 |
|
| 42 |
public: |
| 43 |
virtual Ref<Image> denoise_image(const Ref<Image> &p_image) = 0; |
| 44 |
static Ref<LightmapDenoiser> create(); |
| 45 |
}; |
| 46 |
|
| 47 |
class LightmapRaycaster : public RefCounted { |
| 48 |
GDCLASS(LightmapRaycaster, RefCounted) |
| 49 |
protected: |
| 50 |
static LightmapRaycaster *(*create_function)(); |
| 51 |
|
| 52 |
public: |
| 53 |
|
| 54 |
struct alignas(16) Ray { |
| 55 |
const static unsigned int INVALID_GEOMETRY_ID = ((unsigned int)-1); |
| 56 |
|
| 57 |
|
| 58 |
_FORCE_INLINE_ Ray() : |
| 59 |
geomID(INVALID_GEOMETRY_ID) {} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
_FORCE_INLINE_ Ray(const Vector3 &p_org, |
| 64 |
const Vector3 &p_dir, |
| 65 |
float p_tnear = 0.0f, |
| 66 |
float p_tfar = Math::INF) : |
| 67 |
org(p_org), |
| 68 |
tnear(p_tnear), |
| 69 |
dir(p_dir), |
| 70 |
time(0.0f), |
| 71 |
tfar(p_tfar), |
| 72 |
mask(-1), |
| 73 |
u(0.0), |
| 74 |
v(0.0), |
| 75 |
primID(INVALID_GEOMETRY_ID), |
| 76 |
geomID(INVALID_GEOMETRY_ID), |
| 77 |
instID(INVALID_GEOMETRY_ID) {} |
| 78 |
|
| 79 |
|
| 80 |
_FORCE_INLINE_ explicit operator bool() const { |
| 81 |
return geomID != INVALID_GEOMETRY_ID; |
| 82 |
} |
| 83 |
|
| 84 |
public: |
| 85 |
Vector3 org; |
| 86 |
float tnear; |
| 87 |
Vector3 dir; |
| 88 |
float time; |
| 89 |
float tfar; |
| 90 |
unsigned int mask; |
| 91 |
unsigned int id; |
| 92 |
unsigned int flags; |
| 93 |
|
| 94 |
Vector3 normal; |
| 95 |
float u; |
| 96 |
float v; |
| 97 |
unsigned int primID; |
| 98 |
unsigned int geomID; |
| 99 |
unsigned int instID; |
| 100 |
}; |
| 101 |
|
| 102 |
virtual bool intersect(Ray &p_ray) = 0; |
| 103 |
|
| 104 |
virtual void intersect(Vector<Ray> &r_rays) = 0; |
| 105 |
|
| 106 |
virtual void add_mesh(const Vector<Vector3> &p_vertices, const Vector<Vector3> &p_normals, const Vector<Vector2> &p_uv2s, unsigned int p_id) = 0; |
| 107 |
virtual void set_mesh_alpha_texture(Ref<Image> p_alpha_texture, unsigned int p_id) = 0; |
| 108 |
virtual void commit() = 0; |
| 109 |
|
| 110 |
virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) = 0; |
| 111 |
virtual void clear_mesh_filter() = 0; |
| 112 |
|
| 113 |
static Ref<LightmapRaycaster> create(); |
| 114 |
}; |
| 115 |
|
| 116 |
class Lightmapper : public RefCounted { |
| 117 |
GDCLASS(Lightmapper, RefCounted) |
| 118 |
public: |
| 119 |
enum GenerateProbes { |
| 120 |
GENERATE_PROBES_DISABLED, |
| 121 |
GENERATE_PROBES_SUBDIV_4, |
| 122 |
GENERATE_PROBES_SUBDIV_8, |
| 123 |
GENERATE_PROBES_SUBDIV_16, |
| 124 |
GENERATE_PROBES_SUBDIV_32, |
| 125 |
}; |
| 126 |
|
| 127 |
enum LightType { |
| 128 |
LIGHT_TYPE_DIRECTIONAL, |
| 129 |
LIGHT_TYPE_OMNI, |
| 130 |
LIGHT_TYPE_SPOT |
| 131 |
}; |
| 132 |
|
| 133 |
enum BakeError { |
| 134 |
BAKE_OK, |
| 135 |
BAKE_ERROR_TEXTURE_EXCEEDS_MAX_SIZE, |
| 136 |
BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES, |
| 137 |
BAKE_ERROR_ATLAS_TOO_SMALL, |
| 138 |
BAKE_ERROR_USER_ABORTED, |
| 139 |
}; |
| 140 |
|
| 141 |
enum BakeQuality { |
| 142 |
BAKE_QUALITY_LOW, |
| 143 |
BAKE_QUALITY_MEDIUM, |
| 144 |
BAKE_QUALITY_HIGH, |
| 145 |
BAKE_QUALITY_ULTRA, |
| 146 |
}; |
| 147 |
|
| 148 |
typedef Lightmapper *(*CreateFunc)(); |
| 149 |
|
| 150 |
static CreateFunc create_custom; |
| 151 |
static CreateFunc create_gpu; |
| 152 |
static CreateFunc create_cpu; |
| 153 |
|
| 154 |
protected: |
| 155 |
public: |
| 156 |
typedef bool (*BakeStepFunc)(float, const String &, void *, bool); |
| 157 |
|
| 158 |
struct MeshData { |
| 159 |
|
| 160 |
Vector<Vector3> points; |
| 161 |
Vector<Vector2> uv2; |
| 162 |
Vector<Vector3> normal; |
| 163 |
Vector<RID> material; |
| 164 |
Ref<Image> albedo_on_uv2; |
| 165 |
Ref<Image> emission_on_uv2; |
| 166 |
Variant userdata; |
| 167 |
}; |
| 168 |
|
| 169 |
virtual void add_mesh(const MeshData &p_mesh) = 0; |
| 170 |
virtual void add_directional_light(const String &p_name, bool p_static, const Vector3 &p_direction, const Color &p_color, float p_energy, float p_indirect_energy, float p_angular_distance, float p_shadow_blur) = 0; |
| 171 |
virtual void add_omni_light(const String &p_name, bool p_static, const Vector3 &p_position, const Color &p_color, float p_energy, float p_indirect_energy, float p_range, float p_attenuation, float p_size, float p_shadow_blur) = 0; |
| 172 |
virtual void add_spot_light(const String &p_name, bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_indirect_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size, float p_shadow_blur) = 0; |
| 173 |
virtual void add_probe(const Vector3 &p_position) = 0; |
| 174 |
virtual BakeError bake(BakeQuality p_quality, bool p_use_denoiser, float p_denoiser_strength, int p_denoiser_range, int p_bounces, float p_bounce_indirect_energy, float p_bias, int p_max_texture_size, bool p_bake_sh, bool p_bake_shadowmask, bool p_texture_for_bounces, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function = nullptr, void *p_step_userdata = nullptr, float p_exposure_normalization = 1.0, float p_supersampling_factor = 1.0) = 0; |
| 175 |
|
| 176 |
virtual int get_bake_texture_count() const = 0; |
| 177 |
virtual Ref<Image> get_bake_texture(int p_index) const = 0; |
| 178 |
virtual int get_shadowmask_texture_count() const = 0; |
| 179 |
virtual Ref<Image> get_shadowmask_texture(int p_index) const = 0; |
| 180 |
virtual int get_bake_mesh_count() const = 0; |
| 181 |
virtual Variant get_bake_mesh_userdata(int p_index) const = 0; |
| 182 |
virtual Rect2 get_bake_mesh_uv_scale(int p_index) const = 0; |
| 183 |
virtual int get_bake_mesh_texture_slice(int p_index) const = 0; |
| 184 |
virtual int get_bake_probe_count() const = 0; |
| 185 |
virtual Vector3 get_bake_probe_point(int p_probe) const = 0; |
| 186 |
virtual Vector<Color> get_bake_probe_sh(int p_probe) const = 0; |
| 187 |
|
| 188 |
static Ref<Lightmapper> create(); |
| 189 |
|
| 190 |
Lightmapper(); |
| 191 |
}; |