Results 1 to 9 of 9

Thread: 3D ind 2D sample

Hybrid View

  1. #1
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,267
    Blog Entries
    2
    Rep Power
    338

    3D ind 2D sample

    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
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	3Din2D.png 
Views:	240 
Size:	43.8 KB 
ID:	4308  
    Attached Files Attached Files
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  2. #2

    Re: 3D ind 2D sample

    nice example
    Operating System: Windows 10 Home 64-bit
    CPU: AMD C-70 APU 40nm Technology
    Memory: 4.00GB DDR3 @ 533MHz
    Graphics: 256MB ATI AMD Radeon HD 7290 Graphics

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,778
    Blog Entries
    3
    Rep Power
    691

    Re: 3D ind 2D sample

    Dear Mike,

    that is truly awesome !

    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,131
    Blog Entries
    2
    Rep Power
    10

    Re: 3D ind 2D sample

    One day maybe some 3D neuron will switch on in my brain able to understand what you are saing
    The only words I know here is "adventure game"

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,778
    Blog Entries
    3
    Rep Power
    691

    Re: 3D ind 2D sample



    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  6. #6
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397

    Re: 3D ind 2D sample

    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.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #7
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,267
    Blog Entries
    2
    Rep Power
    338

    Re: 3D ind 2D sample

    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
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  8. #8
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397

    Re: 3D ind 2D sample

    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!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  9. #9
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,267
    Blog Entries
    2
    Rep Power
    338

    Re: 3D ind 2D sample

    Plus you need a simplyfied model of the city, to get the depth information plus you can do collision checks with this simplified model.
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

Similar Threads

  1. ODE Sample #02.01
    By ErosOlmi in forum ODE - Open Dynamics Engine
    Replies: 1
    Last Post: 10-08-2007, 22:50
  2. ODE Sample #02.02
    By ErosOlmi in forum ODE - Open Dynamics Engine
    Replies: 2
    Last Post: 10-08-2007, 16:06

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •