Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  GLSL Undeclared Identifier  (Read 2643 times)
0 Members and 1 Guest are viewing this topic.
Offline thunderfist123

Senior Newbie





« Posted 2013-11-10 14:40:55 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
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:
1  
2  
3  
4  
5  
varying vec3 color;

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

And this is how I set up the lights:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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;
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
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!
Offline Spasi
« Reply #1 - Posted 2013-11-10 14:57:52 »

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

1  
if(diffuseIntesity != 0){

it should be "diffuseIntensity" instead of "diffuseIntesity".

In the fragment shader, you should use "color" instead of "varyingColor".
Offline Mike

« JGO Spiffy Duke »


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #2 - Posted 2013-11-10 15:43:58 »

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 Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-11-10 17:17:14 »

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 Smiley

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

Offline SHC
« Reply #4 - Posted 2013-11-11 12:44:42 »

In the vertex shader, change line 15 to

1  
if (diffuseIntensity != 0.0){

And in the fragment shader, change line 4 to

1  
gl_FragColor = vec4(color, 1.0);

Hope this helps.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (70 views)
2014-11-26 15:22:04

toopeicgaming1999 (59 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!