Sunday 15 August 2010

wave shader

Since the name of this project is loomy, I wanted to have some effects to represent sound and especially sound waves.
I could only have shown it as a partially transparent sphere of course, but I wanted to created something with deferred rendering.

So, I created this first version of the shader to represent the wave :



Shader:

One thing cool with deferred rendering is that once you have paid the cost of creating your depth texture, you can do a lot of special effects in it.

This shader work much like a light in deferred lighting.
I render one big sphere (scaling each frame), into a special camera, with the depth buffer as parameter. (I could process the entire screen of course but this is an optimization)

For each pixel, I check if the original 3d point is at the wanted distance of the center of the wave (0.9 of the sphere for now) and I color it accordingly. For now, as this is only a proof of concept, I only show it fully blue, but since I have the albedo, light, and depth for the pixel, I can change it in virtually every way.


Resonance:

I used the occasion to test a little a collision system (using the basic incorporated into panda collision system).
When I create a visual wave, I also create a collision sphere at the same position that I scale at the same time (with a 0.9 coeff to match the visual). If this collision sphere collides with the center of a object (represented by small collision sphere too), I create a new wave (collision sphere + visual sphere) with a 'power' depending of the power of the arriving wave and the distance between the two centers.
I have still to find a way to stop infinite resonance between objects too close from each other (maybe with a limit of time between two created waves?)

1 comment: