diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-12-08 20:25:08 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-12-08 20:25:08 -0300 |
commit | 428984ec0cfbbf190d88b4a2ff4cb3587a51c309 (patch) | |
tree | 7d0c9fec94614ebeceff0674f8a28bcf9e5f1689 /drivers/gles2 | |
parent | 88c653a9e58a127f99e92a85683f8c3b7587d108 (diff) |
-New mask mode for lights, makes using masks MUCH easier.
Diffstat (limited to 'drivers/gles2')
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 6 | ||||
-rw-r--r-- | drivers/gles2/shaders/canvas.glsl | 23 |
2 files changed, 17 insertions, 12 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index d0f2f88ee6..83b71fd5ff 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -9540,7 +9540,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_opacity = ci->final_opacity; - if (unshaded || (p_modulate.a>0.001 && (!material || material->shading_mode!=VS::CANVAS_ITEM_SHADING_ONLY_LIGHT))) + if (unshaded || (p_modulate.a>0.001 && (!material || material->shading_mode!=VS::CANVAS_ITEM_SHADING_ONLY_LIGHT) && !ci->light_masked )) _canvas_item_render_commands<false>(ci,current_clip,reclip); if (canvas_blend_mode==VS::MATERIAL_BLEND_MODE_MIX && p_light && !unshaded) { @@ -9572,7 +9572,8 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); glBlendFunc(GL_SRC_ALPHA,GL_ONE); } break; - case VS::CANVAS_LIGHT_MODE_MIX: { + case VS::CANVAS_LIGHT_MODE_MIX: + case VS::CANVAS_LIGHT_MODE_MASK: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -9620,6 +9621,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR,Color(light->color.r*light->energy,light->color.g*light->energy,light->color.b*light->energy,light->color.a)); canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT,light->height); canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX,light->xform_cache.affine_inverse()); + canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA,light->mode==VS::CANVAS_LIGHT_MODE_MASK?1.0:0.0); if (has_shadow) { diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index e297b328cd..259e82d704 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -155,6 +155,7 @@ uniform vec4 light_color; uniform vec4 light_shadow_color; uniform float light_height; varying vec4 light_uv_interp; +uniform float light_outside_alpha; #if defined(NORMAL_USED) varying vec4 local_rot; @@ -247,22 +248,27 @@ FRAGMENT_SHADER_CODE vec4 shadow_color=vec4(0.0,0.0,0.0,0.0); #endif + if (any(lessThan(light_uv_interp.xy,vec2(0.0,0.0))) || any(greaterThanEqual(light_uv_interp.xy,vec2(1.0,1.0)))) { + color.a*=light_outside_alpha; //invisible + + } else { + #if defined(USE_LIGHT_SHADER_CODE) //light is written by the light shader -{ - vec4 light_out=light*color; + { + vec4 light_out=light*color; LIGHT_SHADER_CODE - color=light_out; -} + color=light_out; + } #else #if defined(NORMAL_USED) - vec3 light_normal = normalize(vec3(light_vec,-light_height)); - light*=max(dot(-light_normal,normal),0.0); + vec3 light_normal = normalize(vec3(light_vec,-light_height)); + light*=max(dot(-light_normal,normal),0.0); #endif - color*=light; + color*=light; /* #ifdef USE_NORMAL color.xy=local_rot.xy;//normal.xy; @@ -273,9 +279,6 @@ LIGHT_SHADER_CODE //light shader code #endif - if (any(lessThan(light_uv_interp.xy,vec2(0.0,0.0))) || any(greaterThanEqual(light_uv_interp.xy,vec2(1.0,1.0)))) { - color.a=0.0; //invisible - } else { #ifdef USE_SHADOWS |