Spin bluuuur shader

When something spins fast, it blurs. It has to otherwise it looks as if it’s rotating by arbitrary angles. Originally I had this effect done by rendering the same image multiple times, each time slightly rotated and more transparently than the previous time. Yesterday I tried doing it the GLSL way, which looks way better (and is faster). Here’s the result:


And here’s the shader:

uniform float angle;
#define NUM_ROTATIONS 30

vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
    vec2 center = vec2( 0.5, 0.5 );
    vec2 relPos = texture_coords - center;
    vec4 finalColor = vec4( 0.0, 0.0, 0.0, 0.0 );
    float progression = 0.0;
    for( int i=0; i<NUM_ROTATIONS; i++ )
        float angleFract = - angle*float(i)/float(NUM_ROTATIONS);
        float cs = cos( angleFract );
        float sn = sin( angleFract );
        vec2 newPos = vec2( relPos.x*cs - relPos.y*sn, relPos.x*sn + relPos.y*cs );
        newPos += center;
        vec4 tex = texture2D( texture, newPos );
        float rate = pow(float(i),1.2) * (tex.a +0.4);
        progression = progression + rate;
        finalColor += tex * rate;
    return finalColor/progression;

Spinning Tops

I had prototyped a spinner based game earlier in November (I think) and it was very fun to play against my brother, but I couldn’t get to develop it because of the constantly emerging university deadlines. Finally uni’s over which means I’m free… at last until the exams come.

The game is supposed to be an action/fighting game where 2 or more spinning tops fight to the death. It was mainly inspired by the cheap plastic Chipicao spinners I used to collect as a kid (good times…), and they were in turn based on beyblade. There are a couple of Beyblade video games for different consoles already and they new ones keep coming out. Unfortunately it isn’t a ground-breaking idea, people have been making tops for millennia, but there aren’t great many (enough) spinning top games either (especially for PC), plus I really want to make this one.

It is a seemingly simple scenario – there is an arena or terrain (usually bowl shaped) and 2 or more spinning tops. Gravity moves the tops as low as it can (i.e. towards a local minimum) and rigid body physics sends them flying when they touch. Although simply watching this simulation (over and over) becomes more boring by the second, it peaks the interest when you try to predict the outcome and reason about the underlying system, especially if you have the choice of what top(s) to use. Adding the ability to control one of the tops to a certain degree while it still obeys the laws of physics adds even more fun to the equation as now players are no longer mere spectators. Being able to defy and exaggerate those laws on occasions (or more importantly your opponent’s ability to do so) adds a pinch of unpredictability. To cut it short, just the core concept of it sounds enough to keep players engaged.

Anyways, I’ve been playing with this yesterday and since the first prototype was a complete mess (merely a proof of concept), I had to start from scratch. There are many ideas that will go in the mix (and probably more that will drop out), here are a few of them:

  • Tops are flat 2D images which rotate on the screen and bump into each other.
  • Each top has the following primary stats – WEIGHT, JAGGEDNESS, RADIUS, BALANCE. These are directly calculated based on the image. The more pixels, the more weight, the less of a circle it is the more jaggedness, the more off-center the mass is the less balance… you get the picture.
  • In addition tops will have secondary stats some of which are based on the primary ones – MAX-RPM, PUSH-BACK, ENERGY. Stats are a really boring part of the mechanics so I’ll skip the explanations… :)
  • Special abilities possibly based on the colors from the image
  • Arenas are 2D color images with a depth mask. The depth mask determines the incline and can also be used for lighting (and possibly displace mapping).
  • It is a 2D game (no need for a 3rd dimension) but with a couple of cheap tricks can be given 3D-ish look :)
  • Competitive multilayer on a single machine or over the network.

3D reconstruction from projections

Thinking back at that post about volume reconstruction from sprite depth, I start to feel that there is actually a bigger and better use for cube projections, than just reducing data.

It is possible to reconstruct a complete image from multiple depth mapped projection as each of them contains 3D data.One way to do it is to project every point from every projection into the 3D space effectively forming a point cloud, however it is also possible to render them directly using ray casting a transformed ray trough all projections.

This is something I want to test after I’m done with university, one thing that is cool about the idea is that if the projections are cube based only the front 3 faces of the cube need to be considered. Hence reducing the amount of computation by half.

I can tell a few limitation to this approach even from now – it is going to have hard time with concave objects and self-occlusion, it will not work well with transparency and for operations on the 3D data multiple projections have to be considered. One challenge in particular would be the problem of how to fill up holes in concave regions.

It however would have many advantages as well… technically it is a compromise between volume and polygon graphics – it allows complex 3 dimensional shapes to be defined without the need to model them with triangles (just like volumes) but also only contain surface data (just like polygons).

A few terms that might be useful when looking for related literature:

  • Digital Evaluation Model (DEM) – mainly used with terrain height mapping
  • Displacement mapping – applying per pixel 3D deformations to polygons

Blog’s Purpose

I ramble a lot and need something to organize my thoughts and plan activities (so that no time is wasted :) This is mostly going to be a private blog with loads of randomly scattered entries floating around in semi-structured fashion, but I’ll occasionally publish stuff as well (I promise)