godot/scene/3d/gi_probe.h

175 lines
3.8 KiB
C++
Raw Normal View History

2016-12-20 03:21:07 +00:00
#ifndef GIPROBE_H
#define GIPROBE_H
#include "scene/3d/visual_instance.h"
#include "multimesh_instance.h"
class GIProbeData : public Resource {
OBJ_TYPE(GIProbeData,Resource);
RID probe;
public:
enum DataFormat {
DATA_RGBA8,
DATA_DXT5,
DATA_ETC2_EAC,
};
void set_bounds(const AABB& p_bounds);
AABB get_bounds() const;
void set_cell_size(float p_size);
float get_cell_size() const;
void set_to_cell_xform(const Transform& p_xform);
Transform get_to_cell_xform() const;
void set_dynamic_data(const DVector<int>& p_data);
DVector<int> get_dynamic_data() const;
void set_dynamic_range(float p_range);
float get_dynamic_range() const;
void set_static_data(const DVector<uint8_t>& p_data,DataFormat p_format,int p_width,int p_height,int p_depth);
DVector<uint8_t> get_static_data() const;
DataFormat get_static_data_format() const;
int get_static_data_width() const;
int get_static_data_height() const;
int get_static_data_depth() const;
virtual RID get_rid() const;
GIProbeData();
~GIProbeData();
};
VARIANT_ENUM_CAST(GIProbeData::DataFormat);
class GIProbe : public VisualInstance {
OBJ_TYPE(GIProbe,VisualInstance);
public:
enum Subdiv{
SUBDIV_64,
SUBDIV_128,
SUBDIV_256,
SUBDIV_512,
SUBDIV_MAX
};
private:
//stuff used for bake
struct Baker {
enum {
CHILD_EMPTY=0xFFFFFFFF
};
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)
uint32_t used_sides;
float alpha; //used for upsampling
Cell() {
for(int i=0;i<8;i++) {
childs[i]=CHILD_EMPTY;
}
for(int i=0;i<3;i++) {
emission[i]=0;
albedo[i]=0;
}
alpha=0;
used_sides=0;
}
};
Vector<Cell> bake_cells;
int cell_subdiv;
struct MaterialCache {
//128x128 textures
Vector<Color> albedo;
Vector<Color> emission;
};
Vector<Color> _get_bake_texture(Image &p_image, const Color &p_color);
Map<Ref<Material>,MaterialCache> material_cache;
MaterialCache _get_material_cache(Ref<Material> p_material);
int leaf_voxel_count;
AABB po2_bounds;
int axis_cell_size[3];
struct PlotMesh {
Ref<Mesh> mesh;
Transform local_xform;
};
Transform to_cell_space;
List<PlotMesh> mesh_list;
};
Ref<GIProbeData> probe_data;
RID gi_probe;
Subdiv subdiv;
Vector3 extents;
float dynamic_range;
int color_scan_cell_width;
int bake_texture_size;
Vector<Color> _get_bake_texture(Image &p_image,const Color& p_color);
Baker::MaterialCache _get_material_cache(Ref<Material> p_material,Baker *p_baker);
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);
void _plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker);
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);
void _debug_mesh(int p_idx, int p_level, const AABB &p_aabb,Ref<MultiMesh> &p_multimesh,int &idx,Baker *p_baker);
void _create_debug_mesh(Baker *p_baker);
void _debug_bake();
protected:
static void _bind_methods();
public:
void set_probe_data(const Ref<GIProbeData>& p_data);
Ref<GIProbeData> get_probe_data() const;
void set_subdiv(Subdiv p_subdiv);
Subdiv get_subdiv() const;
void set_extents(const Vector3& p_extents);
Vector3 get_extents() const;
void set_dynamic_range(float p_dynamic_range);
float get_dynamic_range() const;
void bake(Node *p_from_node=NULL,bool p_create_visual_debug=false);
virtual AABB get_aabb() const;
virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const;
GIProbe();
~GIProbe();
};
VARIANT_ENUM_CAST(GIProbe::Subdiv)
#endif // GIPROBE_H