Blog 2.0
Dark Style Medium Style Light Style

Blog Statistics
First Previous Homepage Next Latest
RSS Feed

Furry Rendering

Before writing this I must point you in the direction of this blog written by Catalin Zima, particularly this article - that technique acted as the basis of what I'm about to talk about (although I improved upon it somewhat).

So, what is this furry rendering all about? Well, it's about making things look furry (Well I never)! The basic way it works (Which is presented in that excellent article) is this:

1) Take a transparent sheet, draw some dots on it
2) Stack hundreds of copies of the sheet - you get vertical columns building up which is your fur
3) To animate the fur move the sheets around a little bit and the fur will bend

Now, the problem with this is in animating it - every piece of fur has to be moving in the same direction! This is because the animation is done in the vertex shader (the sheets are moved around). A better way would be to move those points around, which is obviously a pixel shader operation.
So, how to achieve every single strand moving individually even though they share the same geometry? Well, in the pixel shader there is an operation which samples a fur density map which is basically boolean - is there fur at this coordinate or not - all I have to do is offset the sample coordinates and the fur has moved sideways a bit. I came up with this helper function:


   79 float2 WindModifyCoord(float2 uv)


   80         {


   81             float4 w = tex2D(WindSampler, uv);


   82 


   83             float2 dir = float2(w.r - 0.5, w.g - 0.5) / 5;


   84             float myTime = (Time + (uv.x + 3) / (uv.y + 2)) * w.b * 100;


   85 


   86             dir += cos(myTime) * w.a * float2(1, 1) * 0.01f;


   87 


   88             float displacementFactor = pow(CurrentLayer, 1.5f);


   89             return uv + dir * displacementFactor;


   90         }


It's quite complex because it does several things, but the upshot is that every single hair is now individually animated to sway in the breeze. I should note here that this probably only works for what I'm using it for, which is grass (a mostly flat plane), for other situations you'd have to change this function - however the technique of offsetting texture coordinates to animate the fur would work for anything. So this method does this:

1) Sample a windmap, this defines the direction and strength of the wind at every point (it could the the output of some kind of GPU fluid simulation)
2) Calculate the direction, the red and green channels store direction, which I then subtract 0.5 from to move the range from [0 - 1] to [-0.5 - 0.5]. The divide by five is purely to reduce the power of wind a bit.
3) Calculate "myTime", the animation for a blade of grass is the same at the same time, so I just modify the time each blade of grass thinks it is and the animation are different! You notice that w.b is in there, by changing that you can make animations move faster or slower.
4) Make the grass wobble, simply by adding on cos(myTime) and multiplying it by w.a, which is the amplitude of wobbles.
5) Calculate displacement factor, CurrentLayer moves from 0 to 1 as you move from the bottom to the top of the grass, so the displacement is larger at the top of the grass.
6) Return the modified coordinate and use that in all subsequent calculations.

It should be illegal to make a blog post about something graphical and then not follow it up with pictures, so here you go:

Furry!

Furry!

Obviously they don't show animation very well, you'll just have to trust me on that ;)

Posted on 2009-06-10 20:02:15.395323
This post : 155 views
Permalink: http://martindevans.appspot.com/blog/perma?agxtYXJ0aW5kZXZhbnNyDwsSCEJsb2dQb3N0GOFdDA

Author:
Post:
Latest Entries:

Triangulation and Blog 2.1
2009-11-09 18:03:49.415016
Neglect
2009-11-05 21:54:34.749240
N
2009-09-13 01:55:27.993530
Virtual Textures
2009-09-02 09:11:37.076017
Hard working Laziness
2009-08-19 14:11:45.639809
Don't go into the long grass
2009-08-03 17:49:34.315912
Oops!
2009-07-08 00:56:45.557563
Landscaping
2009-07-01 12:06:04.994983
Web Development & Game Development
2009-06-18 18:27:18.057752
Furry Rendering
2009-06-10 20:02:15.395323