summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-06-24 18:15:43 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-06-24 18:15:43 -0300
commit52308aba68516d4b4ca29a176d6053cf3f623ce4 (patch)
treef6e7bb32ca38060e508fcd55ce5cd77d5c1b722f
parent48f1d02da4795ba9d485fe5fe2bea907be2fc467 (diff)
ability to change shadow color in light2d
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp1
-rw-r--r--drivers/gles2/shaders/canvas.glsl4
-rw-r--r--scene/2d/light_2d.cpp16
-rw-r--r--scene/2d/light_2d.h5
-rw-r--r--servers/visual/rasterizer.h2
-rw-r--r--servers/visual/visual_server_raster.cpp9
-rw-r--r--servers/visual/visual_server_raster.h2
-rw-r--r--servers/visual/visual_server_wrap_mt.h2
-rw-r--r--servers/visual_server.h1
9 files changed, 41 insertions, 1 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index efc92c5d9f..9d0e0ce0cc 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -9536,6 +9536,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const
canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_TEXTURE,max_texture_units-3);
canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX,light->shadow_matrix_cache);
canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
+ canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR,light->shadow_color);
}
diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl
index 669ae44621..e297b328cd 100644
--- a/drivers/gles2/shaders/canvas.glsl
+++ b/drivers/gles2/shaders/canvas.glsl
@@ -152,6 +152,7 @@ uniform vec4 modulate;
uniform sampler2D light_texture;
uniform vec4 light_color;
+uniform vec4 light_shadow_color;
uniform float light_height;
varying vec4 light_uv_interp;
@@ -379,7 +380,8 @@ LIGHT_SHADER_CODE
#if defined(USE_LIGHT_SHADOW_COLOR)
color=mix(shadow_color,color,shadow_attenuation);
#else
- color*=shadow_attenuation;
+ //color*=shadow_attenuation;
+ color=mix(light_shadow_color,color,shadow_attenuation);
#endif
//use shadows
#endif
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index c0ab544d42..852a6fb46b 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -237,6 +237,16 @@ float Light2D::get_shadow_esm_multiplier() const{
return shadow_esm_multiplier;
}
+void Light2D::set_shadow_color( const Color& p_shadow_color) {
+ shadow_color=p_shadow_color;
+ VS::get_singleton()->canvas_light_set_shadow_color(canvas_light,shadow_color);
+}
+
+Color Light2D::get_shadow_color() const {
+ return shadow_color;
+}
+
+
void Light2D::_notification(int p_what) {
@@ -313,6 +323,10 @@ void Light2D::_bind_methods() {
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);
+ ObjectTypeDB::bind_method(_MD("set_shadow_color","shadow_color"),&Light2D::set_shadow_color);
+ ObjectTypeDB::bind_method(_MD("get_shadow_color"),&Light2D::get_shadow_color);
+
+
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"));
@@ -327,6 +341,7 @@ void Light2D::_bind_methods() {
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::COLOR,"shadow/color"),_SCS("set_shadow_color"),_SCS("get_shadow_color"));
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"));
@@ -356,6 +371,7 @@ Light2D::Light2D() {
shadow_buffer_size=2048;
shadow_esm_multiplier=80;
energy=1.0;
+ shadow_color=Color(0,0,0,0);
}
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index ef875aec2f..bf61868bac 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -18,6 +18,7 @@ private:
bool enabled;
bool shadow;
Color color;
+ Color shadow_color;
float height;
float _scale;
float energy;
@@ -95,6 +96,10 @@ public:
void set_shadow_esm_multiplier( float p_multiplier);
float get_shadow_esm_multiplier() const;
+ void set_shadow_color( const Color& p_shadow_color);
+ Color get_shadow_color() const;
+
+
virtual Rect2 get_item_rect() const;
Light2D();
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 50336e07f4..0b115a4d1d 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -592,6 +592,7 @@ public:
RID shadow_buffer;
int shadow_buffer_size;
float shadow_esm_mult;
+ Color shadow_color;
void *texture_cache; // implementation dependent
@@ -610,6 +611,7 @@ public:
CanvasLight() {
enabled=true;
color=Color(1,1,1);
+ shadow_color=Color(0,0,0,0);
height=0;
z_min=-1024;
z_max=1024;
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 3fc90fd46d..b51f59050d 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -4071,6 +4071,15 @@ void VisualServerRaster::canvas_light_set_shadow_esm_multiplier(RID p_light, flo
}
+void VisualServerRaster::canvas_light_set_shadow_color(RID p_light, const Color& p_color) {
+
+ Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+ clight->shadow_color=p_color;
+
+}
+
+
/****** CANVAS LIGHT OCCLUDER ******/
RID VisualServerRaster::canvas_light_occluder_create() {
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index e2940c216b..73298d58cd 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -1180,6 +1180,8 @@ public:
virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled);
virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size);
virtual void canvas_light_set_shadow_esm_multiplier(RID p_light, float p_multiplier);
+ virtual void canvas_light_set_shadow_color(RID p_light, const Color& p_color);
+
virtual RID canvas_light_occluder_create();
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 6719342a6a..db03d82829 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -626,6 +626,8 @@ public:
FUNC2(canvas_light_set_shadow_enabled,RID,bool);
FUNC2(canvas_light_set_shadow_buffer_size,RID,int);
FUNC2(canvas_light_set_shadow_esm_multiplier,RID,float);
+ FUNC2(canvas_light_set_shadow_color,RID,const Color&);
+
/* CANVAS OCCLUDER */
diff --git a/servers/visual_server.h b/servers/visual_server.h
index ef63907e34..8108030e0d 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -1032,6 +1032,7 @@ public:
virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled)=0;
virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size)=0;
virtual void canvas_light_set_shadow_esm_multiplier(RID p_light, float p_multiplier)=0;
+ virtual void canvas_light_set_shadow_color(RID p_light, const Color& p_color)=0;