PDA

View Full Version : Scaling and Translating in the Vertexshader



TeHa
07-03-2012, 06:27 AM
Hello folks,

I must say, I'm new to OpenGL ES 2.0 and I'm working on Android.
I've written a small vertex shader that implements the scaling and translation of my incoming vertices. Therefor I have a scaling-matrix (mat4 scale) given by
/ sx 0 0 0\
| 0 sy 0 0|
| 0 0 sz 0|
\ 0 0 0 1/
and a translation-vector (vec4 trans) given by:
/tx\
|ty|
|tz|
\1/
so gl_Position = (scale * Vertex) + trans;

but I thought it's easier to give both operations in just one matrix (mat4 proj), so that gpu has only to perform an multiplication and and not a multiplication AND addition. matrix4 looks like that:
/ sx 0 0 tx\
| 0 sy 0 ty|
| 0 0 sz tz|
\ 0 0 0 1/
so gl_Position = Vertex*proj;

Now the problem: the first way coordinate-tranformation works, but when I put both operations together in one martix nothing happens. dont' know what is going wrong? - please help!

TeHa
07-04-2012, 04:10 AM
It's, as always, you should just wait a day before one bothered others with your problems, since they usually dissolve by themselves.
The solution is so simple and ingenious: The definition of matrices is performed by the GL-API column-wise and not row by row. As long as one only performs the scaling it has not affect because the factors are on the main diagonal, but with one additional translational is has effect.