-made normalmaps easier in 2D, fixes #1467
This commit is contained in:
parent
82cbee2d2d
commit
0adca0a7c9
6 changed files with 26 additions and 0 deletions
|
@ -4609,6 +4609,10 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
|
|||
if (fragment_flags.uses_normal) {
|
||||
enablers.push_back("#define NORMAL_USED\n");
|
||||
}
|
||||
if (fragment_flags.uses_normalmap) {
|
||||
enablers.push_back("#define USE_NORMALMAP\n");
|
||||
}
|
||||
|
||||
if (light_flags.uses_light) {
|
||||
enablers.push_back("#define USE_LIGHT_SHADER_CODE\n");
|
||||
}
|
||||
|
|
|
@ -243,6 +243,10 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
|
|||
if (vnode->name==vname_normal) {
|
||||
uses_normal=true;
|
||||
}
|
||||
if (vnode->name==vname_normalmap || vnode->name==vname_normalmap_depth) {
|
||||
uses_normalmap=true;
|
||||
uses_normal=true;
|
||||
}
|
||||
|
||||
if (vnode->name==vname_screen_uv) {
|
||||
uses_screen_uv=true;
|
||||
|
@ -810,6 +814,8 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
|
|||
|
||||
mode_replace_table[4]["POSITION"]="gl_Position";
|
||||
mode_replace_table[4]["NORMAL"]="normal";
|
||||
mode_replace_table[4]["NORMALMAP"]="normal_map";
|
||||
mode_replace_table[4]["NORMALMAP_DEPTH"]="normal_depth";
|
||||
mode_replace_table[4]["UV"]="uv_interp";
|
||||
mode_replace_table[4]["SRC_COLOR"]="color_interp";
|
||||
mode_replace_table[4]["COLOR"]="color";
|
||||
|
@ -861,6 +867,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
|
|||
vname_light="LIGHT";
|
||||
vname_time="TIME";
|
||||
vname_normalmap="NORMALMAP";
|
||||
vname_normalmap_depth="NORMALMAP_DEPTH";
|
||||
vname_normal="NORMAL";
|
||||
vname_texpixel_size="TEXTURE_PIXEL_SIZE";
|
||||
vname_world_vec="WORLD_VERTEX";
|
||||
|
|
|
@ -72,6 +72,7 @@ private:
|
|||
StringName vname_light;
|
||||
StringName vname_time;
|
||||
StringName vname_normalmap;
|
||||
StringName vname_normalmap_depth;
|
||||
StringName vname_normal;
|
||||
StringName vname_texpixel_size;
|
||||
StringName vname_world_vec;
|
||||
|
|
|
@ -207,7 +207,17 @@ void main() {
|
|||
|
||||
|
||||
{
|
||||
#if defined(USE_NORMALMAP)
|
||||
vec3 normal_map=vec3(0.0,0.0,1.0);
|
||||
float normal_depth=1.0;
|
||||
#endif
|
||||
|
||||
FRAGMENT_SHADER_CODE
|
||||
|
||||
#if defined(USE_NORMALMAP)
|
||||
normal = mix(vec3(0.0,0.0,1.0), normal_map * vec3(2.0,-2.0,1.0) - vec3( 1.0, -1.0, 0.0 ), normal_depth );
|
||||
#endif
|
||||
|
||||
}
|
||||
#ifdef DEBUG_ENCODED_32
|
||||
highp float enc32 = dot( color,highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) );
|
||||
|
|
|
@ -1350,6 +1350,8 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
|
|||
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"NormalMap","NORMALMAP","",SLOT_TYPE_VEC,SLOT_OUT},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"NormalMapDepth","NORMALMAP_DEPTH","",SLOT_TYPE_SCALAR,SLOT_OUT},
|
||||
//canvas item light in
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
|
||||
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
|
||||
|
|
|
@ -1145,6 +1145,8 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_fragment_builtins_defs[]={
|
|||
{ "SRC_COLOR", TYPE_VEC4},
|
||||
{ "POSITION", TYPE_VEC4},
|
||||
{ "NORMAL", TYPE_VEC3},
|
||||
{ "NORMALMAP", TYPE_VEC3},
|
||||
{ "NORMALMAP_DEPTH", TYPE_FLOAT},
|
||||
{ "UV", TYPE_VEC2},
|
||||
{ "COLOR", TYPE_VEC4},
|
||||
{ "TEXTURE", TYPE_TEXTURE},
|
||||
|
|
Loading…
Reference in a new issue