summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp3
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp10
-rw-r--r--drivers/gles2/shaders/material.glsl8
-rw-r--r--scene/resources/shader_graph.cpp1
-rw-r--r--servers/visual/shader_language.cpp3
5 files changed, 22 insertions, 3 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index b473e8493f..39b448d6e0 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -4641,6 +4641,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
if (light_flags.uses_light) {
enablers.push_back("#define USE_LIGHT_SHADER_CODE\n");
}
+ if (light_flags.uses_shadow_color) {
+ enablers.push_back("#define USE_LIGHT_SHADOW_COLOR\n");
+ }
if (light_flags.uses_time || fragment_flags.uses_time || vertex_flags.uses_time) {
enablers.push_back("#define USE_TIME\n");
uses_time=true;
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index c8f59ce22b..f981529ee3 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -221,6 +221,10 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
uses_light=true;
}
+ if (vnode->name==vname_shadow) {
+ uses_shadow_color=true;
+ }
+
}
if (type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
@@ -783,13 +787,14 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
replace_table["texscreen"]= "texscreen";
replace_table["texpos"]= "texpos";
- mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POSITION"] = "gl_Position";
+
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_VERTEX"] = "vertex_in.xyz";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_NORMAL"] = "normal_in";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_TANGENT"]="tangent_in";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_BINORMALF"]="binormalf";
-
+
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POSITION"] = "gl_Position";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VERTEX"]="vertex_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["NORMAL"]="normal_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TANGENT"]="tangent_interp";
@@ -858,6 +863,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT"]="light";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["POINT_COORD"]="gl_PointCoord";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["TIME"]="time";
+ mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADOW"]="shadow_color";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["SRC_VERTEX"]="src_vtx";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VERTEX"]="outvec.xy";
diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl
index 38fb03ab5c..ccd80bf2f0 100644
--- a/drivers/gles2/shaders/material.glsl
+++ b/drivers/gles2/shaders/material.glsl
@@ -1175,6 +1175,10 @@ FRAGMENT_SHADER_CODE
vec3 mdiffuse = diffuse.rgb;
vec3 light;
+#if defined(USE_LIGHT_SHADOW_COLOR)
+ vec3 shadow_color=vec3(0.0,0.0,0.0);
+#endif
+
#if defined(USE_LIGHT_SHADER_CODE)
//light is written by the light shader
{
@@ -1195,6 +1199,10 @@ LIGHT_SHADER_CODE
#endif
diffuse.rgb = const_light_mult * ambient_light *diffuse.rgb + light * attenuation * shadow_attenuation;
+#if defined(USE_LIGHT_SHADOW_COLOR)
+ diffuse.rgb += light * shadow_color * attenuation * (1.0 - shadow_attenuation);
+#endif
+
#ifdef USE_FOG
diffuse.rgb = mix(diffuse.rgb,fog_interp.rgb,fog_interp.a);
diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp
index d5204f45d5..7b67eaeda8 100644
--- a/scene/resources/shader_graph.cpp
+++ b/scene/resources/shader_graph.cpp
@@ -1435,6 +1435,7 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
{MODE_MATERIAL,SHADER_TYPE_LIGHT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_IN},
//light out
{MODE_MATERIAL,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Shadow", "SHADOW", "",SLOT_TYPE_VEC, SLOT_OUT },
//canvas item vertex in
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","vec3(SRC_VERTEX,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN},
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 6532c3f0ac..6c5f64edd9 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -1113,7 +1113,8 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::light_builtins_defs[]={
{ "SPECULAR_EXP", TYPE_FLOAT},
{ "SHADE_PARAM", TYPE_FLOAT},
{ "LIGHT", TYPE_VEC3},
- { "POINT_COORD", TYPE_VEC2},
+ { "SHADOW", TYPE_VEC3 },
+ { "POINT_COORD", TYPE_VEC2 },
// { "SCREEN_POS", TYPE_VEC2},
// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
{ "TIME", TYPE_FLOAT},