WebGL Shader compiling error


#1

I’m currently programming on a 3D canvas program and encountered an Error with compiling shaders…

Message:
webgl.js:82 ERROR compiling fragment shader. ERROR: 0:9: ‘varying’ : syntax error

shader.fs.glsl (fragment shader)

precision mediump float;

struct DirectionalLight
{
vec3 direction;
vec3 color;
}

varying vec2 fragTexCoord;
varying vec3 fragNormal;
uniform vec3 ambientLightIntensity;
uniform DirectionalLight sun;
uniform sampler2D sampler;
void main(){
vec3 surfeceNormal = normalize(fragNormal);
vec3 normSunlightDirection = normalize(sun.direction);
vec4 texel = texture2D(sampler, fragTexCoord);

vec3 lightIntensity = ambientLightIntensity + sun.color * max(dot(fragNormal, normSunlightDirection), 0.0);
gl_FragColor = vec4(texel.rgb * lightIntensity, texel.a);

}


#2

I think you simply forgot a semicolon after the struct, i.e.

struct DirectionalLight
{
vec3 direction;
vec3 color;
};


#3

thanks i didnt notice…