2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* gi_probe.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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-12-20 04:21:07 +01:00
|
|
|
#ifndef GIPROBE_H
|
|
|
|
#define GIPROBE_H
|
|
|
|
|
|
|
|
#include "multimesh_instance.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/3d/visual_instance.h"
|
2016-12-20 04:21:07 +01:00
|
|
|
|
|
|
|
class GIProbeData : public Resource {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(GIProbeData, Resource);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
|
|
|
RID probe;
|
|
|
|
|
2016-12-23 04:37:38 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-11-17 03:09:00 +01:00
|
|
|
void set_bounds(const AABB &p_bounds);
|
|
|
|
AABB get_bounds() const;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
|
|
|
void set_cell_size(float p_size);
|
|
|
|
float get_cell_size() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_to_cell_xform(const Transform &p_xform);
|
2016-12-20 04:21:07 +01:00
|
|
|
Transform get_to_cell_xform() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_dynamic_data(const PoolVector<int> &p_data);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> get_dynamic_data() const;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2016-12-22 14:00:15 +01:00
|
|
|
void set_dynamic_range(int p_range);
|
|
|
|
int get_dynamic_range() const;
|
|
|
|
|
2017-02-06 09:12:15 +01:00
|
|
|
void set_propagation(float p_range);
|
|
|
|
float get_propagation() const;
|
|
|
|
|
2016-12-22 14:00:15 +01:00
|
|
|
void set_energy(float p_range);
|
|
|
|
float get_energy() const;
|
|
|
|
|
2017-02-16 12:55:11 +01:00
|
|
|
void set_bias(float p_range);
|
|
|
|
float get_bias() const;
|
|
|
|
|
2017-07-16 04:24:37 +02:00
|
|
|
void set_normal_bias(float p_range);
|
|
|
|
float get_normal_bias() const;
|
|
|
|
|
2016-12-22 14:00:15 +01:00
|
|
|
void set_interior(bool p_enable);
|
|
|
|
bool is_interior() const;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2016-12-31 14:53:29 +01:00
|
|
|
void set_compress(bool p_enable);
|
|
|
|
bool is_compressed() const;
|
|
|
|
|
2016-12-20 04:21:07 +01:00
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
GIProbeData();
|
|
|
|
~GIProbeData();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
class GIProbe : public VisualInstance {
|
|
|
|
GDCLASS(GIProbe, VisualInstance);
|
2016-12-23 04:37:38 +01:00
|
|
|
|
2016-12-20 04:21:07 +01:00
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
enum Subdiv {
|
2016-12-20 04:21:07 +01:00
|
|
|
SUBDIV_64,
|
|
|
|
SUBDIV_128,
|
|
|
|
SUBDIV_256,
|
|
|
|
SUBDIV_512,
|
|
|
|
SUBDIV_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-30 20:33:07 +01:00
|
|
|
typedef void (*BakeBeginFunc)(int);
|
|
|
|
typedef void (*BakeStepFunc)(int, const String &);
|
|
|
|
typedef void (*BakeEndFunc)();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
private:
|
2016-12-20 04:21:07 +01:00
|
|
|
//stuff used for bake
|
|
|
|
struct Baker {
|
|
|
|
|
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
CHILD_EMPTY = 0xFFFFFFFF
|
2016-12-20 04:21:07 +01:00
|
|
|
};
|
|
|
|
struct Cell {
|
|
|
|
|
|
|
|
uint32_t childs[8];
|
|
|
|
float albedo[3]; //albedo in RGB24
|
|
|
|
float emission[3]; //accumulated light in 16:16 fixed point (needs to be integer for moving lights fast)
|
2016-12-22 14:00:15 +01:00
|
|
|
float normal[3];
|
2016-12-20 04:21:07 +01:00
|
|
|
uint32_t used_sides;
|
|
|
|
float alpha; //used for upsampling
|
2016-12-30 12:35:54 +01:00
|
|
|
int level;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
|
|
|
Cell() {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
childs[i] = CHILD_EMPTY;
|
2016-12-20 04:21:07 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
emission[i] = 0;
|
|
|
|
albedo[i] = 0;
|
|
|
|
normal[i] = 0;
|
2016-12-20 04:21:07 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
alpha = 0;
|
|
|
|
used_sides = 0;
|
|
|
|
level = 0;
|
2016-12-20 04:21:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Cell> bake_cells;
|
|
|
|
int cell_subdiv;
|
|
|
|
|
|
|
|
struct MaterialCache {
|
|
|
|
//128x128 textures
|
|
|
|
Vector<Color> albedo;
|
|
|
|
Vector<Color> emission;
|
|
|
|
};
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color);
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Ref<Material>, MaterialCache> material_cache;
|
2016-12-20 04:21:07 +01:00
|
|
|
MaterialCache _get_material_cache(Ref<Material> p_material);
|
|
|
|
int leaf_voxel_count;
|
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB po2_bounds;
|
2016-12-20 04:21:07 +01:00
|
|
|
int axis_cell_size[3];
|
|
|
|
|
|
|
|
struct PlotMesh {
|
2017-02-06 04:38:39 +01:00
|
|
|
Ref<Material> override_material;
|
|
|
|
Vector<Ref<Material> > instance_materials;
|
2017-07-29 05:03:54 +02:00
|
|
|
Ref<Mesh> mesh;
|
2016-12-20 04:21:07 +01:00
|
|
|
Transform local_xform;
|
|
|
|
};
|
|
|
|
|
|
|
|
Transform to_cell_space;
|
|
|
|
|
|
|
|
List<PlotMesh> mesh_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
Ref<GIProbeData> probe_data;
|
|
|
|
|
|
|
|
RID gi_probe;
|
|
|
|
|
|
|
|
Subdiv subdiv;
|
|
|
|
Vector3 extents;
|
2016-12-22 14:00:15 +01:00
|
|
|
int dynamic_range;
|
|
|
|
float energy;
|
2017-02-16 12:55:11 +01:00
|
|
|
float bias;
|
2017-07-16 04:24:37 +02:00
|
|
|
float normal_bias;
|
2017-02-06 09:12:15 +01:00
|
|
|
float propagation;
|
2016-12-22 14:00:15 +01:00
|
|
|
bool interior;
|
2016-12-31 14:53:29 +01:00
|
|
|
bool compress;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
|
|
|
int color_scan_cell_width;
|
|
|
|
int bake_texture_size;
|
|
|
|
|
2017-11-16 01:01:02 +01:00
|
|
|
Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color_mul, const Color &p_color_add);
|
2017-03-05 16:44:50 +01:00
|
|
|
Baker::MaterialCache _get_material_cache(Ref<Material> p_material, Baker *p_baker);
|
2017-11-17 03:09:00 +01:00
|
|
|
void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const Baker::MaterialCache &p_material, const AABB &p_aabb, Baker *p_baker);
|
2017-07-29 05:03:54 +02:00
|
|
|
void _plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _find_meshes(Node *p_at_node, Baker *p_baker);
|
|
|
|
void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
void _debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx, Baker *p_baker);
|
2016-12-20 04:21:07 +01:00
|
|
|
void _create_debug_mesh(Baker *p_baker);
|
|
|
|
|
|
|
|
void _debug_bake();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-10-30 20:33:07 +01:00
|
|
|
static BakeBeginFunc bake_begin_function;
|
|
|
|
static BakeStepFunc bake_step_function;
|
|
|
|
static BakeEndFunc bake_end_function;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_probe_data(const Ref<GIProbeData> &p_data);
|
2016-12-20 04:21:07 +01:00
|
|
|
Ref<GIProbeData> get_probe_data() const;
|
|
|
|
|
|
|
|
void set_subdiv(Subdiv p_subdiv);
|
|
|
|
Subdiv get_subdiv() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_extents(const Vector3 &p_extents);
|
2016-12-20 04:21:07 +01:00
|
|
|
Vector3 get_extents() const;
|
|
|
|
|
2016-12-22 14:00:15 +01:00
|
|
|
void set_dynamic_range(int p_dynamic_range);
|
|
|
|
int get_dynamic_range() const;
|
|
|
|
|
|
|
|
void set_energy(float p_energy);
|
|
|
|
float get_energy() const;
|
|
|
|
|
2017-02-16 12:55:11 +01:00
|
|
|
void set_bias(float p_bias);
|
|
|
|
float get_bias() const;
|
|
|
|
|
2017-07-16 04:24:37 +02:00
|
|
|
void set_normal_bias(float p_normal_bias);
|
|
|
|
float get_normal_bias() const;
|
|
|
|
|
2017-02-06 09:12:15 +01:00
|
|
|
void set_propagation(float p_propagation);
|
|
|
|
float get_propagation() const;
|
|
|
|
|
2016-12-22 14:00:15 +01:00
|
|
|
void set_interior(bool p_enable);
|
|
|
|
bool is_interior() const;
|
|
|
|
|
2016-12-31 14:53:29 +01:00
|
|
|
void set_compress(bool p_enable);
|
|
|
|
bool is_compressed() const;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void bake(Node *p_from_node = NULL, bool p_create_visual_debug = false);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
virtual AABB get_aabb() const;
|
2017-01-07 22:25:37 +01:00
|
|
|
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
|
|
|
GIProbe();
|
|
|
|
~GIProbe();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(GIProbe::Subdiv)
|
|
|
|
|
|
|
|
#endif // GIPROBE_H
|