Fixes canvas light shaders.

Fixes #16904

Restore more out functionality, fix built-ins.

Requested changes, I think?

(cherry picked from commit 25ba49fd88)
This commit is contained in:
Pieter-Jan Briers 2018-03-10 00:21:38 +01:00 committed by Hein-Pieter van Braam
parent 6d767b0f9a
commit 0d2a2a9300
3 changed files with 35 additions and 29 deletions

View File

@ -795,7 +795,6 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"] = "light_height"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"] = "light_height";
actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"] = "light_color"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"] = "light_color";
actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv";
//actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_SHADOW_COLOR"]="light_shadow_color";
actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light";
actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color";
@ -805,9 +804,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV";
actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n";
actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n";
actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_COLOR"] = "#define SHADOW_COLOR_USED\n";
actions[VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n";
actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n";
/** SPATIAL SHADER **/ /** SPATIAL SHADER **/

View File

@ -285,7 +285,19 @@ MATERIAL_UNIFORMS
FRAGMENT_SHADER_GLOBALS FRAGMENT_SHADER_GLOBALS
void light_compute(inout vec4 light,vec2 light_vec,float light_height,vec4 light_color,vec2 light_uv,vec4 shadow,vec3 normal,vec2 uv,vec2 screen_uv,vec4 color) { void light_compute(
inout vec4 light,
inout vec2 light_vec,
inout float light_height,
inout vec4 light_color,
vec2 light_uv,
inout vec4 shadow_color,
vec3 normal,
vec2 uv,
#if defined(SCREEN_UV_USED)
vec2 screen_uv,
#endif
vec4 color) {
#if defined(USE_LIGHT_SHADER_CODE) #if defined(USE_LIGHT_SHADER_CODE)
@ -462,39 +474,41 @@ FRAGMENT_SHADER_CODE
float att=1.0; float att=1.0;
vec2 light_uv = light_uv_interp.xy; vec2 light_uv = light_uv_interp.xy;
vec4 light = texture(light_texture,light_uv) * light_color; vec4 light = texture(light_texture,light_uv);
#if defined(SHADOW_COLOR_USED)
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)))) { 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 color.a*=light_outside_alpha; //invisible
} else { } else {
float real_light_height = light_height;
vec4 real_light_color = light_color;
vec4 real_light_shadow_color = light_shadow_color;
#if defined(USE_LIGHT_SHADER_CODE) #if defined(USE_LIGHT_SHADER_CODE)
//light is written by the light shader //light is written by the light shader
light_compute(light,light_vec,light_height,light_color,light_uv,shadow,normal,uv,screen_uv,color); light_compute(
light,
light_vec,
real_light_height,
real_light_color,
light_uv,
real_light_shadow_color,
normal,
uv,
#if defined(SCREEN_UV_USED)
screen_uv,
#endif
color);
#endif
#else light *= real_light_color;
if (normal_used) { if (normal_used) {
vec3 light_normal = normalize(vec3(light_vec,-real_light_height));
vec3 light_normal = normalize(vec3(light_vec,-light_height));
light*=max(dot(-light_normal,normal),0.0); light*=max(dot(-light_normal,normal),0.0);
} }
color*=light; color*=light;
/*
#ifdef USE_NORMAL
color.xy=local_rot.xy;//normal.xy;
color.zw=vec2(0.0,1.0);
#endif
*/
//light shader code
#endif
#ifdef USE_SHADOWS #ifdef USE_SHADOWS
@ -634,13 +648,8 @@ FRAGMENT_SHADER_CODE
#endif #endif
#if defined(SHADOW_COLOR_USED)
color=mix(shadow_color,color,shadow_attenuation);
#else
//color*=shadow_attenuation; //color*=shadow_attenuation;
color=mix(light_shadow_color,color,shadow_attenuation); color=mix(real_light_shadow_color,color,shadow_attenuation);
#endif
//use shadows //use shadows
#endif #endif
} }

View File

@ -207,7 +207,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SCREEN_TEXTURE"] = constt(ShaderLanguage::TYPE_SAMPLER2D); shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SCREEN_TEXTURE"] = constt(ShaderLanguage::TYPE_SAMPLER2D);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].can_discard = true; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].can_discard = true;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["POSITION"] = constt(ShaderLanguage::TYPE_VEC2); shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["FRAGCOORD"] = constt(ShaderLanguage::TYPE_VEC4);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["NORMAL"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["NORMAL"] = constt(ShaderLanguage::TYPE_VEC3);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["UV"] = constt(ShaderLanguage::TYPE_VEC2); shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["UV"] = constt(ShaderLanguage::TYPE_VEC2);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["COLOR"] = constt(ShaderLanguage::TYPE_VEC4); shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["COLOR"] = constt(ShaderLanguage::TYPE_VEC4);