diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-04-03 01:43:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-04-03 01:43:37 -0300 |
commit | 9fa1698c7420bae2c6353bf300ce2cdb73434bf6 (patch) | |
tree | 7d67492203476b2599621ebe258987c94db79b88 /scene/2d | |
parent | 42d41a3fbc79ff1014d3b65666d6f80240520c8c (diff) |
Changes to Light
-=-=-=-=-=-=-=-=
-Changed material unshaded property for an enum, which supports light-only shading
-Added a "Mix" shading mode, useful for using lights as masks
-Added energy parameter to Light2D
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/canvas_item.cpp | 33 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 15 | ||||
-rw-r--r-- | scene/2d/light_2d.cpp | 42 | ||||
-rw-r--r-- | scene/2d/light_2d.h | 18 |
4 files changed, 79 insertions, 29 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index c3ff03d8f4..118ba33bc6 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -42,8 +42,8 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value) if (p_name==SceneStringNames::get_singleton()->shader_shader) { set_shader(p_value); return true; - } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) { - set_unshaded(p_value); + } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { + set_shading_mode(ShadingMode(p_value.operator int())); return true; } else { @@ -74,10 +74,10 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const { r_ret=get_shader(); return true; - } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) { + } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { - r_ret=unshaded; + r_ret=shading_mode; return true; } else { @@ -100,7 +100,7 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const { void CanvasItemMaterial::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemShader,CanvasItemShaderGraph" ) ); - p_list->push_back( PropertyInfo( Variant::BOOL, "shader/unshaded") ); + p_list->push_back( PropertyInfo( Variant::INT, "shader/shading_mode",PROPERTY_HINT_ENUM,"Normal,Unshaded,Light Only") ); if (!shader.is_null()) { @@ -161,25 +161,30 @@ RID CanvasItemMaterial::get_rid() const { return material; } -void CanvasItemMaterial::set_unshaded(bool p_unshaded) { +void CanvasItemMaterial::set_shading_mode(ShadingMode p_mode) { - unshaded=p_unshaded; - VS::get_singleton()->canvas_item_material_set_unshaded(material,p_unshaded); + shading_mode=p_mode; + VS::get_singleton()->canvas_item_material_set_shading_mode(material,VS::CanvasItemShadingMode(p_mode)); } -bool CanvasItemMaterial::is_unshaded() const{ - - return unshaded; +CanvasItemMaterial::ShadingMode CanvasItemMaterial::get_shading_mode() const { + return shading_mode; } + void CanvasItemMaterial::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"),&CanvasItemMaterial::set_shader); ObjectTypeDB::bind_method(_MD("get_shader:Shader"),&CanvasItemMaterial::get_shader); ObjectTypeDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param); ObjectTypeDB::bind_method(_MD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param); - ObjectTypeDB::bind_method(_MD("set_unshaded","unshaded"),&CanvasItemMaterial::set_unshaded); - ObjectTypeDB::bind_method(_MD("is_unshaded"),&CanvasItemMaterial::is_unshaded); + ObjectTypeDB::bind_method(_MD("set_shading_mode","mode"),&CanvasItemMaterial::set_shading_mode); + ObjectTypeDB::bind_method(_MD("get_shading_mode"),&CanvasItemMaterial::get_shading_mode); + + BIND_CONSTANT( SHADING_NORMAL ); + BIND_CONSTANT( SHADING_UNSHADED ); + BIND_CONSTANT( SHADING_ONLY_LIGHT ); + } @@ -202,7 +207,7 @@ void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p CanvasItemMaterial::CanvasItemMaterial() { material=VS::get_singleton()->canvas_item_material_create(); - unshaded=false; + shading_mode=SHADING_NORMAL; } CanvasItemMaterial::~CanvasItemMaterial(){ diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index c43642a8ec..167f2b96f3 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -45,10 +45,17 @@ class CanvasItemMaterial : public Resource{ OBJ_TYPE(CanvasItemMaterial,Resource); RID material; Ref<Shader> shader; - bool unshaded; +public: + enum ShadingMode { + SHADING_NORMAL, + SHADING_UNSHADED, + SHADING_ONLY_LIGHT, + }; protected: + ShadingMode shading_mode; + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; @@ -66,14 +73,16 @@ public: void set_shader_param(const StringName& p_param,const Variant& p_value); Variant get_shader_param(const StringName& p_param) const; - void set_unshaded(bool p_unshaded); - bool is_unshaded() const; + void set_shading_mode(ShadingMode p_mode); + ShadingMode get_shading_mode() const; virtual RID get_rid() const; CanvasItemMaterial(); ~CanvasItemMaterial(); }; +VARIANT_ENUM_CAST( CanvasItemMaterial::ShadingMode ); + class CanvasItem : public Node { diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 4abb7e5436..c0ab544d42 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -96,6 +96,21 @@ float Light2D::get_height() const { return height; } +void Light2D::set_energy( float p_energy) { + + energy=p_energy; + VS::get_singleton()->canvas_light_set_energy(canvas_light,energy); + +} + + +float Light2D::get_energy() const { + + return energy; +} + + + void Light2D::set_texture_scale( float p_scale) { _scale=p_scale; @@ -178,15 +193,15 @@ int Light2D::get_item_shadow_mask() const { return item_shadow_mask; } -void Light2D::set_subtract_mode( bool p_enable ) { +void Light2D::set_mode( Mode p_mode ) { - subtract_mode=p_enable; - VS::get_singleton()->canvas_light_set_subtract_mode(canvas_light,p_enable); + mode=p_mode; + VS::get_singleton()->canvas_light_set_mode(canvas_light,VS::CanvasLightMode(p_mode)); } -bool Light2D::get_subtract_mode() const { +Light2D::Mode Light2D::get_mode() const { - return subtract_mode; + return mode; } void Light2D::set_shadow_enabled( bool p_enabled) { @@ -260,6 +275,9 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height); + ObjectTypeDB::bind_method(_MD("set_energy","energy"),&Light2D::set_energy); + ObjectTypeDB::bind_method(_MD("get_energy"),&Light2D::get_energy); + ObjectTypeDB::bind_method(_MD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale); ObjectTypeDB::bind_method(_MD("get_texture_scale"),&Light2D::get_texture_scale); @@ -283,8 +301,8 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_item_shadow_mask","item_shadow_mask"),&Light2D::set_item_shadow_mask); ObjectTypeDB::bind_method(_MD("get_item_shadow_mask"),&Light2D::get_item_shadow_mask); - ObjectTypeDB::bind_method(_MD("set_subtract_mode","enable"),&Light2D::set_subtract_mode); - ObjectTypeDB::bind_method(_MD("get_subtract_mode"),&Light2D::get_subtract_mode); + ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Light2D::set_mode); + ObjectTypeDB::bind_method(_MD("get_mode"),&Light2D::get_mode); ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled); ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled); @@ -300,7 +318,8 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_texture_scale"),_SCS("get_texture_scale")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy"),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Add,Sub,Mix"),_SCS("set_mode"),_SCS("get_mode")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"range/height"),_SCS("set_height"),_SCS("get_height")); ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min")); ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max")); @@ -312,6 +331,10 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/esm_multiplier",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_esm_multiplier"),_SCS("get_shadow_esm_multiplier")); ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_mask"),_SCS("get_item_shadow_mask")); + BIND_CONSTANT( MODE_ADD ); + BIND_CONSTANT( MODE_SUB ); + BIND_CONSTANT( MODE_MIX ); + } @@ -329,9 +352,10 @@ Light2D::Light2D() { layer_max=0; item_mask=1; item_shadow_mask=1; - subtract_mode=false; + mode=MODE_ADD; shadow_buffer_size=2048; shadow_esm_multiplier=80; + energy=1.0; } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 6cfb055fa9..ef875aec2f 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -6,6 +6,13 @@ class Light2D : public Node2D { OBJ_TYPE(Light2D,Node2D); +public: + enum Mode { + MODE_ADD, + MODE_SUB, + MODE_MIX, + }; + private: RID canvas_light; bool enabled; @@ -13,6 +20,7 @@ private: Color color; float height; float _scale; + float energy; int z_min; int z_max; int layer_min; @@ -21,7 +29,7 @@ private: int item_shadow_mask; int shadow_buffer_size; float shadow_esm_multiplier; - bool subtract_mode; + Mode mode; Ref<Texture> texture; Vector2 texture_offset; @@ -51,6 +59,9 @@ public: void set_height( float p_height); float get_height() const; + void set_energy( float p_energy); + float get_energy() const; + void set_texture_scale( float p_scale); float get_texture_scale() const; @@ -72,8 +83,8 @@ public: void set_item_shadow_mask( int p_mask); int get_item_shadow_mask() const; - void set_subtract_mode( bool p_enable ); - bool get_subtract_mode() const; + void set_mode( Mode p_mode ); + Mode get_mode() const; void set_shadow_enabled( bool p_enabled); bool is_shadow_enabled() const; @@ -90,5 +101,6 @@ public: ~Light2D(); }; +VARIANT_ENUM_CAST(Light2D::Mode); #endif // LIGHT_2D_H |