WarrenFaith
WarrenFaith

Reputation: 57672

Shader multiply matrices

I have an issue I don't understand.

I have a shader

String[] vsSource = new String[] {
        "attribute vec3 aVertex;",
        "attribute vec3 aColor;",

        "uniform mat4 uMVMatrix;",
        "uniform mat4 uPMatrix;",

        "varying vec3 vColor;",

        "void main(void) {",
        "    vColor = aColor;",
        "    gl_Position = uMVMatrix * uPMatrix * vec4(aVertex, 1.0);",
        "}" };

I set both matrices uMVMatrix and uPMatrix and I want to multiply them in the shader. When I try that, my screen stay black.

When I multiply it in Java and pass it to one mat4 variable, I see my triangle.

String[] vsSource = new String[] {
        "attribute vec3 aVertex;",
        "attribute vec3 aColor;",
        "uniform mat4 mvpMatrix;",

        "varying vec3 vColor;",

        "void main(void) {",
        "    vColor = aColor;",
        "    gl_Position = mvpMatrix * vec4(aVertex, 1.0);",
        "}" };

Can someone tell me why I can't multiply them in the shader?

Upvotes: 1

Views: 261

Answers (1)

bosmacs
bosmacs

Reputation: 7483

Try inverting the order of the matrices in the shader, i.e.

gl_Position = uPMatrix * uMVMatrix * vec4(aVertex, 1.0);

Upvotes: 2

Related Questions