Hey, guys. I've been trying to implement lighting. I had it working previously, but I am trying to refactor it to work better and to add specular light. I will also be trying to extend it to use multiple lights.
Anyway, I hit a snag. I had a ton of errors in my shader programs (I am super new to GLSL). I managed to fix all the errors that were popping up in Chrome, but there must still be some error because my program will no longer link.
Here are the shaders:
<script id="shader-fs" type="x-shader/x-fragment">
uniform int MAX_NUM_OF_LIGHTS;
varying highp vec2 vTextureCoord;
varying mediump vec3 vNormal;
varying mediump vec3 vLight;
uniform mediump vec3 vLightColor;
uniform sampler2D uSampler;
uniform highp float uShineDamper;
uniform highp float uReflectivity;
void main(void) {
mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
mediump vec3 unitNormal = normalize(vNormal);
mediump vec3 unitLight = normalize(vLight);
mediump float brightness = max(dot(unitNormal, unitLight), 0.0);
mediump vec3 diffuse = brightness * vLightColor;
gl_FragColor = vec4(texelColor.rgb * diffuse, texelColor.a);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
uniform int MAX_NUM_OF_LIGHTS;
//Model Attributes
attribute highp vec3 aVertexNormal;
attribute highp vec3 aVertexPosition;
attribute highp vec2 aTextureCoord;
//Light Uniforms
uniform mediump vec3 uLightPosition;
//MVP Matrix Uniforms
uniform highp mat4 uVMatrix;
uniform highp mat4 uMMatrix;
uniform highp mat4 uPMatrix;
varying highp vec2 vTextureCoord;
varying mediump vec3 vNormal;
varying mediump vec3 vLight;
void main(void) {
vec4 worldPosition = uMMatrix * vec4(aVertexPosition, 1.0);
gl_Position = uPMatrix * uVMatrix * worldPosition;
vTextureCoord = aTextureCoord;
vNormal = (uMMatrix * vec4(aVertexNormal, 0.0)).xyz;
vLight = uLightPosition - worldPosition.xyz;
}
</script>
I thought it maybe had to do with my precision, but I am not quite sure. If anyone has any advice, or see's the problem, please let me know.
It's hard not being able to debug GLSL. ^^
Thank you. :)