Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Different shader(programs) for different animations  (Read 989 times)
0 Members and 1 Guest are viewing this topic.
Offline greenOwl

Junior Member


Medals: 1


from Germany


« Posted 2012-12-30 16:08:24 »

Hello,

I'm currently experimenting with shader-based animation of 2D-objects. One of that objects is supposed to have multiple animation-options with the possbility to switch between them on runtime. Thats all fine and stuff my question now is:

Does it make sense (in consideration of performance and code-design) to wirte a sperate shader-pair (vert & frag) for each animation in constrast to writing a single shaderprogram and abstract the uniforms/attribs to a higher level (so they fit for all the different animations).
Note that in my case no textures are involved. Procedural only!

With my limited experiance I see these points on each side:
Single program:
+ no switching between programs (performance?)
+ less efforts client-sided due to standardized structures for uniforms/attribs
- (significant) more complex and confusing shader-code
- possibly unnecessary uniforms/attribs (certain animations might not need all the "space")

Multiple programs:
+ clean shader-code
+ less uniforms/attribs in each shader
- switching between programs necessary
- possibly more efforts on client-side needed

What do you think?
greenOwl

elfeck
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-12-31 03:37:58 »

Switching between programs is not a problem at all when considering performance. Seeing as that is the cleanest and easiest-to-maintain way, I say go for that.

Always go with the cleanest solutions until you begin noticing performance problems.

Offline Danny02
« Reply #2 - Posted 2012-12-31 08:33:25 »

an easy way not to have to write thousends of lines of shader code which are all nearly the same you can use "interfaces".

When you create a shader you can pass a String[] to the gl call. what this does is just appending the strings inside the array. So you can do something like this

new String[]
{
  "float animate(float time, float start, float stop)
  {
    return (stop-start)*time+start;
  }",

  "uniform float time;

  void main()
  {
     gl_Position = new vec4(animate(time, 2, 10));
  }"
}

then you can put your main shader code in one file and create for each animation style another. And runtime you then can create a shader programm for each file in your animation dir for example.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pitbuller
« Reply #3 - Posted 2012-12-31 14:27:22 »

Switching between programs is not a problem at all when considering performance. Seeing as that is the cleanest and easiest-to-maintain way, I say go for that.

Always go with the cleanest solutions until you begin noticing performance problems.

Binding a new shader is about expensive as binding a texture. Depending on gpu thought. But sending lot of uniforms is not cheap either. So profiling is only way so know which one is better.

But keep in mind that making multiple shaders that share some amount of duplicate code is maintenance hell. Every time you fix a bug you need to remember fix it from multiple different shaders same with adding new stuff. So if you plan to make many animation shaders I do not recommend this approach.
So after certain complexity data driven systems start to excel. Shaders can be optimized with ifdefs or shader generation if you need to strip away nonused features.
Offline greenOwl

Junior Member


Medals: 1


from Germany


« Reply #4 - Posted 2012-12-31 14:46:15 »

The "interface"-thingy danny02 suggested sounds quite nice. The downside I see with his solution is a lot of shader-initialization (glShaderSource - ... - glLinkProgram) calls each time I want to change the animation and have to remove, attach and recompile the shader. I dont know for certain, but I belive that this is not quite the optimum concerning performance and such.

@pitbuller
Yes thats why I really don't want to an entire shader for each animation. What do you suggest instead? 1000+ lines per file seem really uncomfortable as well.
That do you mean with "data driven systems"?

elfeck
Online theagentd
« Reply #5 - Posted 2012-12-31 15:02:52 »

Exactly what are these "animations"? To me, "to animate" just means to switch between different textures. I don't see where shaders come in there, and even less why you need multiple shaders for it.

Then again, I agree with ra4king. If it works at the moment, just leave it as it is. Exactly how many sprites or objects are we talking about?

Myomyomyo.
Offline greenOwl

Junior Member


Medals: 1


from Germany


« Reply #6 - Posted 2012-12-31 15:13:56 »

I work completely without textures. Some expamples of animations I wrote already:
> Change coordiantes of vertices to create all kinds of animation based on modifying the shape of my entity (e.g. modify the coordinates in a circular motion to create a wobbly-effect of my entity.
> Use procedural methods in the fragment shader (e.g. noise, gradient-fills, shapes, ...)

Currently I'm just fiddling around with opengl and shaders. I could imagine a total of ~100 objects not counting particles and other effects.

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.

BurntPizza (25 views)
2014-09-19 03:14:18

Dwinin (39 views)
2014-09-12 09:08:26

Norakomi (68 views)
2014-09-10 13:57:51

TehJavaDev (93 views)
2014-09-10 06:39:09

Tekkerue (47 views)
2014-09-09 02:24:56

mitcheeb (68 views)
2014-09-08 06:06:29

BurntPizza (51 views)
2014-09-07 01:13:42

Longarmx (38 views)
2014-09-07 01:12:14

Longarmx (44 views)
2014-09-07 01:11:22

Longarmx (40 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!