Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 609 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
ambient occlusion script #48331
06/26/05 14:22
06/26/05 14:22
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline 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: ventilator] #48332
06/26/05 15:24
06/26/05 15:24
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline
Serious User
jumpman  Offline
Serious User

Joined: Apr 2002
Posts: 1,246
ny
What is that trying to do other than add noise?

Re: ambient occlusion script [Re: jumpman] #48333
06/26/05 16:22
06/26/05 16:22
Joined: Sep 2003
Posts: 489
Switzerland
Dragon Offline
Senior Member
Dragon  Offline
Senior Member

Joined: Sep 2003
Posts: 489
Switzerland
Nothing
but isn't noise enough?


Re: ambient occlusion script [Re: Dragon] #48334
06/26/05 16:26
06/26/05 16:26
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
it's supposed to calculate "realistic" outdoor lighting with soft shadows like on an overcast day. ...the updated screenshot has some post blur added.

Re: ambient occlusion script [Re: ventilator] #48335
06/26/05 18:52
06/26/05 18:52
Joined: May 2005
Posts: 83
Texas
mocosgames Offline
Junior Member
mocosgames  Offline
Junior Member

Joined: May 2005
Posts: 83
Texas
It sort of looks like night vision. Maybe you could make everything look green and use it as a night vision script.

Re: ambient occlusion script [Re: ventilator] #48336
06/26/05 20:37
06/26/05 20:37
Joined: Sep 2003
Posts: 4,959
US
G
Grimber Offline
Expert
Grimber  Offline
Expert
G

Joined: Sep 2003
Posts: 4,959
US
i don;t seem to bealbe to make the proper TGA file for this script. give example or proper steps ( I can't figure out how to apply ANY alpha channel to a tga)

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 Offline
Senior Expert
Pappenheimer  Offline
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: Pappenheimer] #48338
06/26/05 21:01
06/26/05 21:01
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
it's not meant to be realtime. the above screen took about 15 seconds to render for 640x480 and 8 rays per pixel. it was just an experiment. ambient occlusion is a kind of fake global illumination method you can also use with the renderers of tools like maya. i thought it maybe would be nice to record animations with 3dgs and then output movies with this method but getting good results without too much noise is harder than i thought. of course you could also mix in the textures of the geometry. it could also be used to bake the shadows into textures.

the tga just has to be 24bit and the same size as your screen resolution.

Re: ambient occlusion script [Re: ventilator] #48339
06/27/05 01:00
06/27/05 01:00
Joined: Sep 2003
Posts: 4,959
US
G
Grimber Offline
Expert
Grimber  Offline
Expert
G

Joined: Sep 2003
Posts: 4,959
US
k well i tried 24 bit tga, even differnt colors. screen just turns black as it rolls progresses down the screen.

must be my video card or some thing.

Re: ambient occlusion script [Re: ventilator] #48340
06/27/05 02:46
06/27/05 02:46
Joined: Sep 2003
Posts: 4,959
US
G
Grimber Offline
Expert
Grimber  Offline
Expert
G

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

Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1