Without a uniform with a name in a shader

I am new to all of these shader materials and don’t want to, just trying to replace the default SpriteBatch renderer in LibGDX.

I copied the default shader insert and tried to add the shape of the mice, but it gives me "Without uniform with the name" u_mouse "in the shader.

This is all related code:

     String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
             + "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
             + "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
             + "uniform mat4 u_projTrans;\n" //
             + "uniform vec2 u_mouse;\n" //
             + "varying vec4 v_color;\n" //
             + "varying vec2 v_texCoords;\n" //
             + "\n" //
             + "void main()\n" //
             + "{\n" //
             + "   v_color = u_mouse * " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
             + "   v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
             + "   gl_Position =  u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
             + "}\n";
     String fragmentShader = 
             "#ifdef GL_ES\n" //
             + "#define LOWP lowp\n" //
             + "precision mediump float;\n" //
             + "#else\n" //
             + "#define LOWP \n" //
             + "#endif\n" //
             + "varying LOWP vec4 v_color;\n" //
             + "varying vec2 v_texCoords;\n" //
             + "uniform sampler2D u_texture;\n" //
             + "uniform vec2 u_mouse;\n" //
             + "void main()\n"//
             + "{\n" //
             + "  gl_FragColor = v_color * texture2D(u_texture,  u_mouse);\n" //
             + "}";


ShaderProgram shaderTest = new ShaderProgram(vertexShader, fragmentShader);

shaderTest.setUniformf("u_mouse", Gdx.input.getX(),  Gdx.input.getY());

This is the stack trace:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.IllegalArgumentException: no uniform with name 'u_mouse' in shader
    at     com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: java.lang.IllegalArgumentException: no uniform with name 'u_mouse' in shader
    at     com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:283)
    at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformf(ShaderProgram.java:394)
    at com.nehatchick.games.wf.WhiteMountains.render(WhiteMountains.java:424)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:187)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
0
source share
3 answers

This boils down to the fact that after determining the outputs of the vertex shader and the inputs of your fragment shader, the linker understands that it is u_mousenot used in any active code.

, u_mouse v_color, v_color . , GLSL v_color .

u_mouse , . , . glGetProgramInfoLog (...).

, , v_color LOWP , LOWP . , .

+3

, , , u_mouse Vector2. .

shaderTest.setUniformf("u_mouse", new Vector2(Gdx.input.getX(),  Gdx.input.getY()));
0

try calling it between the beginning and the end of the batch batch.setShader(shaderTest); batch.begin(); shaderTest.setUniformf("u_mouse", Gdx.input.getX(), Gdx.input.getY()); batch.draw............... batch.end();

0
source

All Articles