GLSL Undeclared Identifier

I’ve been working on vertex lighting recently with shaders (obviously), but I’ve ran into an issue. Now, forgive me if there is an apparent fix, but I barely know GLSL. So, I’ll show you how I set up my shaders:

	private void setupShaders(){
		Shader geomShaders = new Shader("res/landscape.vert", "res/landscape.frag");
		geomProgram = new ShaderProgram(geomShaders.getvShader(), geomShaders.getfShader());
		
		glUniform1i(glGetUniformLocation(geomProgram.getProgram(), "lookup"), 0);
		
		Shader lightShaders = new Shader("res/lighting.vert", "res/lighting.frag");
		lightProgram = new ShaderProgram(lightShaders.getvShader(), lightShaders.getfShader());
		
	}

ShaderProgram and Shader are just some shader parsing utilities I created, they aren’t the problem because I’ve already used them before lots. Here is my vertex shader:

varying vec3 color;

void main(){

	vec3 vertexPos = (gl_ModelViewMatrix * gl_Vertex).xyz;
	vec3 lightDir = normalize(gl_LightSource[0].position.xyz - vertexPos);
	vec3 surfaceNormal = (gl_NormalMatrix * gl_Normal).xyz;

	float diffuseIntensity = max(0, dot(surfaceNormal, lightDir));
	color.rgb = diffuseIntensity * gl_FrontMaterial.diffuse.rgb;
	color += gl_LightModel.ambient.rgb;	
	
	vec3 reflectDir = normalize(reflect(-lightDir, surfaceNormal));
	float specular = max(0.0, dot(surfaceNormal, reflectDir));
	if(diffuseIntesity != 0){
		float fspecular = pow(specular, gl_FrontMaterial.shininess);
		color.rgb += vec3(fspecular, fspecular, fspecular);
	}

	gl_Position = gl_ModelViewMatrix * gl_Vertex;	
	
}

And my fragment shader:

varying vec3 color;

void main(){
	gl_FragColor = vec4(varyingColor, 1);
}

And this is how I set up the lights:

private void setupLighting(){
		glShadeModel(GL_SMOOTH);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		glLightModel(GL_LIGHT_MODEL_AMBIENT, BufferTools.asFlippedFloatBuffer(new float[]{0.05f, 0.05f, 0.05f, 1f}));
		glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(new float[]{-70, -15, -30, 1}));
		glEnable(GL_COLOR_MATERIAL);
		glColorMaterial(GL_FRONT, GL_DIFFUSE);
		glColor3f(0.4f, 0.27f, 0.17f);
	}

When I run this, I get the following errors;

Vertex shader failed to compile with the following errors:
ERROR: 0:15: error(#143) Undeclared identifier: diffuseIntesity
ERROR: error(#273) 1 compilation errors.  No code generated


Error compiling vertex shader at Shader.java location: res/lighting.vert
Fragment shader failed to compile with the following errors:
ERROR: 0:4: error(#143) Undeclared identifier: varyingColor
ERROR: 0:4: error(#174) Not enough data provided for construction constructor
ERROR: error(#273) 2 compilation errors.  No code generated


Error compiling fragment shader at Shader.java location: res/lighting.frag
Vertex shader failed to compile with the following errors:
ERROR: 0:15: error(#143) Undeclared identifier: diffuseIntesity
ERROR: error(#273) 1 compilation errors.  No code generated


Error compiling vertex shader at Shader.java location: res/lighting.vert
Fragment shader failed to compile with the following errors:
ERROR: 0:4: error(#143) Undeclared identifier: varyingColor
ERROR: 0:4: error(#174) Not enough data provided for construction constructor
ERROR: error(#273) 2 compilation errors.  No code generated

What does it mean undeclared identifier? I’ve declared them all, and I’ve set the color using glColor3f in the setuplighting method. I quite honestly have no idea how to solve this, so I’m hoping someone can help!

You have typos in your code. In the vertex shader, this line:

if(diffuseIntesity != 0){

it should be “diffuseIntensity” instead of “diffuseIntesity”.

In the fragment shader, you should use “color” instead of “varyingColor”.

And always use floats (so 0.0 instead of 0, and 1.0 instead of 1) as there are some drivers that otherwise break. Especially Intel ones :slight_smile:

Mike

If you specify #version 120 or higher, implicit floats should be supported.

In the vertex shader, change line 15 to


if (diffuseIntensity != 0.0){

And in the fragment shader, change line 4 to


gl_FragColor = vec4(color, 1.0);

Hope this helps.