# Sahder nodes: input variable not defined while it should be

hi nehon,

can you have a look at this ?

v = worldViewMatrix * vec4(modelPosition,1.0); causes problem cos “v” is not used as input mapping by SimpleReflectionFrag shader node, but it is discarded globaly for some reason causing an error while it should not

error at bottom of this log :
see line 22, it is conditionaly defined but it should not

``````1    #version 150 core
2    #define DIFFUSEMAP 1
3    #define NORMALSMAP 1
4
5    uniform mat3 g_NormalMatrix;
6    uniform mat4 g_ViewMatrix;
7    uniform mat4 g_WorldViewMatrix;
8    uniform mat4 g_WorldMatrix;
9    uniform vec3 g_CameraPosition;
10    uniform mat4 g_WorldViewProjectionMatrix;
11
12    in vec3 inNormal;
13    in vec4 inTangent;
14    in vec2 inTexCoord;
15    in vec4 inPosition;
16
17    out vec3 NormalsMapVert_normal;
18    out vec2 MetalVert_texCoord;
19    out vec4 NormalsMapVert_lightDir;
20    out vec3 NormalsMapVert_eyeVec;
21    out vec4 NormalsMapVert_debug;
22    #if defined(SIMPLEREFLECTIONMAP)
23        out vec4 NormalsMapVert_v;
24    #endif
25
26    uniform vec4 g_LightPosition; // hack
27    uniform vec4 g_LightColor; // hack
28
29    // this funciton does some math tricks to compute the light dirrection and attenuation.
30    // Attenuation just resolves to 0 if it's a directional light or a spot light.
31    // Then in the lighting.frag, we compute the spotfalloff for the spot light.
32    // The angle cosines are packed into the 4th channel of the lightDirection.
33    // The spot falloff also resolves to 0 for a directional light.
34
35    void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
36        // 0 = Directional, 1 = Point, 2 = Spot
37        float posLight = step(0.5, color.w);    //Returns 0.0 if w < 0.5, otherwise it returns 1.0.
38        // sign : Returns 1.0 if x > 0, 0.0 if x = 0, or –1.0 if x < 0.
39        vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
40        vec3 lightVec = tempVec;
41        #ifdef ATTENUATION
42         float dist = length(tempVec);
43         lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
44         lightDir.xyz = tempVec / vec3(dist);
45        #else
46         lightDir = vec4(normalize(tempVec), 1.0);
47        #endif
48    }
49
50
51
52    void main(){
53        vec4 Global_position = inPosition;
54
55        //NormalsMapVert : Begin
56        vec3 NormalsMapVert_normalIn = inNormal;
57        vec4 NormalsMapVert_tangentIn = inTangent;
58        vec3 NormalsMapVert_modelPosition = Global_position.xyz;
59
60        NormalsMapVert_normal = normalize(g_NormalMatrix * NormalsMapVert_normalIn);
61        // Get the position in eye coordinates
62        NormalsMapVert_v = g_WorldViewMatrix * vec4(NormalsMapVert_modelPosition,1.0);
63
64        vec4 _lightColor=g_LightColor;
65        vec4 _lightPosition=g_LightPosition;
66
67        // light pos (world->view)
68        vec4 vLightPosition=vec4(g_ViewMatrix*vec4(_lightPosition.xyz,clamp(_lightColor.w,0.0,1.0)));
69        vLightPosition.w=_lightColor.w;
70
71        lightComputeDir(NormalsMapVert_v.xyz, _lightColor, vLightPosition, NormalsMapVert_lightDir);
72        NormalsMapVert_eyeVec = normalize(-NormalsMapVert_v.xyz);
73
74    #ifdef NORMALSMAP
75        vec3 tangent = normalize(g_NormalMatrix * NormalsMapVert_tangentIn.xyz);
76        vec3 binormal = cross(NormalsMapVert_normal, tangent);
77        //tbnMat matrix (view space to tangent space)
78        // The multiplication of the binormal is because some binormals need to be inverted depending on the triangle.
79        mat3 tbnMat = mat3(tangent, binormal/* * NormalsMapVert_tangentIn.w*/, NormalsMapVert_normal);
80        //we actually need to mult by the invert the matrix, to go from tangent space to view space
81        //with a normalized rotation matrix one can actually just transpose it instead of inverting it.
82        //=> mat * vec = vec * transpose(mat)
83        NormalsMapVert_lightDir = vec4(NormalsMapVert_lightDir.xyz*tbnMat,1);
84        NormalsMapVert_eyeVec = NormalsMapVert_eyeVec*tbnMat;
85    #else
86
87    #endif
88
89
90        //NormalsMapVert : End
91
92        //MetalVert : Begin
93        vec3 MetalVert_modelPosition = Global_position.xyz;
94        MetalVert_texCoord = inTexCoord;
95        vec4 MetalVert_projPosition;
96
97        MetalVert_projPosition = g_WorldViewProjectionMatrix * vec4(MetalVert_modelPosition, 1.0); //g_WorldViewProjectionMatrix=gl_ModelViewProjectionMatrix
98        Global_position = MetalVert_projPosition;
99        //MetalVert : End
100        gl_Position = Global_position;
101    }

com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Default.vert, defines, type=Vertex, language=GLSL150] error:0(62) : error C1008: undefined variable "NormalsMapVert_v"
0(71) : error C1008: undefined variable "NormalsMapVert_v"
0(72) : error C1008: undefined variable "NormalsMapVert_v"``````

here is the material definition

``````MaterialDef Simple {
MaterialParameters {
Texture2D GlowMap
Texture2D DiffuseMap
Texture2D SimpleReflectionMap
Texture2D NormalsMap
TextureCubeMap RefractionMap
TextureCubeMap ReflectionMap
Color Diffuse
Color SceneAmbient
Color Ambient
Color LightAmbient
Color LightDiffuse
Color Specular
Color LightSpecular
Float Shininess
Boolean Blinn
Float ReflectionAmount
Vector2 TextureOffset
}
Technique {
LightMode MultiPass
Defines {
}
WorldParameters {
WorldViewProjectionMatrix
NormalMatrix
WorldViewMatrix
WorldMatrix
ViewMatrix
CameraPosition
}
Definition : NormalsMapVert : Shaders/NormalsMap/NormalsMapVert.j3sn
InputMappings {
//normalsMap = MatParam.NormalsMap : NormalsMap
normalIn = Attr.inNormal
tangentIn = Attr.inTangent
modelPosition = Global.position.xyz
normalMatrix = WorldParam.NormalMatrix
viewMatrix = WorldParam.ViewMatrix
worldViewMatrix = WorldParam.WorldViewMatrix
worldMatrix = WorldParam.WorldMatrix
cameraPosition = WorldParam.CameraPosition
}
OutputMappings {
}
}
Definition : MetalVert : Shaders/Metal/MetalVert.j3sn
InputMappings {
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
modelPosition = Global.position.xyz
texCoord = Attr.inTexCoord
}
OutputMappings {
Global.position = projPosition
}
}
}
Definition : PrePhongFrag : Shaders/NormalsMap/PrePhongFrag.j3sn
InputMappings {
normalIn = NormalsMapVert.normal
texCoord = MetalVert.texCoord
normalsMap = MatParam.NormalsMap : NormalsMap
lightDirIn = NormalsMapVert.lightDir
eyeVecIn = NormalsMapVert.eyeVec
textureOffset = MatParam.TextureOffset : TextureOffset
}
}
Definition : PhongFrag : Shaders/Phong/PhongFrag.j3sn
InputMappings {
normal = PrePhongFragNormals.normal
lightDir = PrePhongFragNormals.lightDir
eyeVec = PrePhongFragNormals.eyeVec
blinn = MatParam.Blinn
sceneAmbient = MatParam.SceneAmbient
ambient = MatParam.Ambient
diffuseMap = MatParam.DiffuseMap : DiffuseMap
specular = MatParam.Specular
shininess = MatParam.Shininess
lightAmbient = MatParam.LightAmbient
lightDiffuse = MatParam.LightDiffuse
lightSpecular = MatParam.LightSpecular
texCoord = MetalVert.texCoord
debug = NormalsMapVert.debug
textureOffset = MatParam.TextureOffset : TextureOffset
}
}
Definition : SimpleReflectionFrag : Shaders/SimpleReflection/SimpleReflectionFrag.j3sn
Condition : SimpleReflectionMap
InputMappings {
v = NormalsMapVert.v
normal = NormalsMapVert.normal
lambertTerm = PhongFragNormals.lambertTerm
simpleReflectionMap = MatParam.SimpleReflectionMap : SimpleReflectionMap
}
}
Definition : ReflectionFrag : Shaders/Reflection/ReflectionFrag.j3sn
Condition : ReflectionMap
InputMappings {
normal = PrePhongFragNormals.normal
eyeVec = PrePhongFragNormals.eyeVec
reflectionMap = MatParam.ReflectionMap : ReflectionMap
}
}
Definition : MetalFrag : Shaders/Metal/MetalFrag.j3sn
InputMappings {
lightingColor = PhongFragNormals.outColor
reflectionColor = ReflectionFrag.outColor : ReflectionMap
reflectionColor = SimpleReflectionFrag.outColor : SimpleReflectionMap
reflectionAmount = MatParam.ReflectionAmount
diffuse = MatParam.Diffuse : Diffuse
}
OutputMappings {
Global.color = outColor
}
}
}
}

Technique Glow {

WorldParameters {
WorldViewProjectionMatrix
}

Defines {
NEED_TEXCOORD1
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor

NUM_BONES : NumberOfBones
}
}

}
``````

NormalsMap.vert

``````main(){
normal = normalize(normalMatrix * normalIn);

// Get the position in eye coordinates
v = worldViewMatrix * vec4(modelPosition,1.0);

vec4 _lightColor=g_LightColor;
vec4 _lightPosition=g_LightPosition;

// light pos (world->view)
vec4 vLightPosition=vec4(viewMatrix*vec4(_lightPosition.xyz,clamp(_lightColor.w,0.0,1.0)));
vLightPosition.w=_lightColor.w;

lightComputeDir(v.xyz, _lightColor, vLightPosition, lightDir);
eyeVec = normalize(-v.xyz);

...
``````

``````ShaderNodesDefinitions
{
{
Type: Vertex
Documentation
{
@input normalMatrix
@input worldViewMatrix
@input modelPosition
@input normal
}
Input
{
sampler2D normalsMap
vec3 cameraPosition
mat4 viewMatrix
mat4 worldMatrix
mat3 normalMatrix
mat4 worldViewMatrix
vec3 modelPosition
vec3 normalIn
vec4 tangentIn
}
Output
{
vec4 lightDir
vec3 normal
vec4 v
vec3 eyeVec
vec4 debug
vec3 modelPosition
}
}
}``````

thx

Mhh yeah I see, the condition is also used in the vertex shader even when declared in the frag shader.
That looks like a bug indeed. I’ll look into it

thanks

did you had some time to look at it ?