Sign in to follow this  
Ashaira

Shader ';' : syntax error; parse error

Recommended Posts

Ashaira    105
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.

[code]# 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 [/code]

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

[code] 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;[/code]

[code] 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; [/code]

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 ;

Share this post


Link to post
Share on other sites
RobinsonUK    108
[color=#000000]vec3 lightPos [/color][color=#666600]=[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]matWorld [/color][color=#666600]*[/color][color=#000000] vec4[/color][color=#666600]([/color][color=#006666]0.0[/color][color=#666600],[/color][color=#006666]1000.0[/color][color=#666600],[/color][color=#006666]1000.0[/color][color=#666600],[/color][color=#006666]1.0[/color][color=#666600]).[/color][color=#000000]xyz[/color]


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

Share this post


Link to post
Share on other sites
Ashaira    105
[quote name='RobinsonUK' timestamp='1333643756' post='4928524']
[color=#000000]vec3 lightPos [/color][color=#666600]=[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]matWorld [/color][color=#666600]*[/color][color=#000000] vec4[/color][color=#666600]([/color][color=#006666]0.0[/color][color=#666600],[/color][color=#006666]1000.0[/color][color=#666600],[/color][color=#006666]1000.0[/color][color=#666600],[/color][color=#006666]1.0[/color][color=#666600]).[/color][color=#000000]xyz[/color]


[color=#000000]I'm sure you need another closed bracket there.[/color]
[/quote]
"facepalm.jpg"
um im just go over to that corner and hang myself. ty for the help.

Share this post


Link to post
Share on other sites
Ashaira    105
[quote name='Martins Mozeiko' timestamp='1333696244' post='4928693']
Doesn't the error log mention line number in shader source where the error is?
[/quote]

mine always says line 1 so.......

Share this post


Link to post
Share on other sites
Brother Bob    10344
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this