Jump to content
  • Advertisement
Sign in to follow this  
Cadoink

Can't Link Shader Program

This topic is 1082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

Share this post


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

Edited by dpadam450

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Edited by Cadoink

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!