Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shader ';' : syntax error; parse error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Ashaira   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 April 2012 - 09:48 AM

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 ;

Sponsor:

#2 RobinsonUK   Members   -  Reputation: 108

Like
1Likes
Like

Posted 05 April 2012 - 10:35 AM

vec3 lightPos = (matWorld * vec4(0.0,1000.0,1000.0,1.0).xyz


I'm sure you need another closed bracket there.

#3 Ashaira   Members   -  Reputation: 105

Like
1Likes
Like

Posted 06 April 2012 - 01:02 AM

vec3 lightPos = (matWorld * vec4(0.0,1000.0,1000.0,1.0).xyz


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.

#4 Martins Mozeiko   Crossbones+   -  Reputation: 1413

Like
0Likes
Like

Posted 06 April 2012 - 01:10 AM

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

#5 Ashaira   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 April 2012 - 03:23 AM

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


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

#6 Brother Bob   Moderators   -  Reputation: 7780

Like
0Likes
Like

Posted 07 April 2012 - 01:50 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS