Help creating an ambient volume

Blitz3D Forums/Blitz3D Programming/Help creating an ambient volume

RifRaf(Posted 2011) [#1]
Hello again,

im working on a ambient volume lib for bb3d, the function of the lib is
complete which is to allow dynamic shading for entities via entity color
without using alot of processing time or using any linepicks or collisions
to retrieve the shading information.


What I need help with is a more accurate and efficient way to calculate a
ambient value for a single point in 3D space. Currently my volume is a 3
Dimensional Array each cells center is checked for ambient lighting and
its saved to the array. I then blend the values together for smoother
lighting transitions.


Once a volume is made it can be saved and reloaded. Retrieving a volume
shade is as easy as taking the entityXYZ and matching it to the proper
grid space in the volume.

Right now im creating a cells value with many linepicks from its center
outward.. each pick that mises increases the ambient value for that cell..
This is not a correct ambient reading.

So does anyone with math skills above mine(easy enough) willing to help
out here. What im wanting is somthing like this.


;setup scene before hand.. load level mesh and scenery items
;make them pickable or set collisions if need be
;
l

Global Amb_Vol_Red%
Global Amb_Vol_Green%
Global Amb_Vol_Blue%

Function GetAmbientCellValue(X#,y#,z#)
 ;do the magic here
 ;assign the resulting ambients
 Amb_Vol_Red%=resulting_Red%
 Amb_Vol_Green%=resulting_Green%
 Amb_Vol_Blue%=resulting_Blue%
end function


Last edited 2011


RifRaf(Posted 2011) [#2]
small video of the first test I did yesterday. nearly any number of entities can be shaded in real time as they move , I even use it on projectiles and other effects. Once I get the above mentioned code working properly ill add static lights to the sytem too so that maps display glows off of static objects like teleporters or lightbulbs ect.

http://www.empowergames.com/ambvol_test1.wmv


Charrua(Posted 2011) [#3]
it's like a 3d lightmap, ins't it?

Something like precalculating the intensity or influence of lights, ideally on every 3d point (ok zone) and then aplied dinamically.

interesting.

basically you have to do the sum of all light's that "sees" that point (attenuated by distance between them) plus some Ambient (normally constant)

ho knows about the subject use:

attenuation# = 1.0 / (att0 + (att1 * dist) + (att2 * dist^2)

where att0#=0.0, att1#=1.0, att2#=0.0 (as defaults)

dist is the distance between the light and the 3D cell (if there are no obstacles between them)

following is a test code i made when testing a lightmapper for AWC:



hope that help in some way

btw, are you doing linepicks to estimate if there are few or some more objects inmediatly to transform the ammount of ambient light?

juan

Last edited 2011


RifRaf(Posted 2011) [#4]
Thanks for the post.

it's like a 3d lightmap, ins't it?

Something like precalculating the intensity or influence of lights, ideally on every 3d point (ok zone) and then aplied dinamically.


yeah, ive been tesing on a 40,40,40 grid where the grid sizes are dynamically adjusted to the scene size.. so that there arent alot of wasted overlapping cells that are not needed.

btw, are you doing linepicks to estimate if there are few or some more objects inmediatly to transform the ammount of ambient light?


Yes I was using linepicks to check for objects.. so ambient light can sneak a little into a dark room through a window or open door .. how would you go about this without the time consuming linepick, is there a trick ?

Last edited 2011


RifRaf(Posted 2011) [#5]
Ok, I got it sorted. Turned out to be so very simple..

Basically I can get a pretty accurate ambient reading in the volume by starting on the top most row and picking straight down.. whatever the picked location is.. I calculate that cell in the volume grid. That cell and all cells straight above it turn to the brightest setting (255)

thats all the picking I have to do. just one pick per cell along the top.
after setting the verticle columns that need to be set to full bright I run through a loop of cell to cell smoothing. and that it.



Once a volume is created you can set an entities color based on its place in the volume.. Or you can amb_LightMesh a mesh based on the volume which will use vertex colors to map the ambient light onto the mesh as shown below. Even empty space has ambient values you can check.. all done in real time without any additional collision checks or linepicks. Ill post the lib tomorrow , time to get some sleep.


Oh and I have an an addlight(x,y,z,range,r,g,b) in there as well so you can add static lights if you like.







Last edited 2011


Yasha(Posted 2011) [#6]
That looks very cool, nice work.

Something similar to this would be handy (essential?) for something like Thief.


RifRaf(Posted 2011) [#7]
thanks yasha,

Took me longer than i thought, but the Amb_InsetLight() function is working alright now.
Ill tidy up the code and post when I can




RifRaf(Posted 2011) [#8]
ok I posted the library in the code archives
http://www.blitzbasic.com/codearcs/codearcs.php?code=2883

you can also direct download it plus test media here
http://www.empowergames.com/amb_volume.zip

Last edited 2011