I've worked up something that demonstrates generating an alpha channel the way I mentioned. The problem is that I can't figure out how to use the alpha channel.
Things to do with this, if someone can show me how. I've set up a rotating box with a camera (camera number 3) looking at it. This camera is set to an image. The idea is that we use the alpha channel we're generating (camera number 2) to make the image from camera 3 transparent. Then we paste this transparent image ontop of the screen.
The effect SHOULD make it so that all the randomly scattered boxes act like a crazy sort of view port to the camera looking at the box. Sort of like cutting a hole in space with the rotating box behind the hole.
sync on
sync rate 00
autocam off
hide mouse
` Camera 0 will be used to render the stars
backdrop on 0
set camera range 0, 300000, 50000000
` Camera 1 will be used to render nearby objects
make camera 1
backdrop off 1
set camera range 1, 1, 3000
` Camera 2 will be used to generate an alpha channel
make camera 2
backdrop on 2
color backdrop 2, rgb(0,0,0)
set camera to image 2, 1, screen width(), screen height()
set camera range 1, 1, 3000
` Make 2000 stars
ya as float
xa as float
make object plain 1, 5000, 5000
set object light 1, 0
disable object zwrite 1
for i = 1 to 2000
if i > 1 then instance object i, 1
ya = rnd(359000.0)/1000.0
xa = 90-(rnd(179000.0)/1000.0)
rotate object i, xa, ya, rnd(360)
move object i, 2000000
next
` Make a few nearby objects
make object cube 5000, 10
for i = 5001 to 5100
instance object i, 5000
position object i, rnd(1000)-500, 0, rnd(1000)-500
next
` Make a floor
make object plain 4999, 1000, 1000
rotate object 4999, -90.0, 0.0, 0.0
color object 4999, rgb(0, 255, 0)
fix object pivot 4999
position object 4999, 0.0, -5.0, 0.0
`Make a spinning box with a camera watching it for mapping over the screen with our alpha channel
make object cube 5101, 100
position object 5101, 0, 1000000, 0 `set the box WAAAAAY out of the way so it NEVER renders on the normal cameras
make camera 3 `make the camera
position camera 3, 0, 1000000, -200 `move the camera into position
set camera to image 3, 2, screen width(), screen height() `It needs to render to a texture so we can paste it
make light 1 `make a light to illuminate the box
set spot light 1, 0, 90 `make the light a spot light
position light 1, -200, 1000400, -400 `move the light into position
point light 1, 0, 1000000, 0 `point the light at the box
do
position mouse screen width() / 2, screen height() / 2
set cursor 0, 0
print screen fps()
` Object only moves horizontally
if upkey() then move object 5000, 1.0
if downkey() then move object 5000, -1.0
` Look all around, but stop up/down angles from going too far
ya = wrapvalue( camera angle y(0) + mousemovex() )
xa = wrapvalue( camera angle x(0) + mousemovey() )
if xa > 70 and xa < 290
if xa < 180
xa = 70
else
xa = 290
endif
endif
` Apply rotations and movement to cameras and movement object
for c = 0 to 2
rotate camera c, xa, ya, 0.0
next
position camera 1, object position x(5000), object position y(5000), object position z(5000)
position camera 2, object position x(5000), object position y(5000), object position z(5000)
`######################
`Generate Alpha Channel
`######################
lock backbuffer `lock the backbuffer so that our syncs don't actually draw to screen
set object ambience 4999, 0 `make sure the floor doesn't get any ambient light
hide light 0 `turn off the light so that only things which aren't affected by light show up
set object light 5000, 0 `set the boxes to not be affected by light
sync `snapshot the camera so we can use and manipulate the alpha channel image
if spacekey() `take a screenshot if the user presses the space key, to demonstrate the alpha channel creation
save image "test.bmp", 1
endif
show light 0 `turn the lights back on
set object light 5000, 1 `let the boxes recieve light again
set object ambience 4999, 1 `let the ground take ambient light again
sync `resync it so that we can pretend like the alpha channel stuff nothing ever happened
unlock backbuffer `unlock the back buffer so we can resume real time rendering
`##########################
`Resume Normal Camera Stuff
`##########################
`next
rotate object 5000, 0.0, ya, 0.0 `i'm not sure why this is down here and not way up there, but i'm not touching it
sync
loop