posts about gpu generated visuals
December 17th, 2010

Sphere-renderer

shader based sphere renderer from johan holwerda on Vimeo.

This is a pixelshader that draws spheres on pointsprites. This allows the spheres to be perfectly round, and to have a lot of them in view in realtime.
They intersect as though they are spheres (and not like the planes which they are drawn on). This is done by rendering the sprites to the depth-buffer as though they were spheres.

Here’s the pixel-shader code :
-first render point-sprites, and let the vertex-shader pass their depth to the pixel-shader.


void PS_ShowDepth(VS_OUTPUT input, out float4 color: COLOR0,out float depth : DEPTH)
{
float dist = length (input.uv - float2 (0.5f, 0.5f)); //get the distance form the center of the point-sprite
float alpha = saturate(sign (0.5f - dist));
sphereDepth = cos (dist * 3.14159) * sphereThickness * particleSize; //calculate how thick the sphere should be; sphereThickness is a variable.

depth = saturate (sphereDepth + input.color.w); //input.color.w represents the depth value of the pixel on the point-sprite
color = float4 (depth.xxx ,alpha ); //or anything else you might need in future passes
}

1 Comment »

  1. [...] I am using code similar to that written by Johna Holwerda: [...]

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under GPL - 2009 | Powered by Wordpress using the theme aav1