Page 1 of 1

Colour fade transitions between two 3D scenes

Posted: Thu Feb 14, 2013 9:17 pm
by gavindi
Hi,

I'm prototyping a game at the moments and I have two 3D scenes. The first is the title screen and the second is the game scene. When the player presses starts, I would like to fade the scene to white or black (or any other colour for that matter) but I can't think of a way to do this other than to create an all-consuming fog.

Or maybe a giant translucent billboard that takes the whole screen and is transitions to opaque and back again when the scene underneath is ready.

I thought I'd ask for suggestions on what is the coolest, best looking approach to this.

Cheers,
G.

Re: Colour fade transitions between two 3D scenes

Posted: Thu Feb 14, 2013 10:24 pm
by Comtois
just added few lines in MaterialTranparent.pb example

Press space bar to start fading

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Material Transparent
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY, RollZ, Blend, Pas = 0.7 

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    CreatePlane(0, 500, 500, 10, 10, 1, 1)
    CreateSphere(1, 5)
    
    CreateTexture(0, 256, 256)
    StartDrawing(TextureOutput(0))
    DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_AlphaBlend)
    Box(0, 0, 256, 256, RGBA(0, 0, 0, 255)) 
    StopDrawing()
    
    CreateMaterial(0, TextureID(0))
    
    MaterialBlendingMode(0, #PB_Material_AlphaBlend)
    
    CreateEntity(0, MeshID(0), MaterialID(0), 0, 0, 250)  
    RotateEntity(0, 90, 0, 0)
    
    SkyBox("stevecube.jpg")
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 8, 300, #PB_Absolute)
    
    Repeat
      Screen3DEvents()
      
      ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Space)
        BlendMode = 1
      EndIf
      
      If BlendMode
        Blend + pas
      EndIf
      
      If blend >= 255 
        BlendMode = 0
        blend = 255
      EndIf  
      
      SetMaterialColor(0, #PB_Material_DiffuseColor, RGBA(255, 255, 255, Blend))
      
      
      CameraLookAt(0, EntityX(0), EntityY(0), EntityZ(0))
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End 

Re: Colour fade transitions between two 3D scenes

Posted: Fri Feb 15, 2013 1:05 am
by gavindi
Awesome suggestion Comtois, thanks. I do notice that no matter what, my Text3D stays in front of the plane. This happens even if I move the text back through the Z coord.

Re: Colour fade transitions between two 3D scenes

Posted: Fri Feb 15, 2013 6:53 am
by Comtois
add a line to fade your text

Code: Select all

 Text3DColor(0, RGBA(255, 0, 0, 255-blend))