View Full Version : issues about shaders and transformations

02-27-2014, 09:24 AM
- If I'm not wrong, shaders are programs that run in GPU, right?
- Do we send data to this programs using glUniformMatrix*?
- I don't know if it's right but if I send a MVP matrix to the shader, the object's vertices that I want to render will use the position calculated by the shader right before calling the render function.
- If I want to render a lot of objects and I must send the MVP matrix then render the object right after, so I will have a code that send to GPU -> render a lot of times. However if I'm not wrong again this is not a good practice because I'm losing performance because the cost of send information to GPU is very expensive. So a way to get a better performance is send all the informations to GPU then render all the objects.

- And the questions of 1 million dollars is, How can the shader program identify that the MVP matrix is used by a single object and not another one?

02-27-2014, 09:58 AM
1) Yes, that's the basic definition. To use them correctly, you should use a bit more than that, though...
2) Yes, that's one of the possible commands. Keep in mind that they can only be sent if the shader is actually running (glUseProgram).
3) No, if you send a MVP to the shader, the coordinates you want to draw will be transformed right after calling the render function. However, they will be transformed before the shader assigns colors to them.
4) What you allude to is instancing, which is basically what you described: Pack the information every object needs into a chunk, send it to the GPU and then use only a single draw call to draw all objects at once.
5) It can't, it just uses everything you send it and how you coded it. You can, however, add an offset to the position for every instance which will result in a different coordinate, although being transformed with the same MVP.