Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Animation and transformation order  (Read 1621 times)
0 Members and 1 Guest are viewing this topic.
Offline greenOwl

Junior Devvie

Medals: 1

from Germany

« Posted 2012-12-29 17:31:59 »


I'm currently working on a shader-based animation for a game-entity. The (vertex) shader gets the mvp-Matrix as well as data for the animation.
My question is in which order I should execute animation and transformation. Should I do the animation-based manipulation of the vertex data (esp. coordiantes) first and then transform it or vice versa?


Offline matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

« Reply #1 - Posted 2012-12-29 19:05:24 »

At first I thought this is easy to answer... but...

I'd actually say you'd do this after multiplying by the model matrix. But then you'd need to send the model matrix and the view-projection matrix to the shader sperated and you'd have more uniforms to send and more matrices to multiply vectors by...

So I suggest multiplying the vertices by the model matrix on the cpu (you don't even have to do this every frame, since you don't need to rotate / scale or translate something all the time. So you can leave that out sometimes, if you cache the results) and then upload that to the gpu.

In the gpu I'd then do the animation and finally multiply by the view-projection matrix.

(But this is actually dependent on the "animation")
Here an example:
First, I want to clarify, what I think you mean with "animation": For example a windy effect by transforming the vertices by some layered cosine or sine, for example in Minecraft. Where the leave blocks are then affected by the wind.

So what If I want to translate or rotate the blocks?
If I would just first transform the vertices before they are translated I'd get the same wind effect for all leave blocks, since the position of the vertex is the seed of the wind effect. -> all leave blocks have the positions 0, 0 in the beginning -> All do the same function lookup.

So what I do: I multiply all the leave blocks' vertices by the model matrix. -> They get translated each to the right position, for example 16, 9, wheras others are at other positions. -> They do the right sine-function lookup in the shader and get a beautiful windy effect.

But you can have other "animation"-effects which shouldn't be world-space but screen-space.
For example a waving screen effect (You'd actually do it with Framebuffers and fragment shaders, but here is the example for vertex shaders):
You'd get the screen coords of all the vertices and then disort them by a sine function, dependent on their vertex position.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline greenOwl

Junior Devvie

Medals: 1

from Germany

« Reply #2 - Posted 2012-12-29 19:22:06 »

Thank you very much for your detailed answer.
I asked the question because in my case it practically doesn't matter much in which order it's done. But as you mentioned in some scenarios it does.

I'll go with the variant you suggested because it's somewhat more convenient to animate with normalized coordinates and then transform the whole model to screen coordinates.

Pages: [1]
  ignore  |  Print  

EgonOlsen (1675 views)
2018-06-10 19:43:48

EgonOlsen (1723 views)
2018-06-10 19:43:44

EgonOlsen (1161 views)
2018-06-10 19:43:20

DesertCoockie (1588 views)
2018-05-13 18:23:11

nelsongames (1188 views)
2018-04-24 18:15:36

nelsongames (1717 views)
2018-04-24 18:14:32

ivj94 (2542 views)
2018-03-24 14:47:39

ivj94 (1767 views)
2018-03-24 14:46:31

ivj94 (2847 views)
2018-03-24 14:43:53

Solater (972 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!