The best kittens, technology, and video games blog in the world.

Sunday, July 23, 2006

Code generator works

Code generator for the Renderman shading language compiler I'm writing for a masters thesis works. The world is one (small) step closer to raytracing graphic cards ;-). So now it can go all the way through, from source code to abstract syntax tree to assembly to pretty picture. So it can compile this thing:

color silly(point P; point Eye; color near_color; color far_color)
{
   vector ray = P-Eye;
   float ray_dist = sqrt(ray.ray);
   if(ray_dist < 0)
       ray_dist = 0;
   if(ray_dist > 1)
       ray_dist = 1;

   color c = near_color + (far_color-near_color) * ray_dist;

   return c;
}
To this assembly:
    add R1.xyz, R0.xyz, -R1.xyz
   dp3 R2.w, R1.xyz, R1.xyz
   mov_rsq R15.w, R2.w
   mov_rcp R15.w, S.w
   add R15, 0.0, -S.w + jmp 4 xyzw (>0)
   mov R3.w, S.w
8:
   add R15, R3.w, -1.0 + jmp 7 xyzw (>0)
9:
   add R3.xyz, R3.xyz, -R2.xyz
   mul R3.xyz, R3.xyz, R3.w
   add R0.xyz, R2.xyz, R3.xyz
   return
7:
   mov R3.w, 1.0
   jmp 9
4:
   mov R3.w, 0.0
   jmp 8
For now it only supports functions which pretend to be shaders, not "real" surface shaders. And more about our cool hardware here.

No comments: