Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
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  
  [Solved] [LibGDX] Shader problem is beginning to piss me off  (Read 4178 times)
0 Members and 1 Guest are viewing this topic.
Offline vbrain
« Posted 2014-06-11 12:33:42 »

I've written and used shaders for libgdx in the past, but never run into this stupid f**king problem.

"no uniform with name 'u_texture' in shader"

1  
2  
3  
4  
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: no uniform with name 'u_texture' in shader
   at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:293)
   at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:283)
   at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformi(ShaderProgram.java:307)


Here's my shader fragment program
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_sampler2D;
uniform vec2 u_resolution;

varying vec4 v_color;
varying vec2 v_texCoord0;

void main()
{
   vec4 color = texture2D(u_sampler2D, v_texCoord0) * v_color;
   vec2 fragPos = gl_FragCoord.xy / u_resolution.xy; //will give range in [0-1, 0-1]
   float dist = distance(fragPos, vec2(0.5, 0.5)); //distance to the center of the screen
   
   gl_FragColor = vec4(0, 0, dist, 1);
}


I've tried for so long to get this shit to work. None of my other shaders have this f**king problem.

And here's the real kicker. I put my exact same shader code in a different libgdx project and it worked, but in this new project it keeps giving me this stupid f**king error.

I even tried setting the sampler2D's name to u_texture and that didn't work.
Offline Opiop
« Reply #1 - Posted 2014-06-11 12:37:11 »

Um yeah you need to actually have that uniform in the shader, which you don't. Of course it will throw the error if the uniform doesn't exist. Try renaming the Sampler2D uniform again and then post whatever error you have.
Offline vbrain
« Reply #2 - Posted 2014-06-11 12:39:07 »

Um yeah you need to actually have that uniform in the shader, which you don't. Of course it will throw the error if the uniform doesn't exist. Try renaming the Sampler2D uniform again and then post whatever error you have.

I said that I did rename the sampler2D to u_texture and it gave me the exact same error with the exact same stack trace.

Could it be because I created this new project with libgdx 1.1 instead of the nightly 0.9.9 that was used on the previous projects? This is absolutely absurd.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 1103
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2014-06-11 12:44:21 »

You're not actually using u_sampler2D even in the original shader, as you're not using "color", so the whole uniform is optimised away.

Cas Smiley

Offline vbrain
« Reply #4 - Posted 2014-06-11 12:49:17 »

You're not actually using u_sampler2D even in the original shader, as you're not using "color", so the whole uniform is optimised away.

Cas Smiley

That's not the problem. I switched it to this and it still gave me that stupid error:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_sampler2D;
uniform vec2 u_resolution;

varying vec4 v_color;
varying vec2 v_texCoord0;

void main()
{
   vec4 color = texture2D(u_sampler2D, v_texCoord0) * v_color;
   vec2 fragPos = gl_FragCoord.xy / u_resolution.xy; //will give range in [0-1, 0-1]
   float dist = distance(fragPos, vec2(0.5, 0.5)); //distance to the center of the screen
   
   gl_FragColor = color * vec4(fragPos, 0, 1);
}


Also, like I said, I used the exact same shader code in another project and it worked. So, even in that one, the color wasn't being used, but it still worked without errors.
Offline vbrain
« Reply #5 - Posted 2014-06-11 13:17:23 »

Okay, I've solved this issue.

Like I said, for some reason that exact shader code worked in a previous version of LibGDX, but wouldn't work the new one.

What I did:
I set the sampler2D to "u_texture"
1  
uniform sampler2D u_texture;


AND I also had to use the "color" variable so that it wouldn't get optimized out. So, my current fragment shader looks like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_texture;
uniform vec2 u_resolution;

varying vec4 v_color;
varying vec2 v_texCoord0;

const vec4 glowColor = vec4(1, 1, 1, 1);

void main()
{
   vec4 color = texture2D(u_texture, v_texCoord0) * v_color;
   vec2 fragPos = gl_FragCoord.xy / u_resolution.xy; //will give range in [0-1, 0-1]
   float dist = distance(fragPos, vec2(0.5, 0.5)); //distance to the center of the screen
   
   color = mix(color, glowColor, dist);
   gl_FragColor = color;
}


It's very irritating how it works in previous LibGDX versions but not in the new one.
Offline Orangy Tang

JGO Kernel


Medals: 57
Projects: 11


Monkey for a head


« Reply #6 - Posted 2014-06-11 13:42:35 »

AND I also had to use the "color" variable so that it wouldn't get optimized out. So, my current fragment shader looks like this:
Unfortunately this is a GLSL issue - if an attribute isn't used, then the compiler is free to completely remove it. There's no requirement for the driver to still expose a dummy attribute that doesn't do anything. I'm not sure I agree with that but that's what the spec says.

I would guess that libGDX is now actually reporting when you try and set an invalid attribute rather than blindly ignoring them like it did before.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #7 - Posted 2014-06-11 15:37:36 »

I believe this can be "fixed" (as in the issue is ignored like before) if you set
ShaderProgram.pedantic = false;
before creating a ShaderProgram.
Offline vbrain
« Reply #8 - Posted 2014-06-11 16:39:09 »

I believe this can be "fixed" (as in the issue is ignored like before) if you set
ShaderProgram.pedantic = false;
before creating a ShaderProgram.

If I could kiss you right now I would, you magnificent bastard.
That's why it was working in my previous project but not in the current one.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (34 views)
2019-09-04 15:33:17

hadezbladez (3979 views)
2018-11-16 13:46:03

hadezbladez (1444 views)
2018-11-16 13:41:33

hadezbladez (3986 views)
2018-11-16 13:35:35

hadezbladez (769 views)
2018-11-16 13:32:03

EgonOlsen (4085 views)
2018-06-10 19:43:48

EgonOlsen (4664 views)
2018-06-10 19:43:44

EgonOlsen (2753 views)
2018-06-10 19:43:20

DesertCoockie (3647 views)
2018-05-13 18:23:11

nelsongames (3849 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!