Path: chuka.playstation.co.uk!news From: "Mario Wynands" Newsgroups: scea.yaroze.programming.3d_graphics Subject: Re: Lighting Date: Tue, 14 Jul 1998 11:22:45 +1200 Organization: Sidhe Interactive Lines: 62 Message-ID: <6oe4jh$n307@chuka.playstation.co.uk> References: <6odou2$ajq2@scea> NNTP-Posting-Host: p15-max10.wlg.ihug.co.nz X-Newsreader: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Steve Spiller wrote in message <6odou2$ajq2@scea>... >Is there a way to create/simulate point or spotlight lights? Looking >through the library docs it appears you can only have ambient or parallel >lighting... Funnily enough I am working on that exact same thing at the moment (avoiding finishing off some slightly complicated particle systems code :) ), so I should be able to offer some guidance. Firstly, start with a struct something along the lines of typedef struct { int light_type; // point, directional, or spot long da, db, dc; // distance attenuation coefficients long aa, ab, ac; // angle attentuation coefficients for spotlights CVECTOR colour; // colour of light source VECTOR direction; // direction vector for spot and directional GsCOORDINATE2 *coord2; // pointer to coordinate system } Light; Make sure all the polygons in a scene you want affected by the lights are the coloured vertex type (as Craig Graham suggests). When you go to sort an object into the ordering table, iterate through all polygons and light each vertex by applying the (abstract) formula : final_colour = sumof( light_color * dist_attenuation_factor * angle_attentuation_factor * ( light_ray_vector . vertex_normal)) where dist_attenuation_factor = 1 / ( da + db * distance + dc * distance_squared ) angle_attenuation_factor = 1 / ( aa + ab * distance + ac * distance_squared ) or something like that anyway :) This method will happily support directional, point, and spot lights. You may find this slow in complex dynamic scenes, and remember lighting is on a per vertex basis so you may get some artifacting with spotlights, but the results should be good enough. There are several things you could add to this such as diffuse calculations, light 'switches', and ambient lighting etc, but this should be enough to get you started. Cheers, Mario Wynands Director/Project Manager, Sidhe Interactive Sony Playstation Software Development House Email mario@sidhe.co.nz Website www.sidhe.co.nz