I'm trying to understand shaders using libgdx, coming from an XNA/HLSL background. I'm trying to get a vert/frag shader pair to reproduce the output I get without a shader, but it's not displaying anything.
Shader creation:
void SetupShader()
{
ShaderProgram.pedantic = false;
shader = new ShaderProgram(
Gdx.files.internal("assets/default.vert").readString(),
Gdx.files.internal("assets/default.frag").readString());
if(!shader.isCompiled()) {
Gdx.app.log("Problem loading shader:", shader.getLog());
}
batch.setShader(shader);
}
default.vert:
attribute vec4 a_Position;
attribute vec4 a_Normal;
attribute vec2 a_TexCoord;
attribute vec4 a_Color;
uniform mat4 u_projTrans;
varying vec2 v_texCoords;
varying vec4 v_color;
void main() {
v_color = a_Color;
v_texCoords = a_TexCoord;
gl_Position = u_projTrans * a_Position;
}
default.frag:
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texCoords;
varying vec4 v_color;
void main() {
gl_FragColor = v_color;
}
Rendering:
batch.begin();
for (GameObject gObj : gameObjects)
gObj.Draw(batch);
batch.end();
Any suggestions here? I'm new to OpenGL-ES as well, so I may be missing something obvious. I looked around a bit before posting, and the doc for SpriteBatch.setShader(ShaderProgram) was as follows:
Sets the shader to be used in a GLES 2.0 environment. Vertex position attribute is called "a_position", the texture coordinates attribute is called called "a_texCoords0", the color attribute is called "a_color". See ShaderProgram.POSITION_ATTRIBUTE, ShaderProgram.COLOR_ATTRIBUTE and ShaderProgram.TEXCOORD_ATTRIBUTE which gets "0" appened to indicate the use of the first texture unit. The projection matrix is uploaded via a mat4 uniform called "u_proj", the transform matrix is uploaded via a uniform called "u_trans", the combined transform and projection matrx is is uploaded via a mat4 uniform called "u_projTrans". The texture sampler is passed via a uniform called "u_texture". Call this method with a null argument to use the default shader.
In general, the languageās use of this character set is case sensitive.. Does this mean Identifiers are case sensitive? The Identifiers section does not contain a word about it. (the vertex shader containsa_Position, the commenta_position) - Stefan HankeSpriteBatchcreates its shader, and it was primarily a caps issue. I also figured out what the default shaders are- I'll post those below. - user312364