How to get and set matrix_model for custom shader?

I’m writing custom shaders and went through few tutorials as well provided on official website of Play Canvas (https://developer.playcanvas.com/en/tutorials/custom-shaders/)

I’m still unsure how we can set matrix_model and matrix_viewProjection, are they set automatically? if so how we can retrieve them and setup ourselves (for example if we want to change the name of matrix variables)?

Hi @PC_Coder,

They are being set automatically by the engine. If you would like to use your own, instead of overriding those maybe it’s easier to just create and set your own uniforms in your shader.

Check here how the engine resolves and sets the value for them:

Thanks, I got it now.

So do I have to manually calculate the matrices for each entity or I can get them from forward renderer or graphics device? I just have different names for matrices.

You can check how the forward renderer does it for each draw call here, and similarly calculate them for each mesh instance that uses your custom shader:

Thanks, got it now

1 Like

I’d suggest that it’s easier to rename your matrices in the shader and let engine set them as uniforms.

2 Likes