Can't Link Shader Program

Started by
6 comments, last by Cadoink 8 years, 5 months ago

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. :)

Advertisement

Try deleting MAX_NUM_LIGHTS. It doesnt appear you are using it, and may be complaining about any unused uniforms. Also, this is specific to openGL, not general graphics so it should have gone in that sub-forum.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Thank you for the reply. You were right! I didn't know you couldn't declare variables, and not use them. (I am going to be using MAX_NUM_LIGHTS in the future)

Also, I apologize for posting in the wrong forum. I wasn't sure since it was a GLSL question, and I am doing it in the context of WebGL.

In the future, I'll put GLSL questions in the OpenGL space. Thank you!

I believe this is GPU specific. Or maybe Nvidia specific? Might only happen on old cards.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Interesting. My cards aren't too old. I have a pair of gtx 770's.

But that is good to know. I can comment unused lines out until I get to using them. I really wish I could get errors like I had earlier. It was notifying me that I could not do


uniform int MAX_NUM_OF_LIGHTS = 4. 

So I'm still not sure how I'll define constants. I guess I'll just pass the constant in at the Javascript layer. It also notified me when I misspelled things.

Its tough developing without getting errors or without debugging. I had tried using gl.getShaderInfoLog, but I guess that doesn't work for errors in linking the program. My code using gl.CompileShader worked just fine.

Ahh! I actually discovered the real issue.

So I discovered this line of code ( I originally was trying to use getShaderInfoLog)


gl.getProgramInfoLog(shaderProgram)

It says that MAX_NUM_OF_LIGHTS is has different precision.


//In Vertex Shader
uniform int MAX_NUM_OF_LIGHTS;

//In Fragment Shader
uniform int MAX_NUM_OF_LIGHTS;

If I add lowp to each. It works.


//In Vertex Shader
uniform lowp int MAX_NUM_OF_LIGHTS;

//In Fragment Shader
uniform lowp int MAX_NUM_OF_LIGHTS;

What is going on here? Does the fragment shader and vertex shader use different default precision's?

This should give you an answer: http://stackoverflow.com/questions/5366416/in-opengl-es-2-0-glsl-where-do-you-need-precision-specifiers

The default precision in fragment and vertex shaders isn't the same smile.png Also be aware that you aren't using GLSL but "OpenGL ES Shading Language" (GLSL ES, if you want). Not the same.

Oh sweet! I didn't realize. I'll start looking for help with OpenGL ES from now on.

Thank you!

This topic is closed to new replies.

Advertisement