[WIP] Vertex 3-axis deformation shader (Incorporated JME’s Lighting.frag) (43 posts)

  • Profile picture of t0neg0d t0neg0d135p said 3 months ago:

    Heyas…

    I’m working on a vertex shader for handling some standard deformations. Basically (when complete) it will allow for selecting a deformation type and then setting speed, size and depth to achieve the effect your looking for. The vertex shader can be coupled with any fragment shader you like, however, it will require you know a bit about creating material definition files and making sure you pass in the appropriate MaterialParameters, WorldParameters and Defines to accompidate both the vertex deform .vert and whatever .frag you choose to use it with.

    The final deformation types will consist of:

    Wave
    Ripple
    Pinch
    Swell

    Well… and I guess any others that people would like to have included (just post your idea here).

    Here is a sample of the Ripple and Wave deformations. Oh… I also need to allow for reversing the direction of the effect as well.

    Anyways… let me know what you think or pass along any ideas for deforms you’d like to see added.

    Forgot to mention the TODOs…

    I’m finishing up recalculating normals and adding a few more standard deformations.

    Oh man…

    I totally failed to mention the coolest part. This isn’t a single axis deformation… you can turn on and off the X, Y and Z axis deformations individually. Here is a sphere with a Wave deform against all 3 axis:

    Normals recalculation:

    With Common/MatDefs/Light/Lighting.frag

  • Profile picture of normen normen1291p said 3 months ago:

    Cool stuff, great to see so many people fearlessly jumping into “shader world” ^^

  • Profile picture of Sploreg Sploreg206p said 3 months ago:

    this is really cool!

  • Profile picture of t0neg0d t0neg0d135p said 3 months ago:

    I’ve done a bit more work on this.

    For each axis, you can now set:

    Deform axis on/off
    Deformation Type
    Direction
    Speed
    Size
    Depth

    Here is a sphere with Ripple along the Y axis, and Wave along the X and Z axis with different setting for each.

    Some of the cooler applications this can be used for (off the top of my head) would be:

    Animating a snakes movement… without having to animate.
    Animating just about any underwater creature… without having to animate.
    Animating a land animals tail… without having to animate.
    Animating liquid in any shape… would work really well for zero-g liquid.

    Are you getting the “without having to animate” part yet? ;)

    Anyways…. once this a little further along and I start using it with fragment shaders, I’ll throw together an example of a snake or some such thing.

  • Profile picture of InShadow InShadow15p said 3 months ago:

    Really awesome stuff man! :)

  • Profile picture of mifth mifth132p said 3 months ago:

    @t0neg0d , you are killing me again! Will you contribute this shader to the shader library?

  • Profile picture of nehon nehon591p said 3 months ago:

    very nice stuff!

  • Profile picture of wezrule wezrule201p said 3 months ago:

    oh snap :) very nice, how did u learn to use shaders?

  • Profile picture of t0neg0d t0neg0d135p said 3 months ago:

    @mifth Absolutely… As soon as it is finished up, I’ll post the code here. As for getting you that GPU-based version of the other one, I’ll have time to get that out here tonight. Just to clarify, you can switch directions in the GPU-based version, it just jumps the textures oddly when you update the float. @pspeed was nice enough to explain why it was happening to me and patient enough to let me babble about how I could fix it… knowing full well it wasn’t possible lol ;)

    @wezrule Asking a TON of really silly questions and a bunch of reading. People here are really patient (even when my questions made no sense). There isn’t a lot to it… it’s mostly getting the fundamental understand of how they work (which didn’t click with me for quite a while).

    EDIT: I should also mention, info on the fundamental workings of shaders is NOT readily available on the web. Trying to find an answer to simple concepts like what texture coordinates actually are (0-1??! Makes sense now.. but…), is next to impossible to find… so ask here. Also, I’m still lost on a TON of of these… but trial and error/asking those who know has been a good thing.

  • Profile picture of wezrule wezrule201p said 3 months ago:

    ok cool thx :) , i’ve been meaning to learn them for a while, but always get stuck at the first hurdle

  • Profile picture of nehon nehon591p said 3 months ago:

    @t0neg0d said:
    @wezrule Asking a TON of really silly questions and a bunch of reading. People here are really patient (even when my questions made no sense).

    Well according to your recent achievements, helping you wasn’t a waste at all ;)

  • Profile picture of Sploreg Sploreg206p said 3 months ago:

    How difficult is calculating normals for a solid surface going to be?

  • Profile picture of t0neg0d t0neg0d135p said 3 months ago:

    @Sploreg Well… I thought I had a good understanding of how to do this… but it is proving a bit more difficult than I originally thought. All the examples I can find for recalculating normals are based off of changes to a single axis, so I am getting stuck on how to determine the normal once a deformation is applied to more than one axis. I’ll post the code I was working with soon and see if someone smarter than me can figure it out.

  • Profile picture of Sploreg Sploreg206p said 3 months ago:

    You essentially need the neighbour vertices, and for that you will need a geometry shader. Or, if your mesh is symetrical (like a sphere or plane) with evenly spaced points, I suppose you could still do this in the vertex shader and just interpolate one unit length in each direction of the neighbouring vertices, run the calculation on them, then take the normals and average them (say 4 samples to 4 neighbours to get 4 normals, and then average those to get your new normal).

    How do the examples suggest to recalculate the normals after the deformation?

  • Profile picture of pspeed pspeed822p said 3 months ago:

    If your formula for generating the position is based on standard curves then it should be possible to find the normal for that position on the curves. I don’t know the math you are using, though. I also don’t know what vertex-specific info your shader uses to figure out where on the curves…

    This will be more accurate in general than sampling surrounding points, though. If you can get away with it.