From a1f715a4da71fbc2b7d6fad68624bf8b22c6da17 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 2 Mar 2015 00:54:10 -0300 Subject: support for 2D shadow casters Added support for 2D shadow casters. *DANGER* Shaders in CanvasItem CHANGED, if you are using shader in a CanvasItem and pull this, you will lose them. Shaders now work through a 2D material system similar to 3D. If you don't want to lose the 2D shader code, save the shader as a .shd, then create a material in CanvasItem and re-assign the shader. --- scene/2d/light_2d.cpp | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'scene/2d/light_2d.cpp') diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index cea8c06d3f..93be0c397f 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -170,6 +170,29 @@ bool Light2D::is_shadow_enabled() const { return shadow; } +void Light2D::set_shadow_buffer_size( int p_size ) { + + shadow_buffer_size=p_size; + VS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light,shadow_buffer_size); +} + +int Light2D::get_shadow_buffer_size() const { + + return shadow_buffer_size; +} + +void Light2D::set_shadow_esm_multiplier( float p_multiplier) { + + shadow_esm_multiplier=p_multiplier; + VS::get_singleton()->canvas_light_set_shadow_esm_multiplier(canvas_light,p_multiplier); +} + +float Light2D::get_shadow_esm_multiplier() const{ + + return shadow_esm_multiplier; +} + + void Light2D::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { @@ -229,18 +252,26 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled); ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled); + ObjectTypeDB::bind_method(_MD("set_shadow_buffer_size","size"),&Light2D::set_shadow_buffer_size); + ObjectTypeDB::bind_method(_MD("get_shadow_buffer_size"),&Light2D::get_shadow_buffer_size); + + ObjectTypeDB::bind_method(_MD("set_shadow_esm_multiplier","multiplier"),&Light2D::set_shadow_esm_multiplier); + ObjectTypeDB::bind_method(_MD("get_shadow_esm_multiplier"),&Light2D::get_shadow_esm_multiplier); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); - ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture_offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); + ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"height"),_SCS("set_height"),_SCS("get_height")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_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,"z_range_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")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"layer_range_min",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_min"),_SCS("get_layer_range_min")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"layer_range_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow_enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled")); + 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")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_min",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_min"),_SCS("get_layer_range_min")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"range/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow/enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/buffer_size",PROPERTY_HINT_RANGE,"32,16384,1"),_SCS("set_shadow_buffer_size"),_SCS("get_shadow_buffer_size")); + 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")); } @@ -258,6 +289,8 @@ Light2D::Light2D() { layer_max=0; item_mask=1; subtract_mode=false; + shadow_buffer_size=2048; + shadow_esm_multiplier=80; } -- cgit v1.2.3 From 09489e3a78de39bb4d8690f3c65f8a5e7a56a95e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 9 Mar 2015 02:34:56 -0300 Subject: lot of work on 2D lighting and isometric maps added a new demo, isometric_light that does full isometric sorting, lights, shadows, etc. --- scene/2d/light_2d.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'scene/2d/light_2d.cpp') diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 93be0c397f..5472e0b00e 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -148,6 +148,18 @@ int Light2D::get_item_mask() const { return item_mask; } +void Light2D::set_item_shadow_mask( int p_mask) { + + item_shadow_mask=p_mask; + VS::get_singleton()->canvas_light_set_item_shadow_mask(canvas_light,item_shadow_mask); + +} + +int Light2D::get_item_shadow_mask() const { + + return item_shadow_mask; +} + void Light2D::set_subtract_mode( bool p_enable ) { subtract_mode=p_enable; @@ -246,6 +258,9 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_item_mask","item_mask"),&Light2D::set_item_mask); ObjectTypeDB::bind_method(_MD("get_item_mask"),&Light2D::get_item_mask); + 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); @@ -272,6 +287,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow/enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled")); ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/buffer_size",PROPERTY_HINT_RANGE,"32,16384,1"),_SCS("set_shadow_buffer_size"),_SCS("get_shadow_buffer_size")); 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")); } @@ -288,6 +304,7 @@ Light2D::Light2D() { layer_min=0; layer_max=0; item_mask=1; + item_shadow_mask=1; subtract_mode=false; shadow_buffer_size=2048; shadow_esm_multiplier=80; -- cgit v1.2.3 From a6f96f46b779a815b03974fece21728fe32e88d2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 10 Mar 2015 21:05:49 -0300 Subject: small optimizations to isometric light demo should work faster, and even faster if exported.. as textures have been optimized. --- scene/2d/light_2d.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'scene/2d/light_2d.cpp') diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 5472e0b00e..8f6907798f 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -23,7 +23,7 @@ Rect2 Light2D::get_item_rect() const { Size2i s; - s = texture->get_size(); + s = texture->get_size()*scale; Point2i ofs=texture_offset; ofs-=s/2; @@ -63,6 +63,8 @@ void Light2D::set_texture_offset( const Vector2& p_offset) { texture_offset=p_offset; VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset); + item_rect_changed(); + } Vector2 Light2D::get_texture_offset() const { @@ -87,11 +89,27 @@ void Light2D::set_height( float p_height) { VS::get_singleton()->canvas_light_set_height(canvas_light,height); } + + float Light2D::get_height() const { return height; } +void Light2D::set_scale( float p_scale) { + + scale=p_scale; + VS::get_singleton()->canvas_light_set_scale(canvas_light,scale); + item_rect_changed(); + +} + + +float Light2D::get_scale() const { + + return scale; +} + void Light2D::set_z_range_min( int p_min_z) { z_min=p_min_z; @@ -242,6 +260,10 @@ 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_scale","scale"),&Light2D::set_scale); + ObjectTypeDB::bind_method(_MD("get_scale"),&Light2D::get_scale); + + ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min); ObjectTypeDB::bind_method(_MD("get_z_range_min"),&Light2D::get_z_range_min); @@ -276,6 +298,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); 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_scale"),_SCS("get_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,"range/height"),_SCS("set_height"),_SCS("get_height")); @@ -299,6 +322,7 @@ Light2D::Light2D() { shadow=false; color=Color(1,1,1); height=0; + scale=1.0; z_min=-1024; z_max=1024; layer_min=0; -- cgit v1.2.3 From a93e33f5c8afc8ce2e9c1674718ff103bfae49b0 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 10:33:58 -0300 Subject: added spatial and node2d helper methods to perform operations such as translaiton, rotation, etc directly on nodes. --- scene/2d/light_2d.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scene/2d/light_2d.cpp') diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 8f6907798f..949c952b39 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -23,7 +23,7 @@ Rect2 Light2D::get_item_rect() const { Size2i s; - s = texture->get_size()*scale; + s = texture->get_size()*_scale; Point2i ofs=texture_offset; ofs-=s/2; @@ -98,8 +98,8 @@ float Light2D::get_height() const { void Light2D::set_scale( float p_scale) { - scale=p_scale; - VS::get_singleton()->canvas_light_set_scale(canvas_light,scale); + _scale=p_scale; + VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale); item_rect_changed(); } @@ -107,7 +107,7 @@ void Light2D::set_scale( float p_scale) { float Light2D::get_scale() const { - return scale; + return _scale; } void Light2D::set_z_range_min( int p_min_z) { @@ -322,7 +322,7 @@ Light2D::Light2D() { shadow=false; color=Color(1,1,1); height=0; - scale=1.0; + _scale=1.0; z_min=-1024; z_max=1024; layer_min=0; -- cgit v1.2.3 From 92ab362afae275ac26ba24db88395d6d4977515d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 10:39:32 -0300 Subject: avoid function naming conflict on light scale --- scene/2d/light_2d.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scene/2d/light_2d.cpp') diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 949c952b39..4abb7e5436 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -96,7 +96,7 @@ float Light2D::get_height() const { return height; } -void Light2D::set_scale( float p_scale) { +void Light2D::set_texture_scale( float p_scale) { _scale=p_scale; VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale); @@ -105,7 +105,7 @@ void Light2D::set_scale( float p_scale) { } -float Light2D::get_scale() const { +float Light2D::get_texture_scale() const { return _scale; } @@ -260,8 +260,8 @@ 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_scale","scale"),&Light2D::set_scale); - ObjectTypeDB::bind_method(_MD("get_scale"),&Light2D::get_scale); + ObjectTypeDB::bind_method(_MD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale); + ObjectTypeDB::bind_method(_MD("get_texture_scale"),&Light2D::get_texture_scale); ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min); @@ -298,7 +298,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); 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_scale"),_SCS("get_scale")); + 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,"range/height"),_SCS("set_height"),_SCS("get_height")); -- cgit v1.2.3