Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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 344 times)
0 Members and 1 Guest are viewing this topic.
Offline greenOwl

Junior Member


Medals: 1


from Germany


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

Hello,

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?

Thanks,
greenOwl

elfeck
Offline matheus23

JGO Wizard


Medals: 71
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2012-12-29 20: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.

Take a look at my development Blog: http://matheusdev.tumblr.com
Also look at my RPG Ruins of Revenge
Offline greenOwl

Junior Member


Medals: 1


from Germany


« Reply #2 - Posted 2012-12-29 20: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.

elfeck
Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (34 views)
2013-05-17 21:29:12

alaslipknot (42 views)
2013-05-16 21:24:48

gouessej (72 views)
2013-05-16 00:53:38

gouessej (71 views)
2013-05-16 00:17:58

theagentd (79 views)
2013-05-15 15:01:13

theagentd (74 views)
2013-05-15 15:00:54

StreetDoggy (116 views)
2013-05-14 15:56:26

kutucuk (139 views)
2013-05-12 17:10:36

kutucuk (140 views)
2013-05-12 15:36:09

UnluckyDevil (147 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.071 seconds with 20 queries.