PDA

View Full Version : 3D ind 2D sample



Michael Hartlef
28-10-2007, 16:59
Hi folks,

I promised a little sample for a new functionality in TBGL, that you can erase the color buffer, but let the depth buffer still have it's values.
Mostly you see this approach in adventure games, where you have a 3D character
infront of a prerendered scene.

Ok, here is a little sample script. The platform and cube you see is prerendered in BLENDER. The ball is created with TBGL. You can move the ball via A/W/S/Y . The tricky part is to find the right camera position that reassembles the settings in Blender. For some reason I had to rotate it 40 degrees instead of 50 like in Blender. ???
Right now the FOV you have use is 45 degrees but Petr will give use the ability to set different values.

Have fun
Michael

matthew
28-10-2007, 18:04
nice example :)

Petr Schreiber
28-10-2007, 20:07
Dear Mike,

:o that is truly awesome :o!

It seems Blender takes looking to ground plan ( 0, -1, 0 ) as zero, while TBGL looks forward ( 0, 0, 1 ), not into ground.
And from this positive angles grow clockwise, while in TBGL ( and OpenGL ) it is counter clickwise.
That is why 40(in TBGL)+50(in Blender) makes 90° - thats angular distance between two vectors mentioned above.

Wow wow wow again,
I knew you are very talented, but this is really cool,
Petr

ErosOlmi
28-10-2007, 20:20
One day maybe some 3D neuron will switch on in my brain able to understand what you are saing :D
The only words I know here is "adventure game" :)

Ciao
Eros

Petr Schreiber
28-10-2007, 20:39
:)

What Mike did, is that he rendered scene in Blender modeller, including shadows for example and made possible to place 3D object ( sphere ) there, which can go "behind" the rendered object in real time.

Trick is that he uses original scene geometry just as depth mask, rendered image as stealing beauty which is visible and sphere is TBGL defined stuff.

This is script worth article ;), really smart!


Petr

kryton9
28-10-2007, 20:53
Ok, am I getting this? The plane, cube and such is just an image. The only real 3d object is the ball. How in the world is it knowing where to clip the ball so it looks like it is part of the background scene?

Mike this is a very interesting example you made... I am looking at the code and not getting it. Maybe once I wake up more. But very cool for sure.

Michael Hartlef
28-10-2007, 21:37
I think you are right Petr about the vectors. Have to experiment a little more with it.

Kent and Eros: I rendered the ground plane and the cube in Blender and exported the image. I also exported the Blender scene to an M15.

In TB first I render the scene with the ground plane and cube. Next I do TBGL_CLEARFRAME, but without clearing the depth buffer. OpenGL has a color buffer and a depth buffer. The color buffer ofcourse stores the pixel colors. The depth buffer stores the z-coordinate of each pixel. When you draw a new polygon, OpenGL knows if the color has to be stored inside the color buffer or not. Only if it is infront (closer to the camera) of the original pixel. And because I just clear the color, the depth info from the groundplane and the cube is still there.

Next I draw the background image, but first I tell TBGL not to write to the depth buffer when I draw the image. After that I turn on using the depth buffer again and then draw the ball. And here the depth buffer info is taken into count and so it only draws the ball over the picture, where it is infront of the old hidden scene.

I hope I made it a little more clearly.

Michael

kryton9
29-10-2007, 05:17
Thanks Mike, ok now I can see what is going on when I read what you wrote and the look at the code.

I guess this would be handy with a very complex background geometry like a city and instead of having to render the city each time, you do it once, then use an image for subsequent screen updates and the object that will move like a car. That is an awesome trick and demo!! Thanks!!

Michael Hartlef
29-10-2007, 08:08
Plus you need a simplyfied model of the city, to get the depth information plus you can do collision checks with this simplified model.