Results 1 to 9 of 9

Thread: 3D ind 2D sample

  1. #1

    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 Images Attached Images
    Attached Files Attached Files

  2. #2

    Re: 3D ind 2D sample

    nice example
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    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 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    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 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

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

    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

    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

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

    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

    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.

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

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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