i was bored so i tried to write an ambient occlusion render script.

it doesn't really work well but maybe someone wants to improve it.
Code:
bmap b_canvas = <canvas.tga>; // use the same size as screen resolution
panel pnl_canvas
{
bmap = b_canvas;
}
function render()
{
pnl_canvas.visible = on;
randomize();
var yy = 0;
while(yy < screen_size.y)
{
var format;
format = bmap_lock(b_canvas, 0);
var xx = 0;
while(xx < screen_size.x)
{
vec_set(temp, vector(xx, yy, 10000));
vec_for_screen(temp, camera);
c_trace(camera.x, temp, 0);
var color[3];
if(trace_hit)
{
var hits = 0;
var rays = 5; // increase for less noise
var i = 0;
while(i < rays)
{
var from[3];
var to[3];
vec_set(from, target);
vec_add(from, normal); // some offset
vec_set(to, normal);
vec_rotate(to, vector(random(180) - 90, random(180) - 90, 0)); // hemisphere?
vec_normalize(to, 10000);
vec_add(to, target);
c_trace(from, to, 0);
if(trace_hit)
{
hits += 1;
}
i += 1;
}
var shade;
shade = int((1 - (hits / rays)) * 255);
vec_set(color, vector(shade, shade, shade));
}
else
{
vec_set(color, vector(255, 255, 255));
}
var pixel;
pixel = pixel_for_vec(color, 100, format);
pixel_to_bmap(b_canvas, xx, yy, pixel);
xx += 1;
}
bmap_unlock(b_canvas);
yy += 1;
wait(1);
}
}
on_r = render;