niedziela, 29 stycznia 2012

Fake Snowflake Shadow

Some time ago I was walking at night in a dense snow fall. I won't talk about my mood, but I was walking alone, nobody was around and I had some time to think, or rather to observe what was happening around. I was really excited about the shadows that where casted by snowflakes. They were dancing everywhere around, like small spiders running through the snow. Something beautiful, honestly. Of course, I mean shadows that are casted by something like street lamp. Now the problem is - how to simulate them? Of course we can cast each shadow accurately. But there are some obvious problems, and when I say problem I mean performance. I think I don't have to explain what problems are connected to shadowing complex particle system with multiple lights (just imagine the deferred shading with all those particles outside buffers, problems with transparency, or FR with multiple pass particle drawing, crazy). And also, there is some possibility, that you render your flakes (or even more possibly - rain) as post process. Sure! It is possible to do it in a straight way, but we wouldn't be game developers if we wouldn't look for some fakes ;) So how can we add some fancy shadows on the snow, that will look like drunk spiders? As you can expect, I'm not going to talk about any physically accurate solution. Look at the image first.

The upper part of the image is a 2D ortho projection of the world, the Source is our street lamp, green line is the ground. The lower part is meant to be the top-down view. As you can see, when the snowflake is close to the lamp (high), it's shadow is casted far from the center of the lamp cone, and it's movement dx1 is quite big. Then, when the snowflake falls and is close to the ground, it's movement dx2 decreases and position get's closer to the center. The situation shown here is utopia, because the flake falls straight down, with const speed. But, what it shows is that the shadow will be tending towards cone center with decreasing speed. This is a very important observation. Now, let's look at the right side. The snow is falling by some trajectory and in successive time periods it is located in P0, P1, P2 and P3 positions. The rule is quite the same, its shadow in time (T0-T3) tends towards cone center with decreasing speed, but we have to remember that this speed will not decrease monotonically, but will be varying. There even may be a situation, when T(n) is farther from cone center than T(n-1). When we look from top at the problem, we also have to add some variation in the other axis (due to air drag, the flake doesn't move straight), we can assume that shadow moves over some simple spline, directed towards S' (cone center) and with variably decreasing speed. The Lambda area is some small area around S', where shadows tend to dissapear (i think that making them bigger and more transparent would look good). You have to include this Lambda area if you don't want your shadows to dissapear suddenly. That's what I've observed in nature - flakes don't go towards strict cone center, but towards some area, because the light bulb isn't a point, but a volume.

Ok, I think that the idea is simple and obvious, so now - how can we simulate this? There are many possibilities, like:

  • Particle system used only for shadows
  • Post process stage shadowing
  • Animated textures (even on low-end hardware, but I won't call any exact names ;P) with texture projection
  • etc.
What you can take from this note is the general behaviour of snowflakes. Their movement is partly predictable (or at least its schema), and by reproducing it you can achieve some eye-candy scene.

Brak komentarzy:

Prześlij komentarz