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:
dp3 R2.w,,
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
add R15, R3.w, -1.0 + jmp 7 xyzw (>0)
mul,, R3.w
mov R3.w, 1.0
jmp 9
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: