Looking at https://github.com/libgdx/libgdx/wiki/Shaders, I have decided to try these shaders:

    String vertexShader = "attribute vec4 a_position;\n"+
                            "uniform mat4 u_projectionViewMatrix;\n"+
                            "void main()\n"+
                            "{\n" +
                            "gl_Position =  u_projectionViewMatrix * a_position;\n"+
                            "} ";
    String fragmentShader = "void main()\n"+
                            "gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"+
    ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);

Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: no uniform with name 'u_projTrans' in shader

  • 1
    \$\begingroup\$ Please add more information to your question. Are you trying to find a uniform called u_projTrans somewhere in your program? \$\endgroup\$
    – Soapy
    Mar 18, 2015 at 9:18
  • \$\begingroup\$ It'd be nice if you added the drawing code where you try to assign to your uniform matrix. It looks as if you might have some code trying to set u_projTrans when your vertex shader has u_projectionViewMatric as Soapy mentioned. \$\endgroup\$
    – Cobertos
    Mar 18, 2015 at 14:19
  • \$\begingroup\$ @Soapy: I am not doing anything else. I simply copy-pasted the example shader code from the tutorial I linked. \$\endgroup\$
    – Saturn
    Mar 18, 2015 at 17:45
  • \$\begingroup\$ @Omega it's not the shaders that are the problem, you're doing something wrong in your code. \$\endgroup\$
    – Soapy
    Mar 18, 2015 at 19:49

4 Answers 4


There is nothing wrong with the shaders.

The error you're getting is due to somewhere in your program your calling a line similar to this:

shader.setUniformMatrix("u_projTrans", matrix);

Basically this error is thrown when either u_projTrans doesn't exist in that shader or it does exist in the shader but you don't use it. When it's not used the shader compiler will optimize away unused uniforms.

  • \$\begingroup\$ In that page, they don't specify what is the value of matrix. What am I suppose to use for it? I'm just rendering a Sprite object in my batch. \$\endgroup\$
    – Saturn
    Mar 19, 2015 at 17:13
  • \$\begingroup\$ Matrices are used for affine transforms \$\endgroup\$
    – Soapy
    Mar 19, 2015 at 17:15
  • \$\begingroup\$ So I don't need one and therefore I don't provide it. Also the shader program is not using anything called u_projTrans, so why am I getting this error? \$\endgroup\$
    – Saturn
    Mar 19, 2015 at 17:49
  • \$\begingroup\$ You will need one if you want to translate, rotate and scale easily. And considering your shader is already using a projection matrix it looks like your shader is geared up to use a modelview matrix. \$\endgroup\$
    – Soapy
    Mar 19, 2015 at 18:37
  • \$\begingroup\$ You're gonna need to post more code if you want people's help \$\endgroup\$
    – Soapy
    Mar 19, 2015 at 18:38

You are most certainly trying to use your shader in SpriteBatch. SpriteBatch is setting up the shader's projection matrices, which are by convention (as MadEqua answered) called u_projTrans, not u_projectionViewMatrix (see SpriteBatch source). SpriteBatch also uses some more uniforms which you must declare (and use, so they aren't optimized away).

However, there is a way how to stop libGDX from crashing when it is trying to set non-existent uniforms and that is by setting pedantic flag to false:

ShaderProgram.pedantic = false;

Your application is trying to find an uniform in the shader called u_projTrans to send it the projection matrix.

The simplest fix is changing this shader line:

"uniform mat4 u_projectionViewMatrix;\n"+


"uniform mat4 u_projTrans;\n"+

Then the variable names should match on both the application and shader sides.


As the others already pointed out in their answers, SpriteBatch expects specific uniforms in the shader and you should either rename them or set the pedantic flag to false.

I just wanted to add, that both those things didn't help me solve this error.

The solution was this paragraph from the documentation:

You can ensure that the shader compiled properly via shader.isCompiled(). A compile log can be spit out using shader.getLog().

Turned out, my shader didn't even compile properly, because it had a syntax error. So, always make sure to call shader.isCompiled() and shader.getLog()


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .