4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
ambient occlusion script
#48331
06/26/05 14:22
06/26/05 14:22
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
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;
|
|
|
Re: ambient occlusion script
[Re: mocosgames]
#48337
06/26/05 20:37
06/26/05 20:37
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Look's great on your screen! (Without motion!)
But, how is the framerate, and how does the scene look without the effect?
Last edited by Pappenheimer; 06/26/05 20:40.
|
|
|
Re: ambient occlusion script
[Re: ventilator]
#48340
06/27/05 02:46
06/27/05 02:46
|
Joined: Sep 2003
Posts: 4,959 US
Grimber
Expert
|
Expert
Joined: Sep 2003
Posts: 4,959
US
|
ok couldn't seem to get your script working, but after i butchered it up i got a semi versionish of it. Hers is what i did to the script to at least get the above results ( just changed how the color vector was set for the differnt colors) its based on the trace distance result for color intensity Code:
bmap b_canvas = <canvas.tga>; // use the same size as screen resolution
panel pnl_canvas { bmap = b_canvas; flags = refresh; }
function render() { me = player; var color[3]; var trace_hit; var xx; var i; var pixel; randomize(); var format; var yy = 0; while(yy < screen_size.y) { pnl_canvas.visible = on; format = bmap_lock(b_canvas, 0); xx = 0; while(xx < screen_size.x) { vec_set(temp.x, vector(xx, yy, 2000)); vec_for_screen(temp.x, camera); trace_hit = c_trace(camera.x, temp.x,ignore_me); if (trace_hit !=0) { i = (1-trace_hit/2000)*255; i = int(i); vec_set(color,vector(i,i,i)); } else { i = 255; vec_set(color,vector(i,i,i)); } 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;
can get sort of close to your results be adjusting how the color intensity is calcualted based on distance mabey to make it run even faster and get the pixelation effect could set blocks of pixels. start on row 1 and skip every other row on teh screen then fill in the surrounding pixels example instead of setting xx,yy for every pixel, take a page from interlace monitors. start on second row of pixels 0123-> Y = 0 0123-> Y = 1 0123-> Y = 2 so start X = 1 Y = 1 fill 0,0 1,0 2,0 0,1 1,1 2,1 0,2 1,2 2,2 all in one shot so XX and YY increments would be XX+=3 YY +=3
|
|
|
|