Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 582 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 Kernel


Medals: 106
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.

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 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  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

pw (11 views)
2014-07-24 01:59:36

Riven (9 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (49 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!