Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  Uniform locations return -1  (Read 774 times)
0 Members and 1 Guest are viewing this topic.
Offline Spacebeans
« Posted 2014-05-24 18:55:12 »

Sorry for all the GLSL topics, I'm having bug after bug...

My fragment shader has two uniform samplers:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
...
uniform sampler2D t_diffuse;
uniform sampler2D t_specular;
...
 
void main() {
   vec4 diffuse = texture2D(t_diffuse, gl_TexCoord[0].st).rgba;
   vec4 specular = texture2D(t_specular, gl_TexCoord[0].st).rgba;
   ...  
   gl_FragColor = specular;
}


I access them with: (Per frame)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   glActiveTexture(GL_TEXTURE0);
   testTexture.bind();
   texLoc = glGetUniformLocation(world.getLightingProgram().programID, "t_diffuse");
   glUniform1f(texLoc,  testTexture.id);
   if(texLoc < 0) System.out.println("Error accessing diffuse: " + texLoc);
         
   glActiveTexture(GL_TEXTURE1);
   testSpecular.bind(); //glBindTexture(GL_TEXTURE_2D, id); - Works...
   texLoc = glGetUniformLocation(world.getLightingProgram().programID, "t_specular");
   glUniform1f(texLoc, testSpecular.id);
   if(texLoc < 0) System.out.println("Error accessing specular: " + texLoc);


And here's the output:
1  
 Error accessing diffuse: -1


The light shader program ID returns 1. So that works.
The diffuse texture returns 1. (testTexture.id;)
The specular texture return 2. (testSpecular.id;)
But the specular IS working...
Offline princec

« JGO Spiffy Duke »


Medals: 437
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2014-05-24 18:59:47 »

As you've just ignored the diffuse value... the GLSL compiler has helpfully optimised the whole thing away. Slightly annoying when you're debugging shaders but that's what it does.

Cas Smiley

Offline Sickan

Senior Devvie


Medals: 9



« Reply #2 - Posted 2014-05-24 19:01:52 »

   texLoc = glGetUniformLocation(world.getLightingProgram().programID, "sampler01");
Shouldn't you use t_diffuse as that is the variable name in the shader, when you access it? I've only a few hours experience with GLSL, so correct me if I'm wrong.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spacebeans
« Reply #3 - Posted 2014-05-24 19:02:54 »

Yeah, I just renamed all of them for the sake of the thread, same error.
Offline Spacebeans
« Reply #4 - Posted 2014-05-24 20:18:33 »

Also, it seems to be binding the testTexture to the specular sampler.
Offline Spacebeans
« Reply #5 - Posted 2014-05-24 20:41:30 »

Okay, I see what you mean, I'm using the specular map but the diffuse map isn't being used. Thanks for the info!
Offline Danny02
« Reply #6 - Posted 2014-05-24 22:35:02 »

also, you have to bind the texture unit not the texture id.
GL_Texture0 == 0
GL_Texture1 == 1
...
Offline Spacebeans
« Reply #7 - Posted 2014-05-24 22:42:01 »

Thanks, its all working now! Except for the specular mapping. Can anyone please help me out with that?

Heres my shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
#version 120
varying vec3 normal;
varying vec3 position;

uniform vec2 lightLocation;
uniform vec3 lightColor;
uniform vec3 ambientLight;

uniform sampler2D t_diffuse;
uniform sampler2D t_specular;

uniform bool material;
 
void main() {
      vec4 diffuse = texture2D(t_diffuse, gl_TexCoord[0].st);
      vec4 specular = texture2D(t_specular, gl_TexCoord[0].st);
     
        float distance = length(lightLocation - gl_FragCoord.xy);
        float attenuation = 1.0 / distance;
        vec4 light = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4(lightColor, 1);
       
        vec4 color;
       
        if(material)
        light += specular;
       color = light * diffuse;
       if(!material)
       color = light;
       
        gl_FragColor = color;
}
Offline HeroesGraveDev

JGO Kernel


Medals: 320
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #8 - Posted 2014-05-25 01:01:45 »

You are using a strange combination of the modern and deprecated pipelines.

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.

Mr.CodeIt (23 views)
2014-12-23 03:34:11

rwatson462 (53 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (85 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (78 views)
2014-12-05 12:39:02

SHC (89 views)
2014-12-03 16:27:13

CopyableCougar4 (95 views)
2014-11-29 21:32:03

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

toopeicgaming1999 (151 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!