Monday, February 10, 2014

Shock Wave Refraction Pixel Shader

Yesterday I had a few hours time and tweaked my explosion effects a little bit. Its not 100% finished, but have a first look:

Shock Wave Pixel Shader from Jan Tepelmann on Vimeo.

The implementation is straight forward. I use a pixel shader to manipulate the drawn pixels around the explosion. To be able doing this you have to render the whole scene first to a full screen quad. For more details about post-processing with full screen quads, heres a nice blog post about it. By drawing to the quad you can execute a pixel shader for every drawn pixel. The vertex shader does nothing in this case. This process is called post processing and effects like HDR, Bloom or more advanced effects like Screen Space Ambient Occlusion (SSAO) are realized in that way. But the possibilities for different effects are endless. Also deferred shading is some kind of post processing effect (nice slides explaining deferred shading).
In SunBurn you can simply create a post processor by deriving from a specific base class. This class uses a full screen quad for appling a pixel shader on the current frame.
The post processor is responsible for passing all the input variables to the actual shader and maybe do some pre processing. In my case I had to transform the explosions world positions into the coordinate system of the full screen quad. This is simply the texture coordinate space with (0,0) at the top left and (1,1) at the bottom right. Thats different to the normal projection process with the view-projection matrix! To get everything right I made a sketch how the positions have to be transformed.

Transformation from world space coordinates to texture coordinates
Next I want to add a refraction effect to the space ship engines.

No comments:

Post a Comment