Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    2D background for 3D project

    Help
    5
    9
    545
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JMM161437
      JMM161437 F last edited by

      I've been experimenting with blending and couldn't quite make a 2D background for my 3D project... can anyone help me figure out how to do this? Just a simple explanation would be appreciated!

      1 Reply Last reply Reply Quote 0
      • vinicity
        vinicity F last edited by vinicity

        I think Gothon’s Rubik’s Cube program did that. Take a look!

        https://fuzearena.com/forum/topic/829/rubik-s-cube-toy-simulator/1

        1 Reply Last reply Reply Quote 2
        • Gothon
          Gothon F last edited by Gothon

          That is correct, my program draws the 3D cube on top of a 2D night sky background. In Fuze the 3D drawObjects() function always draws a builtin background (black by default). In order to hide this black screen I draw on additional targets (via setDrawTarget()) using a special image called a mask which keeps track of which pixels are foreground and which ones are background.

          The first thing I do in my program is draw the mask and the cube each to its own buffer. To create the mask, I draw the 3D cube as a 100% pure white object. In the mask everywhere the object is will be {1,1,1,1} == white and the background will be {0,0,0,1} == black. To get an image of the cube, I draw it normally over the black background.

          With these two images ready I can draw the scene to the main frameBuffer draw target. I start by drawing the background. Then I subtract the mask using the minus blend mode. Every color minus white will be black, and every color minus black will be itself. This will create a black hole in the background where I can draw the foreground object. I then blend that object into the hole using the add blend mode with the cube image. (anything + black = itself) Finally I draw any foreground 2D user interface / HUD on top.

          The following image from Wikipedia shows traditional masking using boolean logic based blending operations rather than the arithmetic based ones available in Fuze.
          masking illustration
          https://en.wikipedia.org/wiki/Mask_(computing)#Image_masks

          1 Reply Last reply Reply Quote 7
          • JMM161437
            JMM161437 F last edited by

            wow thank you very much @Gothon ! I messed with this for hours and only got the image to show in the 3D object like a window... this is is very helpful!

            1 Reply Last reply Reply Quote 1
            • JMM161437
              JMM161437 F last edited by

              It worked! got a red cube to rotate in front of the image! the masking object needed to glow to make the object more solid but it worked! thanks so much! can't wait to implement this into my new game :)

              1 Reply Last reply Reply Quote 4
              • SteveZX81
                SteveZX81 F last edited by

                Gothon is a genius without a doubt, I really admire his amazing level of talent (and yes I'll admit I'm jealous as hell. haha)

                1 Reply Last reply Reply Quote 4
                • JMM161437
                  JMM161437 F last edited by

                  @SteveZX81 ha yeah his FUZE creations are amazing. and the way he makes it happen is pure genius!

                  1 Reply Last reply Reply Quote 1
                  • F
                    fgalliat last edited by

                    Hey, thanks, you saved my project !
                    I had to deal w/ setMaterial( black / white / color ) to build my mask & scene
                    Used different modes w/ setBlend() then finally it worked !
                    I'll try to clean my code then post some screenshots for source.

                    F 1 Reply Last reply Reply Quote 1
                    • F
                      fgalliat @fgalliat last edited by

                      @fgalliat : here are shots : init.jpg render.jpg ... thanks again

                      1 Reply Last reply Reply Quote 5
                      • First post
                        Last post