summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d')
-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
10 files changed, 233 insertions, 28 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: