- Home /
Question by
Somian · Apr 29, 2016 at 02:01 PM ·
shadercharactercontrollerglsl
GLSL shader won't compile
Hi,
I have this shader that doesn't really do anything yet. for some reason, however, I get "syntax error" where I define the varying vec4 "uv"
Shader "Blocker/FloorScreen"
{
Properties
{
floorTex ("Floor", 2D) = "white" {}
}
SubShader
{
Pass
{
GLSLPROGRAM
uniform sampler2D floorTex;
varying vec4 uv;
#ifdef VERTEX
void main()
{
uv = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
void main()
{
gl_FragColor = texture2D(floorTex, vec2(uv));
}
#endif
ENDGLSL
}
}
}
I simply can't see what's wrong with this oO
Comment
Is "uv" a reserved keyword in GLSL? Have you tried rena$$anonymous$$g it to something else?
yeah, it had a different name before. same problem.
the full error is
GLSL compilation failed: ERROR: 0:20: 'varying' : syntax error: syntax error
can't it cope with varyings anymore? :D
Best Answer
Answer by Somian · Apr 29, 2016 at 02:44 PM
Ok, I changed it to...
GLSLPROGRAM
uniform sampler2D floorTex;
#ifdef VERTEX
varying vec4 uv;
void main()
{
uv = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
varying vec4 uv;
void main()
{
gl_FragColor = texture2D(floorTex, vec2(uv));
//gl_FragColor = vec4(1.0,1.0,0.8,0.5);
}
I moved the definition of uv into the vertex and pixel shader separately. This works now. Strange, though. Shouldn't the other way work, too?