PDA

View Full Version : suggest a best way to do transformation of matrices in openGLES2.0?



maheedharachalla
08-27-2014, 04:36 AM
Hi.I am developing an OpenGLES2.0 application.Time to render the application is crucial thing for me.My application has both static and dynamic objects(moving pointers in dial).To improve the performance I want to reduce the computation burden on CPU. I want to compute the transformation matrices(translate,rotate,scaling) in the shader itself instead of computing them on CPU (only for dynamic objects).Is it advisable to do like this to improve the performance?

My vertex shader will look this



vertex .c
---------------------------------------------------------------------------------


int main()
{

if(static==0) //for static rendering. Value sent from the app
{
gl_Position = mvp* vec4(vert,1.0); // MVP is calculated in the app and sent to shader

}

if(static==1) // for dynamic objects. Value sent from the app
{
/* compute translated matrix
/* Compute rotated matrix
/* compute scaled matrix

gl_Postion = mvp*vec4(vert,1.0); /* mvp is calculated in the shader

}

}

calculation burden will be on GPU instead of CPU only in the case of dynamic objects.Will this improve time to render an application? I need a better FPS.

Agent D
08-27-2014, 04:40 AM
Branches in shader code are generally very bad for performance.

Even if you don't have branches and compute the matrices every time, doing the same thing multiple times in parallel doesn't make it faster and you simply shift static time overhead from the CPU to the GPU. Even worse, since all vertices probably won't be computed at the same time, you multiply the static time overhead.

mhagain
08-27-2014, 11:10 AM
The vertex shader is run once per-vertex.

Based on that it should be obvious that for, say, a 200 triangle model you're now computing your transforms 600 times.

Compare that to once-only for the entire model and the cost of an upload if you just do it on the CPU.