2D background for 3D project



  • 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!


  • F

    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


  • F

    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



  • 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!



  • 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 :)


  • F

    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)



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



  • 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.



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


Log in to reply