PDA

View Full Version : Why isn't my shader linking?



Aumnayan
08-16-2012, 02:34 PM
I'm having a bit of a problem linking my shaders. They seam to build fine, but the vertex shader continually fails to link, without indicating what's causing the link to fail. I've included source for a simple app which builds and links the shaders, which I am using to test at the moment, since I can't seam to get to the point where I'm evaluating what the shaders are doing to the screen. Any ideas?

My current shaders:

GLchar *TerrainVertexShaderStr[] = {
(GLchar*) "#version 120\n",
(GLchar*) "uniform sampler2D vertTexture; \n",
(GLchar*) "uniform sampler2D normTexture; \n",
(GLchar*) "uniform vec3 sunpos; \n",
(GLchar*) "uniform vec4 transMatrix; \n",
(GLchar*) "in vec2 vPosition; \n",
(GLchar*) "out float color; \n",
(GLchar*) "out float diff; \n",
(GLchar*) "void main () { \n",
(GLchar*) " vec2 tpos = vec2(vPosition.xy); \n",
(GLchar*) " tpos.x = (tpos.x * transMatrix.b) + transMatrix.r; \n",
(GLchar*) " tpos.y = (tpos.y * transMatrix.a) + transMatrix.g; \n",
(GLchar*) " vec4 vert = texture(vertTexture, tpos); \n",
(GLchar*) " vec3 norm = texture(normTexture, tpos).xyz; \n",
(GLchar*) " color = clamp(((vert.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f); \n",
(GLchar*) " diff = clamp(dot(norm.xyz, normalize(sunpos - vert.xyz)), 0.6f, 1.0f); \n",
(GLchar*) " gl_Position = gl_ModelViewProjectionMatrix * vert; \n",
(GLchar*) "}"
};

GLchar *TerrainFragmentShaderStr[] = {
(GLchar*) "#version 120\n",
(GLchar*) "uniform sampler1D colorTexture; \n",
(GLchar*) "uniform sampler2D grndTexture; \n",
(GLchar*) "in float color; \n",
(GLchar*) "in float diff; \n",
(GLchar*) "void main () { \n",
(GLchar*) " vec4 vcolor = texture1D(colorTexture, color); \n",
//" vec4 tcolor = texture(grndTexture, texCrd); \n",
(GLchar*) " gl_FragColor = vcolor * diff; \n",
(GLchar*) "}"
};

The output from my execution:

OpenGL Version: 2.1.8543 Release
GLSL Version: 1.20
Compiling vertex shader:
Vertex shader was successfully compiled to run on hardware.

Compiling fragment shader:
Fragment shader was successfully compiled to run on hardware.

Creating progrem:
Fragment shader(s) linked, vertex shader(s) failed to link.

Alfonse Reinheart
08-16-2012, 09:55 PM
#version 120
...
in vec2 vPosition;
out float color;
out float diff;


`in` and `out` are defined in GLSL 1.30 and above. You should be getting a compiler error in your shader compiling.

Aumnayan
08-17-2012, 08:07 AM
That odd, considering the previous incarnation of this shader (below) compiled and linked fine. And the problems I'm experiencing are in the linker and not the compiler. This is being run on a Radeon X1200, changing it isn't an option. The only real difference between the two is that I'm grabbing a couple of texel's with texture2D calls.

This is supported in GLSL 1.20, and I haven't been able to find anything saying the drivers I'm using are an exception to that.

My previous working shader:

"#version 120\n",
"uniform vec3 sunpos; \n",
"in vec4 vPosition; \n",
"in vec3 vNormal; \n",
"in vec4 vColor; \n",
"in vec2 vTexCoord; \n",
"out vec2 texCrd; \n",
"out float color; \n",
"out float diff; \n",
"void main () { \n",
" texCrd = vTexCoord; \n",
" color = clamp(((gl_Vertex.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f); \n",
" diff = clamp(dot(vNormal.xyz, normalize(sunpos - gl_Vertex.xyz)), 0.6f, 1.0f); \n",
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n",
"}"
};

aqnuep
08-17-2012, 08:16 AM
As far as I remember, for pre-HD2000 Radeon cards the drivers seem to not do anything at compile time but the compilation was also done at link time thus despite you don't get an actual compile error but a link error, it is most likely because of the 'in' and 'out' stuff. As Alfonse noted, those are only available in GLSL 1.30 which was introduced together with OpenGL 3.0 which targeted HD2000+ cards thus it's definitely not supported on the X1200. So please try to use a valid shader at least as what you wrote (even if the first version happened to work) is just not a valid GLSL 1.20 shader.

Aumnayan
08-17-2012, 08:46 AM
I apologise. I shouldn't ask for help then dump on the response given when it goes contrary to what I understand, since if I understood it I wouldn't need to ask. I've modified the shaders to be the following, which I believe are valid 1.2 shaders.

I'm getting the same error. As informative as the error "vertex shader (s) failed to link" is.


GLchar *TerrainVertexShaderStr[] = {
(GLchar*) "#version 120\n",
(GLchar*) "uniform sampler2D vertTexture; \n",
(GLchar*) "uniform sampler2D normTexture; \n",
(GLchar*) "uniform vec3 sunpos; \n",
(GLchar*) "uniform vec4 transMatrix; \n",
(GLchar*) "attribute vec2 vPosition; \n",
(GLchar*) "varying vec2 texCrd; \n",
(GLchar*) "varying float color; \n",
(GLchar*) "varying float diff; \n",
(GLchar*) "void main () { \n",
(GLchar*) " vec2 tpos = vec2(gl_Vertex.xy); \n",
(GLchar*) " tpos.x = (tpos.x * transMatrix.b) + transMatrix.r; \n",
(GLchar*) " tpos.y = (tpos.y * transMatrix.a) + transMatrix.g; \n",
(GLchar*) " vec4 vert = texture2D(vertTexture, tpos).xyzw; \n",
(GLchar*) " vec3 norm = texture2D(normTexture, tpos).xyz; \n",
(GLchar*) " color = clamp(((vert.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f); \n",
(GLchar*) " diff = clamp(dot(norm.xyz, normalize(sunpos - vert.xyz)), 0.6f, 1.0f); \n",
(GLchar*) " texCrd = vec2(vPosition.xy); \n",
(GLchar*) " gl_Position = gl_ModelViewProjectionMatrix * vert; \n",
(GLchar*) "}"
};

GLchar *TerrainFragmentShaderStr[] = {
(GLchar*) "#version 120\n",
(GLchar*) "uniform sampler1D colorTexture; \n",
(GLchar*) "uniform sampler2D grndTexture; \n",
(GLchar*) "varying vec2 texCrd; \n",
(GLchar*) "varying float color; \n",
(GLchar*) "varying float diff; \n",
(GLchar*) "void main () { \n",
(GLchar*) " vec4 vcolor = texture1D(colorTexture, color); \n",
(GLchar*) " vec4 tcolor = texture2D(grndTexture, texCrd); \n",
(GLchar*) " gl_FragColor = vcolor * diff; \n",
(GLchar*) "}"
};

Any other pointers?

Aumnayan
08-17-2012, 09:25 AM
It seams as though I'm SOL with regards to using textures in my vertex shader. Another user with a similar problem (http://www.opengl.org/discussion_boards/showthread.php/178779-Trouble-accessing-texture-data-from-the-vertex-shader?goto=newpost) found a solution and got me thinking about things and unless I'm mistaken when a call to


glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &value)

returns 0, nothing I try is going to get a sampler2D to work in the vertex shader.

Thank you for the info on in/out, and your help to date.