Merge pull request #6414 from RandomShaper/improve-shader-shadow
Expose additional light/shadow properties to canvas item shaders
This commit is contained in:
commit
80861b7d59
@ -4666,7 +4666,7 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
|
||||
enablers.push_back("#define USE_LIGHT_SHADER_CODE\n");
|
||||
}
|
||||
if (light_flags.uses_shadow_color) {
|
||||
enablers.push_back("#define USE_LIGHT_SHADOW_COLOR\n");
|
||||
enablers.push_back("#define USE_OUTPUT_SHADOW_COLOR\n");
|
||||
}
|
||||
if (light_flags.uses_time || fragment_flags.uses_time || vertex_flags.uses_time) {
|
||||
enablers.push_back("#define USE_TIME\n");
|
||||
@ -4709,7 +4709,7 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
|
||||
enablers.push_back("#define USE_TEXPIXEL_SIZE\n");
|
||||
}
|
||||
if (light_flags.uses_shadow_color) {
|
||||
enablers.push_back("#define USE_LIGHT_SHADOW_COLOR\n");
|
||||
enablers.push_back("#define USE_OUTPUT_SHADOW_COLOR\n");
|
||||
}
|
||||
|
||||
if (vertex_flags.uses_worldvec) {
|
||||
|
@ -904,6 +904,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_VEC"]="light_vec";
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_HEIGHT"]="light_height";
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_COLOR"]="light";
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_SHADOW"]="light_shadow_color";
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_UV"]="light_uv";
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT"]="light_out";
|
||||
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SHADOW"]="shadow_color";
|
||||
|
@ -244,7 +244,7 @@ FRAGMENT_SHADER_CODE
|
||||
|
||||
vec2 light_uv = light_uv_interp.xy;
|
||||
vec4 light = texture2D(light_texture,light_uv) * light_color;
|
||||
#if defined(USE_LIGHT_SHADOW_COLOR)
|
||||
#if defined(USE_OUTPUT_SHADOW_COLOR)
|
||||
vec4 shadow_color=vec4(0.0,0.0,0.0,0.0);
|
||||
#endif
|
||||
|
||||
@ -380,7 +380,7 @@ LIGHT_SHADER_CODE
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_SHADOW_COLOR)
|
||||
#if defined(USE_OUTPUT_SHADOW_COLOR)
|
||||
color=mix(shadow_color,color,shadow_attenuation);
|
||||
#else
|
||||
//color*=shadow_attenuation;
|
||||
|
@ -1185,7 +1185,7 @@ FRAGMENT_SHADER_CODE
|
||||
vec3 mdiffuse = diffuse.rgb;
|
||||
vec3 light;
|
||||
|
||||
#if defined(USE_LIGHT_SHADOW_COLOR)
|
||||
#if defined(USE_OUTPUT_SHADOW_COLOR)
|
||||
vec3 shadow_color=vec3(0.0,0.0,0.0);
|
||||
#endif
|
||||
|
||||
@ -1209,7 +1209,7 @@ LIGHT_SHADER_CODE
|
||||
#endif
|
||||
diffuse.rgb = const_light_mult * ambient_light *diffuse.rgb + light * attenuation * shadow_attenuation;
|
||||
|
||||
#if defined(USE_LIGHT_SHADOW_COLOR)
|
||||
#if defined(USE_OUTPUT_SHADOW_COLOR)
|
||||
diffuse.rgb += light * shadow_color * attenuation * (1.0 - shadow_attenuation);
|
||||
#endif
|
||||
|
||||
|
@ -1483,6 +1483,8 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightHeight","LIGHT_HEIGHT","",SLOT_TYPE_SCALAR,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowColor","LIGHT_SHADOW.rgb","",SLOT_TYPE_VEC,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowAlpha","LIGHT_SHADOW.a","",SLOT_TYPE_SCALAR,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN},
|
||||
@ -1490,6 +1492,8 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
|
||||
//canvas item light out
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowColor","SHADOW.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowAlpha","SHADOW.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
|
||||
//end
|
||||
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT},
|
||||
|
||||
|
@ -1180,6 +1180,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_light_builtins_defs[]={
|
||||
{ "LIGHT_HEIGHT", TYPE_FLOAT},
|
||||
{ "LIGHT_COLOR", TYPE_VEC4},
|
||||
{ "LIGHT_UV", TYPE_VEC2},
|
||||
{ "LIGHT_SHADOW", TYPE_VEC4},
|
||||
{ "LIGHT", TYPE_VEC4},
|
||||
{ "SHADOW", TYPE_VEC4},
|
||||
{ "POINT_COORD", TYPE_VEC2},
|
||||
|
@ -2422,6 +2422,7 @@ void ShaderGraphView::_create_node(int p_id) {
|
||||
colors.push_back("Color");
|
||||
colors.push_back("LightColor");
|
||||
colors.push_back("Light");
|
||||
colors.push_back("ShadowColor");
|
||||
colors.push_back("Diffuse");
|
||||
colors.push_back("Specular");
|
||||
colors.push_back("Emmision");
|
||||
@ -2434,6 +2435,7 @@ void ShaderGraphView::_create_node(int p_id) {
|
||||
reals.push_back("ShadeParam");
|
||||
reals.push_back("SpecularExp");
|
||||
reals.push_back("LightAlpha");
|
||||
reals.push_back("ShadowAlpha");
|
||||
reals.push_back("PointSize");
|
||||
reals.push_back("Discard");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user