Hey,
I'm looking into making a volumetric smoke effect, and I found this good example:
Rem Project: Smoke
Rem Created: 30.05.2005 15:53:14
Rem ***** Main Source File *****
`Create smoke image
create bitmap 1,50,50
ink rgb(250,200,100),0
for x=1 to 1000
ang=rnd(360)
rad=rnd(20)
dot 25+sin(ang)*rad,25+cos(ang)*rad
next x
blur bitmap 1,4
img = free_image()
get image img,0,0,50,50
delete bitmap 1
Type Vectors
x As Float
y As Float
z As Float
EndType
Type Particle
p As Vectors
v As Vectors
sz As Vectors
Fade As Float
EndType
make matrix 1,1000,1000,20,20
position camera 0,20,-50
GOSUB makeSmoke
t = 10000
make object cube t, 10
`sync on
sync rate 60
do
text 0, 0, str$(screen fps())
`text 0, 0, str$(camera position x())+":"+str$(camera position y())+":"+str$(camera position z())
`text 0, 10, str$(camera angle x())+":"+str$(camera angle y())+":"+str$(camera angle z())
`position object t, camera position x(), camera position y(), camera position z()
`rotate object t, camera angle x(), camera angle y(), camera angle z()
`move object t, 10
GOSUB loopSmoke
if leftkey() then windx# = windx# - 0.01
if rightkey() then windx# = windx# + 0.01
if upkey() then windz# = windz# + 0.01
if downkey() then windz# = windz# - 0.01
camera#=wrapvalue(camera#+0.3)
position camera -sin(camera#)*128.0,30,100+cos(camera#)*128.0
point camera 0.0,0.0,100+0.0
`sync
loop
makeSmoke:
ttlPrc = 400
objPrc = free_object()
DIM Particles(ttlPrc) As Particle
`Make particles
for x=objPrc to objPrc+ttlPrc
make object plain x,10,10
`make object triangle x, -10, 0, 0, 0, 10, 0, 10, 0, 0
texture object x, 0, img
hide object x
ghost object on x,0
set object transparency x, 2
set alpha mapping on x, 100
disable object zread x `THIS LINE NEEDS AN ALTERNATIVE
next x
RETURN
loopSmoke:
`Loop through particles
for t=1 to ttlPrc
Particles(t).sz.x = Particles(t).sz.x + 0.5
Particles(t).sz.y = Particles(t).sz.y + 0.5
Particles(t).p.x = Particles(t).p.x + Particles(t).v.x + windx#
Particles(t).p.y = Particles(t).p.y + Particles(t).v.y
Particles(t).p.z = Particles(t).p.z + Particles(t).v.z + windz#
`Fade particle value
Particles(t).Fade = Particles(t).Fade - 1
`Position, scale and fade particle object
position object objPrc+t-1,Particles(t).p.x,Particles(t).p.y,Particles(t).p.z
scale object objPrc+t-1,Particles(t).sz.x,Particles(t).sz.y,100
fade object objPrc+t-1,Particles(t).Fade
`Point at camera
set object to camera orientation objPrc+t-1
next t
inc i
if i>ttlPrc then i=1
if Particles(i).Fade < 0
`Position
Particles(i).p.x = 0
Particles(i).p.y = 0
Particles(i).p.z = 100
`Scale
Particles(i).sz.x = 50
Particles(i).sz.y = 50
`Velocity (randomize)
Particles(i).v.x = rnd(100)/1000.0-0.1
Particles(i).v.y = rnd(200)/1000.0+0.1
Particles(i).v.z = rnd(100)/1000.0-0.1
Particles(i).Fade = ttlPrc / 2.0
`Show the particle
show object objPrc+i-1
endif
RETURN
Function free_object()
Repeat
Inc i
Until Object Exist(i) = 0
EndFunction i
Function free_image()
Repeat
Inc i
Until Image Exist(i) = 0
EndFunction i
The only problem is on line 77, where the smoke has the zdepth disabled. This creates a better looking smoke effect, as you can see if you run it, the transparent planes don't interfere with each other. Of course, this means that no objects can appear between the camera and the smoke or the smoke will appear on front. Does anyone know how to stop these transparency artifacts without disabling the zdepth?
EDIT: Of course, as soon as I post it, I find the answer...
it seems that "disable object zWRITE" works. It seems to render objects between the camera and smoke correctly and doesn't have the problems with transparency.