Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shader ';' : syntax error; parse error

Started by Ashaira Apr 5, 2012 at 3:48 PM 4 replies 4.6k views
Original Post
Ashaira
Ashaira
I'm working on adding normal map lighting to my terrain shader and for some reason i get a syntax error when it compiles but i cant find whats wrong with it. i added a total of nor more than 15 lines from the previous ver which compiled and worked fine.

this is what it looks like with the modifications for the normal map.

# Vertex Shader Start
uniform mat4 u_MVP;

attribute vec3 aPosition;
varying vec3 vPosition;

attribute vec2 a_texCoord;
varying vec2 v_texCoord;
attribute vec3 a_Tangents;
varying vec3 v_Tangents;
attribute vec3 a_Bitangents;
varying vec3 v_Bitangents;
uniform mat4 matWorld;
uniform vec3 CameraPos;
varying float v_eyeDist;
uniform sampler2D texture5;
attribute vec3 a_Normals;
varying vec3 v_Normals;
varying vec3 v_viewDirection;
varying vec3 v_lightDirection;

void main()
{
vPosition = aPosition;
v_texCoord = a_texCoord;
v_Normals = normalize(vec3(matWorld * vec4(a_Normals, 0.0)));
vec4 tmp5 = texture2D(texture5,v_texCoord);
vPosition.y = vPosition.y + ((tmp5.r + tmp5.g*2.0 + tmp5.b*3.0)/10.0) * 20.0;
vec4 vWorldPos = matWorld * vec4(vPosition,1.0);
v_eyeDist = sqrt( (vWorldPos.x - CameraPos.x) * (vWorldPos.x - CameraPos.x) + (vWorldPos.y - CameraPos.y) * (vWorldPos.y - CameraPos.y) + (vWorldPos.z - CameraPos.z) * (vWorldPos.z - CameraPos.z) );

vec3 viewDirectionWorld = vWorldPos.xyz - vPosition;
vec3 lightPos = (matWorld * vec4(0.0,1000.0,1000.0,1.0).xyz;
vec3 lightDirection = lightPos - vPosition;
mat3 tangentMat = mat3(a_Tangents,a_Bitangents,a_Normals);
v_viewDirection = viewDirectionWorld * tangentMat;
v_lightDirection = lightDirection * tangentMat;
gl_Position = u_MVP * vec4(vPosition,1.0);
}
# Vertex Shader End
# Fragment Shader Start
precision highp float;
varying vec2 v_texCoord;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
uniform sampler2D texture6;
varying vec3 v_Normals;
varying vec3 v_viewDirection;
varying vec3 v_lightDirection;
varying float v_eyeDist;

float computeLinearFogFactor()
{
float u_fogMaxDist = 10.0;
float u_fogMinDist = 1.0;
float factor;

factor = (v_eyeDist - u_fogMinDist) /(u_fogMaxDist - u_fogMinDist );

factor = clamp(factor, 0.0, 1.0);
return factor;
}

void main()
{
vec4 u_fogColor = vec4(0.7,0.7,0.7,1.0);
float fogFactor = computeLinearFogFactor();
vec4 tmp1 = texture2D(texture1,v_texCoord*32.0);
vec4 tmp2 = texture2D(texture2,v_texCoord*32.0);
vec4 tmp3 = texture2D(texture3,v_texCoord*32.0);
vec4 tmp4 = texture2D(texture4,v_texCoord);
float factor = 1.0 / ( tmp4.x + tmp4.y + tmp4.z );
vec4 tmp = vec4( (tmp1.rgb * tmp4.x + tmp2.rgb * tmp4.y + tmp3.rgb * tmp4.z) * factor, 1.0 );
vec4 lightColor = vec4(1.0,1.0,1.0,1.0);
vec4 normal = texture2D(texture6, v_texCoord);
normal = normalize(normal * 2.0 - 1.0);
vec3 lightDirection = normalize(v_lightDirection);
vec3 viewDirection = normalize(v_viewDirection);
float nDotL = dot(normal.xyz, lightDirection);
vec3 reflection = (2.0 * normal.xyz * nDotL) - lightDirection;
float rDotV = max(0.0, dot(reflection, viewDirection));
vec4 ambient = lightColor * tmp;
vec4 diffuse = lightColor * nDotL * tmp;
vec4 specular = lightColor * pow(rDotV, 2.0);
vec4 FinalColor = diffuse + specular + ambient;
gl_FragColor = fogFactor * u_fogColor + (1.0 - fogFactor) * FinalColor;
}
# Fragment Shader End


and these are the lines that where added and are probably causing the error.

vec3 viewDirectionWorld = vWorldPos.xyz - vPosition;
vec3 lightPos = (matWorld * vec4(0.0,1000.0,1000.0,1.0).xyz;
vec3 lightDirection = lightPos - vPosition;
mat3 tangentMat = mat3(a_Tangents,a_Bitangents,a_Normals);
v_viewDirection = viewDirectionWorld * tangentMat;
v_lightDirection = lightDirection * tangentMat;


vec4 lightColor = vec4(1.0,1.0,1.0,1.0);
vec4 normal = texture2D(texture6, v_texCoord);
normal = normalize(normal * 2.0 - 1.0);
vec3 lightDirection = normalize(v_lightDirection);
vec3 viewDirection = normalize(v_viewDirection);
float nDotL = dot(normal.xyz, lightDirection);
vec3 reflection = (2.0 * normal.xyz * nDotL) - lightDirection;
float rDotV = max(0.0, dot(reflection, viewDirection));
vec4 ambient = lightColor * tmp;
vec4 diffuse = lightColor * nDotL * tmp;
vec4 specular = lightColor * pow(rDotV, 2.0);
vec4 FinalColor = diffuse + specular + ambient;


can anyone see where the problem might be? or at least hint me as to what exactly the error is about cause i sure as hell checked all the ;
RobinsonUK
RobinsonUK
[color=#000000]vec3 lightPos [color=#666600]=[color=#000000] [color=#666600]([color=#000000]matWorld [color=#666600]*[color=#000000] vec4[color=#666600]([color=#006666]0.0[color=#666600],[color=#006666]1000.0[color=#666600],[color=#006666]1000.0[color=#666600],[color=#006666]1.0[color=#666600]).[color=#000000]xyz


[color=#000000]I'm sure you need another closed bracket there.
Ashaira
Ashaira

[color=#000000]vec3 lightPos [color=#666600]=[color=#000000] [color=#666600]([color=#000000]matWorld [color=#666600]*[color=#000000] vec4[color=#666600]([color=#006666]0.0[color=#666600],[color=#006666]1000.0[color=#666600],[color=#006666]1000.0[color=#666600],[color=#006666]1.0[color=#666600]).[color=#000000]xyz


[color=#000000]I'm sure you need another closed bracket there.

"facepalm.jpg"
um im just go over to that corner and hang myself. ty for the help.
bubu LV
bubu LV
Doesn't the error log mention line number in shader source where the error is?
Ashaira
Ashaira

Doesn't the error log mention line number in shader source where the error is?


mine always says line 1 so.......
Brother Bob
Brother Bob
Then your shader code is most likely loaded without line breaks. Verify that each line of shader code is actually separated by a line break and that they aren't lost when you load the shader.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.