Demo: Fish schooling / flocking / Boids code

edited April 2013 in General discussions
I've been working on a simple game with my son. Supposed to be about a penguin catching fish. I've adapted Craig Reynolds' algorithms for use with ORX (Scroll, actually), and I've posted a video demo of how the schooling looks:

This video is only at 30fps, and for some reason YouTube made it really blurry; it looks pretty smooth in actuality.

The goal was a bit different from the classic Boids:
  1. Better clumping and alignmentnone
  2. Fish are more apt to turn in unison, as a groupnone

For #1, this was a matter of turning the 'align' weighting way up compared to the other parameters.

For #2, I implemented a raycast (thanks ROM!) to detect when a wall was coming up, creating a "persistent alignment" state, which is "contagious" for nearby fish. The end effect is that when one fish gets near a wall, most/all of the fish in the school will turn in unison away from the wall.

I can provide code if anyone is interested.


  • edited April 2013
    Nice video, thanks for sharing it with us!

    I, for one, would be interested by your code.

    What you need next is a nice shader on that water. ;)
  • edited April 2013
    Are you on github?
  • edited April 2013
    Yes, username: keleborn
  • edited April 2013
    Added you. =)
  • edited April 2013
    Any pointers on the shader stuff? I'm not experienced as a game / graphics programmer.
  • edited April 2013
    Mmh, I don't have many resources, I guess you can have a look at the shader I wrote for Mushroom Stew, but it's a bit messy as it was one of my first shaders.

    There's also this, for the water surface only:

    The interesting part is the fragment/pixel shader, that's the only one you can modify.

    Also, I recently wrote two simple tutorials for orx, both contains shaders if you want to have a look:
    - resource
    - simpletest
  • edited April 2013
    When you say "that's the only one you can modify," does it mean that the orxShader stuff only deals with the pixel shaders?
  • edited April 2013
    Yes, what I mean is that you can use any custom pixel/fragment shader for any of your objects.
    However, there's a fixed vertex shader that will be used all the time (if you want to change the vertex shader, you'll probably also want to change the internal vertex format, so you might as well do your own rendering at this point, hooking it with the orxRENDER events).
    There's no geometry or tessellation shader either as they don't make sense for quads.
    If you want one for a custom object, you need to roll your own rendering for it.
  • edited April 2013
    Also, for examples of what's doable with a simple quad + pixel shader, have a look at :)
Sign In or Register to comment.