summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/baked_light.cpp7
-rw-r--r--scene/3d/baked_light.h15
-rw-r--r--scene/3d/baked_light_instance.cpp65
-rw-r--r--scene/3d/baked_light_instance.h33
-rw-r--r--scene/3d/light.cpp32
-rw-r--r--scene/3d/light.h17
-rw-r--r--scene/3d/sprite_3d.cpp1
-rw-r--r--scene/3d/sprite_3d.h4
-rw-r--r--scene/3d/visual_instance.cpp78
-rw-r--r--scene/3d/visual_instance.h9
-rw-r--r--scene/register_scene_types.cpp5
-rw-r--r--scene/resources/baked_light.cpp308
-rw-r--r--scene/resources/baked_light.h106
-rw-r--r--scene/scene_string_names.cpp4
-rw-r--r--scene/scene_string_names.h3
15 files changed, 657 insertions, 30 deletions
diff --git a/scene/3d/baked_light.cpp b/scene/3d/baked_light.cpp
deleted file mode 100644
index 55832b7c18..0000000000
--- a/scene/3d/baked_light.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "baked_light.h"
-#include "mesh_instance.h"
-
-BakedLight::BakedLight() {
-
-
-}
diff --git a/scene/3d/baked_light.h b/scene/3d/baked_light.h
deleted file mode 100644
index a6f997afe9..0000000000
--- a/scene/3d/baked_light.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef BAKED_LIGHT_H
-#define BAKED_LIGHT_H
-
-#include "scene/3d/spatial.h"
-class BakedLightBaker;
-
-
-class BakedLight : public Spatial {
- OBJ_TYPE(BakedLight,Spatial);
-
-public:
- BakedLight();
-};
-
-#endif // BAKED_LIGHT_H
diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp
new file mode 100644
index 0000000000..c1cc1f6b68
--- /dev/null
+++ b/scene/3d/baked_light_instance.cpp
@@ -0,0 +1,65 @@
+#include "baked_light_instance.h"
+#include "scene/scene_string_names.h"
+
+
+RID BakedLightInstance::get_baked_light_instance() const {
+
+ if (baked_light.is_null())
+ return RID();
+ else
+ return get_instance();
+
+}
+
+void BakedLightInstance::set_baked_light(const Ref<BakedLight>& p_baked_light) {
+
+ baked_light=p_baked_light;
+
+ RID base_rid;
+
+ if (baked_light.is_valid())
+ base_rid=baked_light->get_rid();
+ else
+ base_rid=RID();
+
+ set_base(base_rid);
+
+ if (is_inside_world()) {
+
+ emit_signal(SceneStringNames::get_singleton()->baked_light_changed);
+
+// for (List<Node*>::Element *E=baked_geometry.front();E;E=E->next()) {
+// VS::get_singleton()->instance_geometry_set_baked_light(E->get()->get_instance(),baked_light.is_valid()?get_instance():RID());
+// }
+ }
+}
+
+Ref<BakedLight> BakedLightInstance::get_baked_light() const{
+
+ return baked_light;
+}
+
+AABB BakedLightInstance::get_aabb() const {
+
+ return AABB(Vector3(0,0,0),Vector3(1,1,1));
+}
+DVector<Face3> BakedLightInstance::get_faces(uint32_t p_usage_flags) const {
+
+ return DVector<Face3>();
+}
+
+
+void BakedLightInstance::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_baked_light","baked_light"),&BakedLightInstance::set_baked_light);
+ ObjectTypeDB::bind_method(_MD("get_baked_light"),&BakedLightInstance::get_baked_light);
+ ObjectTypeDB::bind_method(_MD("get_baked_light_instance"),&BakedLightInstance::get_baked_light_instance);
+
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"baked_light",PROPERTY_HINT_RESOURCE_TYPE,"BakedLight"),_SCS("set_baked_light"),_SCS("get_baked_light"));
+ ADD_SIGNAL( MethodInfo("baked_light_changed"));
+}
+
+BakedLightInstance::BakedLightInstance() {
+
+
+}
diff --git a/scene/3d/baked_light_instance.h b/scene/3d/baked_light_instance.h
new file mode 100644
index 0000000000..b904ced9a7
--- /dev/null
+++ b/scene/3d/baked_light_instance.h
@@ -0,0 +1,33 @@
+#ifndef BAKED_LIGHT_INSTANCE_H
+#define BAKED_LIGHT_INSTANCE_H
+
+#include "scene/3d/visual_instance.h"
+#include "scene/resources/baked_light.h"
+
+class BakedLightBaker;
+
+
+class BakedLightInstance : public VisualInstance {
+ OBJ_TYPE(BakedLightInstance,VisualInstance);
+
+ Ref<BakedLight> baked_light;
+
+
+protected:
+
+ static void _bind_methods();
+public:
+
+
+ RID get_baked_light_instance() const;
+
+ void set_baked_light(const Ref<BakedLight>& baked_light);
+ Ref<BakedLight> get_baked_light() const;
+
+ virtual AABB get_aabb() const;
+ virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const;
+
+ BakedLightInstance();
+};
+
+#endif // BAKED_LIGHT_H
diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp
index b4b7b400c6..7cc1d12daa 100644
--- a/scene/3d/light.cpp
+++ b/scene/3d/light.cpp
@@ -351,6 +351,17 @@ void Light::set_operator(Operator p_op) {
}
+void Light::set_bake_mode(BakeMode p_bake_mode) {
+
+ bake_mode=p_bake_mode;
+}
+
+Light::BakeMode Light::get_bake_mode() const {
+
+ return bake_mode;
+}
+
+
Light::Operator Light::get_operator() const {
return op;
@@ -416,6 +427,18 @@ void Light::approximate_opengl_attenuation(float p_constant, float p_linear, flo
}
+void Light::set_enabled(bool p_enabled) {
+
+ enabled=p_enabled;
+ VS::get_singleton()->instance_light_set_enabled(get_instance(),enabled);
+}
+
+bool Light::is_enabled() const{
+
+ return enabled;
+}
+
+
void Light::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_parameter","variable","value"), &Light::set_parameter );
@@ -428,8 +451,14 @@ void Light::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_projector:Texture"), &Light::get_projector );
ObjectTypeDB::bind_method(_MD("set_operator","operator"), &Light::set_operator );
ObjectTypeDB::bind_method(_MD("get_operator"), &Light::get_operator );
+ ObjectTypeDB::bind_method(_MD("set_bake_mode","bake_mode"), &Light::set_bake_mode );
+ ObjectTypeDB::bind_method(_MD("get_bake_mode"), &Light::get_bake_mode );
+ ObjectTypeDB::bind_method(_MD("set_enabled","enabled"), &Light::set_enabled );
+ ObjectTypeDB::bind_method(_MD("is_enabled"), &Light::is_enabled );
+ ADD_PROPERTY( PropertyInfo( Variant::BOOL, "params/enabled"), _SCS("set_enabled"), _SCS("is_enabled"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "params/bake_mode",PROPERTY_HINT_ENUM,"Disabled,Indirect,Full"), _SCS("set_bake_mode"), _SCS("get_bake_mode"));
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/energy", PROPERTY_HINT_EXP_RANGE, "0,64,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_ENERGY );
/*
if (type == VisualServer::LIGHT_OMNI || type == VisualServer::LIGHT_SPOT) {
@@ -490,6 +519,8 @@ Light::Light(VisualServer::LightType p_type) {
op=OPERATOR_ADD;
set_project_shadows( false );
set_base(light);
+ enabled=true;
+ bake_mode=BAKE_MODE_DISABLED;
}
@@ -563,6 +594,7 @@ DirectionalLight::DirectionalLight() : Light( VisualServer::LIGHT_DIRECTIONAL )
shadow_param[SHADOW_PARAM_PSSM_SPLIT_WEIGHT]=0.5;
shadow_param[SHADOW_PARAM_PSSM_ZOFFSET_SCALE]=2.0;
+
}
diff --git a/scene/3d/light.h b/scene/3d/light.h
index dea7dbee6c..76b44c8712 100644
--- a/scene/3d/light.h
+++ b/scene/3d/light.h
@@ -64,6 +64,14 @@ public:
COLOR_SPECULAR=VisualServer::LIGHT_COLOR_SPECULAR
};
+ enum BakeMode {
+
+ BAKE_MODE_DISABLED,
+ BAKE_MODE_INDIRECT,
+ BAKE_MODE_FULL
+
+ };
+
enum Operator {
@@ -78,8 +86,10 @@ private:
Color colors[3];
+ BakeMode bake_mode;
VisualServer::LightType type;
bool shadows;
+ bool enabled;
Operator op;
// bind helpers
@@ -114,6 +124,12 @@ public:
void set_operator(Operator p_op);
Operator get_operator() const;
+ void set_bake_mode(BakeMode p_bake_mode);
+ BakeMode get_bake_mode() const;
+
+ void set_enabled(bool p_enabled);
+ bool is_enabled() const;
+
virtual AABB get_aabb() const;
virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const;
@@ -127,6 +143,7 @@ public:
VARIANT_ENUM_CAST( Light::Parameter );
VARIANT_ENUM_CAST( Light::LightColor );
VARIANT_ENUM_CAST( Light::Operator );
+VARIANT_ENUM_CAST( Light::BakeMode);
class DirectionalLight : public Light {
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 21fdb9abd3..49e593c1f5 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -479,6 +479,7 @@ void Sprite3D::set_frame(int p_frame) {
if (frame != p_frame)
frame=p_frame;
+ _queue_update();
}
int Sprite3D::get_frame() const {
diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h
index 1330cd1c30..fe8e1f6ebf 100644
--- a/scene/3d/sprite_3d.h
+++ b/scene/3d/sprite_3d.h
@@ -5,9 +5,9 @@
#include "scene/2d/animated_sprite.h"
-class SpriteBase3D : public VisualInstance {
+class SpriteBase3D : public GeometryInstance {
- OBJ_TYPE(SpriteBase3D,VisualInstance);
+ OBJ_TYPE(SpriteBase3D,GeometryInstance);
public:
enum DrawFlags {
diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp
index 96f16ab8c8..625da9b093 100644
--- a/scene/3d/visual_instance.cpp
+++ b/scene/3d/visual_instance.cpp
@@ -31,7 +31,7 @@
#include "servers/visual_server.h"
#include "room_instance.h"
#include "scene/scene_string_names.h"
-
+#include "baked_light_instance.h"
#include "skeleton.h"
AABB VisualInstance::get_transformed_aabb() const {
@@ -186,6 +186,61 @@ float GeometryInstance::get_draw_range_end() const {
return draw_end;
}
+void GeometryInstance::_notification(int p_what) {
+
+ if (p_what==NOTIFICATION_ENTER_WORLD) {
+
+ if (flags[FLAG_USE_BAKED_LIGHT]) {
+
+ _find_baked_light();
+ }
+
+
+ } else if (p_what==NOTIFICATION_EXIT_WORLD) {
+
+ if (flags[FLAG_USE_BAKED_LIGHT]) {
+
+ if (baked_light_instance) {
+ baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ baked_light_instance=NULL;
+ }
+ _baked_light_changed();
+
+ }
+ }
+
+}
+
+void GeometryInstance::_baked_light_changed() {
+
+ if (!baked_light_instance)
+ VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID());
+ else
+ VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance());
+
+}
+
+void GeometryInstance::_find_baked_light() {
+
+ Node *n=get_parent();
+ while(n) {
+
+ BakedLightInstance *bl=n->cast_to<BakedLightInstance>();
+ if (bl) {
+
+ baked_light_instance=bl;
+ baked_light_instance->connect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ _baked_light_changed();
+
+ return;
+ }
+
+ n=n->get_parent();
+ }
+
+ _baked_light_changed();
+}
+
void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
ERR_FAIL_INDEX(p_flag,FLAG_MAX);
@@ -198,8 +253,20 @@ void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
_change_notify("geometry/visible");
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
}
-
-
+ if (p_flag==FLAG_USE_BAKED_LIGHT) {
+
+ if (is_inside_world()) {
+ if (!p_value) {
+ if (baked_light_instance) {
+ baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ baked_light_instance=NULL;
+ }
+ _baked_light_changed();
+ } else {
+ _find_baked_light();
+ }
+ }
+ }
}
bool GeometryInstance::get_flag(Flags p_flag) const{
@@ -224,6 +291,8 @@ void GeometryInstance::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_draw_range_end","mode"), &GeometryInstance::set_draw_range_end);
ObjectTypeDB::bind_method(_MD("get_draw_range_end"), &GeometryInstance::get_draw_range_end);
+ ObjectTypeDB::bind_method(_MD("_baked_light_changed"), &GeometryInstance::_baked_light_changed);
+
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/visible"), _SCS("set_flag"), _SCS("get_flag"),FLAG_VISIBLE);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "geometry/material_override",PROPERTY_HINT_RESOURCE_TYPE,"Material"), _SCS("set_material_override"), _SCS("get_material_override"));
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/cast_shadow"), _SCS("set_flag"), _SCS("get_flag"),FLAG_CAST_SHADOW);
@@ -234,6 +303,7 @@ void GeometryInstance::_bind_methods() {
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/billboard_y"), _SCS("set_flag"), _SCS("get_flag"),FLAG_BILLBOARD_FIX_Y);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/depth_scale"), _SCS("set_flag"), _SCS("get_flag"),FLAG_DEPH_SCALE);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/visible_in_all_rooms"), _SCS("set_flag"), _SCS("get_flag"),FLAG_VISIBLE_IN_ALL_ROOMS);
+ ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/use_baked_light"), _SCS("set_flag"), _SCS("get_flag"),FLAG_USE_BAKED_LIGHT);
ADD_SIGNAL( MethodInfo("visibility_changed"));
@@ -258,5 +328,7 @@ GeometryInstance::GeometryInstance() {
flags[FLAG_BILLBOARD_FIX_Y]=false;
flags[FLAG_DEPH_SCALE]=false;
flags[FLAG_VISIBLE_IN_ALL_ROOMS]=false;
+ baked_light_instance=NULL;
+
}
diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h
index afb9ed70f8..1cf96d5d9e 100644
--- a/scene/3d/visual_instance.h
+++ b/scene/3d/visual_instance.h
@@ -78,6 +78,8 @@ public:
};
+class BakedLightInstance;
+
class GeometryInstance : public VisualInstance {
OBJ_TYPE( GeometryInstance, VisualInstance );
@@ -91,7 +93,7 @@ public:
FLAG_BILLBOARD_FIX_Y=VS::INSTANCE_FLAG_BILLBOARD_FIX_Y,
FLAG_DEPH_SCALE=VS::INSTANCE_FLAG_DEPH_SCALE,
FLAG_VISIBLE_IN_ALL_ROOMS=VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,
- FLAG_USE_BAKED_LIGHT_VOLUME=VS::INSTANCE_FLAG_USE_BAKED_LIGHT_VOLUME,
+ FLAG_USE_BAKED_LIGHT=VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
FLAG_MAX=VS::INSTANCE_FLAG_MAX,
};
@@ -102,8 +104,13 @@ private:
Ref<Material> material_override;
float draw_begin;
float draw_end;
+ void _find_baked_light();
+ BakedLightInstance *baked_light_instance;
+
+ void _baked_light_changed();
protected:
+ void _notification(int p_what);
static void _bind_methods();
public:
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index f3d757b601..30e6e01842 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -187,7 +187,7 @@
#include "scene/3d/area.h"
#include "scene/3d/physics_joint.h"
#include "scene/3d/multimesh_instance.h"
-#include "scene/3d/baked_light.h"
+#include "scene/3d/baked_light_instance.h"
#include "scene/3d/ray_cast.h"
#include "scene/3d/immediate_geometry.h"
#include "scene/3d/sprite_3d.h"
@@ -407,7 +407,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<PathFollow>();
ObjectTypeDB::register_type<VisibilityNotifier>();
ObjectTypeDB::register_type<VisibilityEnabler>();
- ObjectTypeDB::register_type<BakedLight>();
+ ObjectTypeDB::register_type<BakedLightInstance>();
ObjectTypeDB::register_type<WorldEnvironment>();
//scenariofx
@@ -515,6 +515,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<SurfaceTool>();
ObjectTypeDB::register_type<MeshDataTool>();
+ ObjectTypeDB::register_type<BakedLight>();
OS::get_singleton()->yield(); //may take time to init
diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp
new file mode 100644
index 0000000000..b3de7143ee
--- /dev/null
+++ b/scene/resources/baked_light.cpp
@@ -0,0 +1,308 @@
+#include "baked_light.h"
+#include "servers/visual_server.h"
+
+void BakedLight::set_mode(Mode p_mode) {
+
+ mode=p_mode;
+ VS::get_singleton()->baked_light_set_mode(baked_light,(VS::BakedLightMode(p_mode)));
+}
+
+BakedLight::Mode BakedLight::get_mode() const{
+
+ return mode;
+}
+
+void BakedLight::set_octree(const DVector<uint8_t>& p_octree) {
+
+ VS::get_singleton()->baked_light_set_octree(baked_light,p_octree);
+}
+
+DVector<uint8_t> BakedLight::get_octree() const {
+
+ return VS::get_singleton()->baked_light_get_octree(baked_light);
+}
+
+
+void BakedLight::_update_lightmaps() {
+
+ VS::get_singleton()->baked_light_clear_lightmaps(baked_light);
+ for(Map<int,Ref<Texture> >::Element *E=lightmaps.front();E;E=E->next()) {
+
+ VS::get_singleton()->baked_light_add_lightmap(baked_light,E->get()->get_rid(),E->key());
+ }
+
+}
+
+void BakedLight::add_lightmap(const Ref<Texture> p_texture,int p_id) {
+
+ ERR_FAIL_COND(!p_texture.is_valid());
+ ERR_FAIL_COND(p_id<0);
+ lightmaps[p_id]=p_texture;
+ VS::get_singleton()->baked_light_add_lightmap(baked_light,p_texture->get_rid(),p_id);
+}
+
+void BakedLight::erase_lightmap(int p_id) {
+
+ ERR_FAIL_COND(!lightmaps.has(p_id));
+ lightmaps.erase(p_id);
+ _update_lightmaps();
+}
+
+void BakedLight::get_lightmaps(List<int> *r_lightmaps) {
+
+ for(Map<int,Ref<Texture> >::Element *E=lightmaps.front();E;E=E->next()) {
+
+ r_lightmaps->push_back(E->key());
+ }
+
+}
+
+Ref<Texture> BakedLight::get_lightmap_texture(int p_id) {
+
+ if (!lightmaps.has(p_id))
+ return Ref<Texture>();
+
+ return lightmaps[p_id];
+
+
+}
+
+void BakedLight::clear_lightmaps() {
+
+ lightmaps.clear();
+ _update_lightmaps();
+}
+
+RID BakedLight::get_rid() const {
+
+ return baked_light;
+}
+
+Array BakedLight::_get_lightmap_data() const {
+
+ Array ret;
+ ret.resize(lightmaps.size()*2);
+
+ int idx=0;
+ for(Map<int,Ref<Texture> >::Element *E=lightmaps.front();E;E=E->next()) {
+
+ ret[idx++]=E->key();
+ ret[idx++]=E->get();
+ }
+
+ return ret;
+
+}
+
+void BakedLight::_set_lightmap_data(Array p_array){
+
+ lightmaps.clear();
+ for(int i=0;i<p_array.size();i+=2) {
+
+ int id = p_array[i];
+ Ref<Texture> tex = p_array[i+1];
+ ERR_CONTINUE(id<0);
+ ERR_CONTINUE(tex.is_null());
+ lightmaps[id]=tex;
+ }
+ _update_lightmaps();
+}
+
+
+void BakedLight::set_cell_subdivision(int p_subdiv) {
+
+ cell_subdiv=p_subdiv;
+}
+
+int BakedLight::get_cell_subdivision() const{
+
+ return cell_subdiv;
+}
+
+void BakedLight::set_initial_lattice_subdiv(int p_size){
+
+ lattice_subdiv=p_size;
+}
+int BakedLight::get_initial_lattice_subdiv() const{
+
+ return lattice_subdiv;
+}
+
+void BakedLight::set_plot_size(float p_size){
+
+ plot_size=p_size;
+}
+float BakedLight::get_plot_size() const{
+
+ return plot_size;
+}
+
+void BakedLight::set_bounces(int p_size){
+
+ bounces=p_size;
+}
+int BakedLight::get_bounces() const{
+
+ return bounces;
+}
+
+void BakedLight::set_cell_extra_margin(float p_margin) {
+ cell_extra_margin=p_margin;
+}
+
+float BakedLight::get_cell_extra_margin() const {
+
+ return cell_extra_margin;
+}
+
+void BakedLight::set_edge_damp(float p_margin) {
+ edge_damp=p_margin;
+}
+
+float BakedLight::get_edge_damp() const {
+
+ return edge_damp;
+}
+
+
+void BakedLight::set_normal_damp(float p_margin) {
+ normal_damp=p_margin;
+}
+
+float BakedLight::get_normal_damp() const {
+
+ return normal_damp;
+}
+
+void BakedLight::set_energy_multiplier(float p_multiplier){
+
+ energy_multiply=p_multiplier;
+}
+float BakedLight::get_energy_multiplier() const{
+
+ return energy_multiply;
+}
+
+void BakedLight::set_gamma_adjust(float p_adjust){
+
+ gamma_adjust=p_adjust;
+}
+float BakedLight::get_gamma_adjust() const{
+
+ return gamma_adjust;
+}
+
+void BakedLight::set_bake_flag(BakeFlags p_flags,bool p_enable){
+
+ flags[p_flags]=p_enable;
+}
+bool BakedLight::get_bake_flag(BakeFlags p_flags) const{
+
+ return flags[p_flags];
+}
+
+
+
+void BakedLight::_bind_methods(){
+
+
+ ObjectTypeDB::bind_method(_MD("set_mode","mode"),&BakedLight::set_mode);
+ ObjectTypeDB::bind_method(_MD("get_mode"),&BakedLight::get_mode);
+
+ ObjectTypeDB::bind_method(_MD("set_octree","octree"),&BakedLight::set_octree);
+ ObjectTypeDB::bind_method(_MD("get_octree"),&BakedLight::get_octree);
+
+ ObjectTypeDB::bind_method(_MD("add_lightmap","texture:Texture","id"),&BakedLight::add_lightmap);
+ ObjectTypeDB::bind_method(_MD("erase_lightmap","id"),&BakedLight::erase_lightmap);
+ ObjectTypeDB::bind_method(_MD("clear_lightmaps"),&BakedLight::clear_lightmaps);
+
+ ObjectTypeDB::bind_method(_MD("_set_lightmap_data","lightmap_data"),&BakedLight::_set_lightmap_data);
+ ObjectTypeDB::bind_method(_MD("_get_lightmap_data"),&BakedLight::_get_lightmap_data);
+
+ ObjectTypeDB::bind_method(_MD("set_cell_subdivision","cell_subdivision"),&BakedLight::set_cell_subdivision);
+ ObjectTypeDB::bind_method(_MD("get_cell_subdivision"),&BakedLight::get_cell_subdivision);
+
+ ObjectTypeDB::bind_method(_MD("set_initial_lattice_subdiv","cell_subdivision"),&BakedLight::set_initial_lattice_subdiv);
+ ObjectTypeDB::bind_method(_MD("get_initial_lattice_subdiv","cell_subdivision"),&BakedLight::get_initial_lattice_subdiv);
+
+ ObjectTypeDB::bind_method(_MD("set_plot_size","plot_size"),&BakedLight::set_plot_size);
+ ObjectTypeDB::bind_method(_MD("get_plot_size"),&BakedLight::get_plot_size);
+
+ ObjectTypeDB::bind_method(_MD("set_bounces","bounces"),&BakedLight::set_bounces);
+ ObjectTypeDB::bind_method(_MD("get_bounces"),&BakedLight::get_bounces);
+
+ ObjectTypeDB::bind_method(_MD("set_cell_extra_margin","cell_extra_margin"),&BakedLight::set_cell_extra_margin);
+ ObjectTypeDB::bind_method(_MD("get_cell_extra_margin"),&BakedLight::get_cell_extra_margin);
+
+ ObjectTypeDB::bind_method(_MD("set_edge_damp","edge_damp"),&BakedLight::set_edge_damp);
+ ObjectTypeDB::bind_method(_MD("get_edge_damp"),&BakedLight::get_edge_damp);
+
+ ObjectTypeDB::bind_method(_MD("set_normal_damp","normal_damp"),&BakedLight::set_normal_damp);
+ ObjectTypeDB::bind_method(_MD("get_normal_damp"),&BakedLight::get_normal_damp);
+
+ ObjectTypeDB::bind_method(_MD("set_energy_multiplier","energy_multiplier"),&BakedLight::set_energy_multiplier);
+ ObjectTypeDB::bind_method(_MD("get_energy_multiplier"),&BakedLight::get_energy_multiplier);
+
+ ObjectTypeDB::bind_method(_MD("set_gamma_adjust","gamma_adjust"),&BakedLight::set_gamma_adjust);
+ ObjectTypeDB::bind_method(_MD("get_gamma_adjust"),&BakedLight::get_gamma_adjust);
+
+ ObjectTypeDB::bind_method(_MD("set_bake_flag","flag","enabled"),&BakedLight::set_bake_flag);
+ ObjectTypeDB::bind_method(_MD("get_bake_flag","flag"),&BakedLight::get_bake_flag);
+
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Octree,Lightmaps"),_SCS("set_mode"),_SCS("get_mode"));
+
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/cell_subdiv",PROPERTY_HINT_RANGE,"4,14,1"),_SCS("set_cell_subdivision"),_SCS("get_cell_subdivision"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/lattice_subdiv",PROPERTY_HINT_RANGE,"1,5,1"),_SCS("set_initial_lattice_subdiv"),_SCS("get_initial_lattice_subdiv"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/light_bounces",PROPERTY_HINT_RANGE,"0,3,1"),_SCS("set_bounces"),_SCS("get_bounces"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/plot_size",PROPERTY_HINT_RANGE,"1.0,16.0,0.01"),_SCS("set_plot_size"),_SCS("get_plot_size"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/energy_mult",PROPERTY_HINT_RANGE,"0.01,4096.0,0.01"),_SCS("set_energy_multiplier"),_SCS("get_energy_multiplier"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/gamma_adjust",PROPERTY_HINT_EXP_EASING),_SCS("set_gamma_adjust"),_SCS("get_gamma_adjust"));
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/diffuse"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_DIFFUSE);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/specular"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_SPECULAR);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/translucent"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_TRANSLUCENT);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/conserve_energy"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_CONSERVE_ENERGY);
+
+ ADD_PROPERTY( PropertyInfo(Variant::RAW_ARRAY,"octree",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_octree"),_SCS("get_octree"));
+ ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"lightmaps",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_lightmap_data"),_SCS("_get_lightmap_data"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/cell_margin",PROPERTY_HINT_RANGE,"0.01,0.8,0.01"),_SCS("set_cell_extra_margin"),_SCS("get_cell_extra_margin"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/edge_damp",PROPERTY_HINT_RANGE,"0.0,8.0,0.1"),_SCS("set_edge_damp"),_SCS("get_edge_damp"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/normal_damp",PROPERTY_HINT_RANGE,"0.0,1.0,0.01"),_SCS("set_normal_damp"),_SCS("get_normal_damp"));
+
+ BIND_CONSTANT( MODE_OCTREE );
+ BIND_CONSTANT( MODE_LIGHTMAPS );
+
+ BIND_CONSTANT( BAKE_DIFFUSE );
+ BIND_CONSTANT( BAKE_SPECULAR );
+ BIND_CONSTANT( BAKE_TRANSLUCENT );
+ BIND_CONSTANT( BAKE_CONSERVE_ENERGY );
+ BIND_CONSTANT( BAKE_MAX );
+
+
+}
+
+
+BakedLight::BakedLight() {
+
+ cell_subdiv=8;
+ lattice_subdiv=4;
+ plot_size=2.5;
+ bounces=1;
+ energy_multiply=1.0;
+ gamma_adjust=1.0;
+ cell_extra_margin=0.05;
+ edge_damp=0.0;
+ normal_damp=0.0;
+
+ flags[BAKE_DIFFUSE]=true;
+ flags[BAKE_SPECULAR]=false;
+ flags[BAKE_TRANSLUCENT]=true;
+ flags[BAKE_CONSERVE_ENERGY]=false;
+
+ mode=MODE_OCTREE;
+ baked_light=VS::get_singleton()->baked_light_create();
+}
+
+BakedLight::~BakedLight() {
+
+ VS::get_singleton()->free(baked_light);
+}
diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h
new file mode 100644
index 0000000000..8b50f6e0d3
--- /dev/null
+++ b/scene/resources/baked_light.h
@@ -0,0 +1,106 @@
+#ifndef BAKED_LIGHT_H
+#define BAKED_LIGHT_H
+
+#include "resource.h"
+#include "scene/resources/texture.h"
+
+class BakedLight : public Resource {
+
+ OBJ_TYPE( BakedLight, Resource);
+public:
+ enum Mode {
+
+ MODE_OCTREE,
+ MODE_LIGHTMAPS
+ };
+
+ enum BakeFlags {
+ BAKE_DIFFUSE,
+ BAKE_SPECULAR,
+ BAKE_TRANSLUCENT,
+ BAKE_CONSERVE_ENERGY,
+ BAKE_MAX
+ };
+
+private:
+
+ RID baked_light;
+ Mode mode;
+ Map<int,Ref<Texture> > lightmaps;
+
+ //bake vars
+ int cell_subdiv;
+ int lattice_subdiv;
+ float plot_size;
+ float energy_multiply;
+ float gamma_adjust;
+ float cell_extra_margin;
+ float edge_damp;
+ float normal_damp;
+ int bounces;
+ bool flags[BAKE_MAX];
+
+
+
+ void _update_lightmaps();
+
+ Array _get_lightmap_data() const;
+ void _set_lightmap_data(Array p_array);
+ static void _bind_methods();
+
+public:
+
+ void set_cell_subdivision(int p_subdiv);
+ int get_cell_subdivision() const;
+
+ void set_initial_lattice_subdiv(int p_size);
+ int get_initial_lattice_subdiv() const;
+
+ void set_plot_size(float p_size);
+ float get_plot_size() const;
+
+ void set_bounces(int p_size);
+ int get_bounces() const;
+
+ void set_energy_multiplier(float p_multiplier);
+ float get_energy_multiplier() const;
+
+ void set_gamma_adjust(float p_adjust);
+ float get_gamma_adjust() const;
+
+ void set_cell_extra_margin(float p_margin);
+ float get_cell_extra_margin() const;
+
+ void set_edge_damp(float p_margin);
+ float get_edge_damp() const;
+
+ void set_normal_damp(float p_margin);
+ float get_normal_damp() const;
+
+ void set_bake_flag(BakeFlags p_flags,bool p_enable);
+ bool get_bake_flag(BakeFlags p_flags) const;
+
+
+ void set_mode(Mode p_mode);
+ Mode get_mode() const;
+
+ void set_octree(const DVector<uint8_t>& p_octree);
+ DVector<uint8_t> get_octree() const;
+
+ void add_lightmap(const Ref<Texture> p_texture,int p_id);
+ void erase_lightmap(int p_id);
+ void get_lightmaps(List<int> *r_lightmaps);
+ Ref<Texture> get_lightmap_texture(int p_id);
+ void clear_lightmaps();
+
+ virtual RID get_rid() const;
+
+ BakedLight();
+ ~BakedLight();
+};
+
+
+VARIANT_ENUM_CAST(BakedLight::Mode);
+VARIANT_ENUM_CAST(BakedLight::BakeFlags);
+
+#endif // BAKED_LIGHT_H
diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp
index a8e4c80f89..40792f5139 100644
--- a/scene/scene_string_names.cpp
+++ b/scene/scene_string_names.cpp
@@ -140,4 +140,8 @@ SceneStringNames::SceneStringNames() {
_im_update = StaticCString::create("_im_update");
_queue_update = StaticCString::create("_queue_update");
+ baked_light_changed = StaticCString::create("baked_light_changed");
+ _baked_light_changed = StaticCString::create("_baked_light_changed");
+
+
}
diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h
index 2286712250..866c0ea387 100644
--- a/scene/scene_string_names.h
+++ b/scene/scene_string_names.h
@@ -148,6 +148,9 @@ public:
StringName _im_update;
StringName _queue_update;
+ StringName baked_light_changed;
+ StringName _baked_light_changed;
+
};