Tuesday, April 30, 2013

HELL, IT'S ABOUT TIME!

Finally, we got to build something cool with our renderer.

To me, "cool" is not about how realistic things are, but how artistic they are. That's why I build this, for your consideration:



I spent some time doing the swirl effect on that giant sphere in the middle, which turns out to be very sweet. Like many cool effects, this one requires post processing (in this case the opaque texture). Once I got the texture and data required for the texture coordinates look-up, the rest is all in pixel shader, and this is the core part of the effect:


float2 center = float2(0.5,0.5);
float2 toUV = texcoord_screen - center;
float distanceFromCenter = length(toUV);
float2 normToUV = toUV / distanceFromCenter;
float angle = atan2(normToUV.y, normToUV.x);

angle += distanceFromCenter * distanceFromCenter * (20* sin(g_secondsElapsed/10));
float2 newUV;
sincos(angle, newUV.y, newUV.x);
newUV *= distanceFromCenter;
newUV += center;

float4 c1 = tex2D(g_textureSampler, newUV);
        float4 c2 = tex2D(g_textureSampler, texcoord_screen);
        float4  textureSample =  lerp(c1,c2, 0.3); //this is for the partial transparency

As you can see, I set the center to 0.5, 0.5 (which is the center of the screen), instead of the center of that sphere (which could be done by passing the position of the sphere and the world_to_view, view_to_projected transform matrix). I didn't bother to do it because the sphere is big enough that there is no point to do that. I was planning on making that sphere a black hole, parallel to the moon that behind it, but it doesn't look that good since the effect is too small and the black hole needs something more than just a swirl effect.


As for other objects, it's nothing we haven't done before. 

  • The rook and the ground is done by using environment map. 
  • The knight has a normal map with a soft intersection effect. 
  • As for the moon that you can't see, it's using the normal diffuse lighting with a normal map. 
  • The background is a simple plane with lighting disabled in fragment shader.
  • The UI is just ... UI, plus a vignetting effect.
Controls:
WASD - to move all the objects.
UOJKIL - to move the directional light to control the shadow.

Anyways, enough for talking, let's enjoy this image for another minute and call this an end.

Link to the code:






No comments:

Post a Comment