• Advertisement
Sign in to follow this  

Strange Shader Link Error / LWJGL

This topic is 2568 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


i am using LWJGL which works quite fine until i tried to use a geometry shader. I get a strange error while linking my shader code.
Here is the Shader-Code (Vert, Geom, Frag) first:

#version 330 core
#extension GL_ARB_uniform_buffer_object : enable
precision highp float;

#define ATTR_NORMAL 1
#define ATTR_COLOR 2
#define ATTR_TEXCOORD0 3

layout(location = ATTR_POSITION) in vec3 gs_Vertex;
layout(location = ATTR_NORMAL) in vec3 gs_Normal;
layout(location = ATTR_COLOR) in vec4 gs_Color;
layout(location = ATTR_TEXCOORD0) in vec4 gs_MultiTexCoord0;

layout(std140) uniform transform {
mat4 ModelMatrix;
mat4 ModelViewMatrix;
mat4 ViewMatrix;
mat4 InvViewMatrix;
mat4 NormalMatrix;
mat4 ProjectionMatrix;
vec3 cameraPosition;
vec3 viewDir;
} Transform;

uniform samplerBuffer InstanceData;

uniform vec3 skyLightDir;
uniform vec3 FogColor;

out vec4 FogParamVtoG;
out vec4 gs_TexCoordVtoG[8];
out vec4 vertColorVtoG;
out vec3 skyLightDirVtoG;
out vec3 viewDirVtoG;
out vec3 normalVtoG;
out vec3 cameraPositionVtoG;

float inCircle(vec4 vertex, mat4 ModelViewMat){
return length(vertex - ModelViewMat * vec4(Transform.cameraPosition, 1.0));

void main(){
vec4 viewSpacePosition = Transform.ModelViewMatrix * vec4(gs_Vertex, 1.0);
gl_Position = Transform.ProjectionMatrix * viewSpacePosition;

// calculate fog related information
FogParamVtoG.xyz = FogColor;
FogParamVtoG.w = exp(length(viewSpacePosition.xyz) / 50.0) / 2.6;

// Pass through
vertColorVtoG = gs_Color;
normalVtoG = vec3(Transform.NormalMatrix * vec4(gs_Normal, 0.0));
gs_TexCoordVtoG[0] = gs_MultiTexCoord0;
viewDirVtoG = -viewSpacePosition.xyz;
//skyLightDirOut = vec3(Transform.ViewMatrix * vec4(skyLightDir, 1.0)) - viewSpacePosition.xyz;
skyLightDirVtoG = vec3(0.0, 1.0, 1.0);
cameraPositionVtoG = Transform.cameraPosition;

Geometry-Shader (just trying to get it to work, only pass-though until now:
#version 330 core
#extension GL_EXT_geometry_shader4 : enable
precision highp float;

varying in vec4 FogParamVtoG[gl_VerticesIn];
varying in vec4 gs_TexCoordVtoG[gl_VerticesIn][8];
varying in vec4 vertColorVtoG[gl_VerticesIn];
varying in vec3 skyLightDirVtoG[gl_VerticesIn];
varying in vec3 viewDirVtoG[gl_VerticesIn];
varying in vec3 normalVtoG[gl_VerticesIn];
varying in vec3 cameraPositionVtoG[gl_VerticesIn];

varying out vec4 FogParamGtoF;
varying out vec4 gs_TexCoordGtoF[8];
varying out vec4 vertColorGtoF;
varying out vec3 skyLightDirGtoF;
varying out vec3 viewDirGtoF;
varying out vec3 normalGtoF;
varying out vec3 cameraPositionGtoF;

void main(void)
//increment variable
int i;

for(i=0; i< gl_VerticesIn; i++){
gl_Position = gl_PositionIn;
FogParamGtoF = FogParamVtoG;
gs_TexCoordGtoF[0] = gs_TexCoordVtoG[0];
vertColorGtoF = vertColorVtoG;
skyLightDirGtoF = skyLightDirVtoG;
viewDirGtoF = viewDirVtoG;
normalGtoF = normalVtoG;
cameraPositionGtoF = cameraPositionVtoG;

#version 330 core
precision highp float;

in vec4 FogParamGtoF;
in vec4 gs_TexCoordGtoF[8];
in vec4 vertColorGtoF;
in vec3 skyLightDirGtoF;
in vec3 viewDirGtoF;
in vec3 normalGtoF;
in vec3 cameraPositionGtoF;

out vec4 FragmentColor;

uniform vec4 AmbientColor;
uniform sampler2D TestTexture;

void main(){
vec4 color = vertColorGtoF;
//vec4 color = texture2D(TestTexture, gs_TexCoordGtoF[0].st);

vec3 Normal = normalize(normalGtoF);
vec3 ViewDir = normalize(viewDirGtoF);
vec3 LightDir = normalize(skyLightDirGtoF);
vec3 Reflection = normalize(reflect(Normal, LightDir));

vec3 half_vector = normalize(LightDir + ViewDir);
float HdotN = max( 0.0f, dot( half_vector, Normal ) );
float specular = 1.5 * pow( HdotN, 300 );
float diffuse = 0.6 * max( 0.0f, dot( Normal, LightDir ) );
FragmentColor = color * vec4( 0.3 + diffuse + specular, 0.3 + diffuse + specular, 0.3 + diffuse + specular, 1.0f );

(Wrong names are due to copy and paste, i am switching names sometimes to take the geom shader out. Varyings have to have different names then to pass from vertex to fragment shader)
Vertex and Fragment together are working just fine. Adjusting the names of the varying variables works fine, the shaders compile (no error message).
The messages are:
Shader: normalShader2
Info log:
Vertex shader was successfully compiled to run on hardware.

Shader: normalShader2
Info log:
Geometry shader was successfully compiled to run on hardware.

Shader: normalShader2
Info log:
Fragment shader was successfully compiled to run on hardware.

Calling GL20.glUseProgram(normalShader2.getShaderID()); produces this error message and i have no clue where the error could be. Maybe someone can help:
Shader: normalShader2
Info log:
Fragment shader(s) failed to link, vertex shader(s) failed to link.
ERROR: error(#277) Symbol '' usage doesn't match between two stages
ERROR: error(#277) Symbol '' usage doesn't match between two stages

Before cleaning up the names i got similar warnings but all related to varyings. This is strange.

Share this post

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

  • Advertisement