It looks like you're new here. If you want to get involved, click one of these buttons!

Just a simple question, but confusing to ke anyway... I have this:

Lua

```
self.mesh.shader.mModel = modelMatrix()
self.mesh.shader.mView = viewMatrix()
self.mesh.shader.mProjection = projectionMatrix()
```

Vertexshader

```
uniform mat4 mModel;
uniform mat4 mView;
uniform mat4 mProjection;
...
void main()
{
...
mat4 mvp = mProjection * mView * mModel;
gl_Position = mvp * position;
// gl_Position = modelViewProjection * position;
}
```

I'm confused, because I thought my expression for mvp should be identical to the predefined modelViewProjection, but it isn't working; my mesh isn't showing at all.

Anyone knows how to accomplish this? Eventually I wanna scale the mModel*position coordinates.

Tagged:

## Comments

You wrote:

So, presumably what you eventually want then is a

`viewProjectionMatrix`

.Here's the easiest way to do this:

If you reset the model matrix before you draw, then it means the model matrix passed into the shaders MVPM is an identity matrix:

And

thismeans that the shaders`modelViewProjectionMatrix`

is in fact just a viewProjectionMatrix. You've effectively removed the modelMatrix out of the equation by resetting it to the identity.The model's position then comes not from the automatic MVPM, but from the

`mMatrix`

you passed in.So in the shader, this will be correct:

This will also be much more perfomant than recalculating the MVP in each run through the vertex shader.

Sometimes I wish the Codea forum would allow answers to be up/ down-voted

Turned out the problem was that the shader variables for each matrix weren't updated every step.

Only problem now is that the rendering order is reversed somehow. Everything in the back is rendered in in front and vice versa. So I'm still a little bit confused...

@yojimbo2000 Your solution worked well! Thank you so much.

I didn't come up with this method btw. I think it might've been one of @Ignatz 's?

Ok, I found the thread where we discussed this before, it was @Ignatz who came up with this technique:

https://codea.io/talk/discussion/comment/62198/#Comment_62198