Page 1 of 1

Simple animated custom skybox fun.

Posted: Wed Oct 29, 2014 10:21 pm
by DK_PETER

Code: Select all

;SkyBox
;By DK_PETER
;Simple animated skybox...

EnableExplicit
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

Structure _TheSet
  id.i
  ms.i
  ma.i
  cl.i
  tx.i
EndStructure

Structure _Sky
  lf._TheSet
  rt._TheSet
  up._TheSet
  dn._TheSet
  bk._TheSet
  fr._TheSet
  node.i
  twink.i
  SkySize.i
EndStructure

Structure _Vars
  Scw.i
  Sch.i
  FScr.i
  Win.i
  Cam.i
  Path.s
EndStructure

Declare.i SetResolution(Width.i = -1, Height.i = -1, FS.i = #False)
Declare.i CreateSkyboxImages(Size.i = 2048)
Declare.i DoBaseStars(Img.i, Total.i = 2000)
Declare.i DoNebulae(Fract.i = 3)
Declare.i CreateSkyboxImages(Size.i = 2048)
Declare.i MyBox(Name.s)

Global va._Vars, sk._Sky

Procedure SetResolution(Width.i = -1, Height.i = -1, FS.i = #False)
  va\FScr = FS
  If Width = -1 Or Height= -1
    ExamineDesktops()
    va\Scw = DesktopWidth(0):va\Sch = DesktopHeight(0)
  Else
    va\Scw = Width:va\Sch = Height
  EndIf
  
  If FS = #False
    va\Win = OpenWindow(#PB_Any, 0, 0, va\Scw, va\Sch, "Launch",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(va\Win), 0, 0, va\Scw, va\Sch, #False, 0, 0)
  Else
    OpenScreen(va\Scw, va\Sch, 32, "Launch")
  EndIf
  va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
  sk\node = CreateNode(#PB_Any, 0, 0, 0)
EndProcedure

Procedure.i DoBaseStars(Img.i, Total.i = 2000)
  Protected count.i, tmcol.i, alp.i
  StartDrawing(TextureOutput(Img))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  For count = 1 To Total
    tmcol = Random(255,100)
    alp   = Random(255,50)
    Circle(Random(TextureWidth(Img)-1, 1), Random(TextureHeight(Img)-1,1),2,RGBA(tmcol,tmcol,tmcol,alp))
  Next Count
  StopDrawing()
EndProcedure

Procedure.i DoTwink()
  Protected newtx.i, count.i
  newtx = CreateTexture(#PB_Any, sk\SkySize, sk\SkySize)
  StartDrawing(TextureOutput(newtx))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  Box(0,0,sk\SkySize, sk\SkySize, $0)
  For count = 1 To 4500
    Circle(Random(TextureWidth(newtx)-1, 1), Random(TextureHeight(newtx)-1,1),1,$58FFFFFF)
  Next Count
  StopDrawing()
  ProcedureReturn newtx
EndProcedure

Procedure.i DoNebulae(Fract.i = 3)
  Protected pox.i, poy.i, raax.i, raay.i,TheMax.i, x.i, y.i, tx.i
  tx = CreateTexture(#PB_Any, sk\SkySize, sk\SkySize)
  StartDrawing(TextureOutput(tx))
  Box(0, 0, TextureWidth(tx), TextureHeight(tx), $0)
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AlphaBlend)
  TheMax = TextureWidth(tx)/4
  For y = 0 To Fract
    BackColor(RGBA(Random(255,50),Random(255,80),Random(255,80),Random(30,10))):FrontColor($02111111)
    For x = 0 To 5
      pox = Random(TextureWidth(tx)-TheMax, TheMax)
      poy = Random(TextureWidth(tx)-TheMax, TheMax)
      raax = Random(TheMax,TheMax/2):raay = Random(TheMax,TheMax/2)
      EllipticalGradient(pox, poy, raax, raay)
      Ellipse(pox, poy, raax, raay)
    Next x
  Next y
  StopDrawing()
  ProcedureReturn tx
EndProcedure

Procedure.i CreateSkyboxImages(Size.i = 2048)
  sk\SkySize = Size
  sk\twink = DoTwink()
  sk\bk\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\bk\tx,Random(3000,1000))
  sk\bk\cl = DoNebulae(Random(4,0))
  sk\dn\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\dn\tx,Random(3000,1000))
  sk\dn\cl = DoNebulae(Random(4,0))
  sk\fr\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\fr\tx,Random(3000,1000))
  sk\fr\cl = DoNebulae(Random(4,0))
  sk\lf\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\lf\tx,Random(3000,1000))
  sk\lf\cl = DoNebulae(Random(4,0))
  sk\rt\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\rt\tx,Random(3000,1000))
  sk\rt\cl = DoNebulae(Random(4,0))
  sk\up\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\up\tx,Random(3000,1000))
  sk\up\cl = DoNebulae(Random(4,0))
EndProcedure

Procedure.i MakeSkybox(Name.s = "Sky")
  With sk\fr
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma),0 + MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, -90, 0, 0, #PB_Absolute)
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam), CameraZ(va\cam) + TextureWidth(\tx)/2, #PB_Absolute)
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\bk
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, 90, 180, 0, #PB_Absolute) 
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam), CameraZ(va\cam)-TextureWidth(\tx)/2, #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\up
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, 180, 0, 0, #PB_Absolute) 
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam)+TextureWidth(\tx)/2, CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\dn
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, 0, 0, 0, #PB_Absolute)
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam)-TextureWidth(\tx)/2, CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\rt
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, -90, 0, 90, #PB_Absolute)     
    MoveEntity(\id, CameraX(va\cam)+TextureWidth(\tx)/2, CameraY(va\cam), CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\lf
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, -90, 0, -90, #PB_Absolute)     
    MoveEntity(\id, CameraX(va\cam)-TextureWidth(\tx)/2, CameraY(va\cam), CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
EndProcedure

Procedure.i RunNow()
  Protected ev.i
  Repeat
    If va\FScr = #False
      Repeat
        ev = WindowEvent()
      Until ev = 0
    EndIf
    ExamineMouse()
    
    RotateCamera(va\Cam, -MouseDeltaY() * 0.03, -MouseDeltaX() * 0.03, 0, #PB_Relative)
    ;MoveNode(sk\node, CameraX(va\Cam), CameraY(va\Cam), CameraZ(va\Cam))
    ;To those I teach (Not active forum members):
    ;Test demo på pc 1 til 8.
    RenderWorld()
    
    ExamineKeyboard()
    
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape)
  End
EndProcedure

SetResolution()
CreateSkyboxImages()
MakeSkybox()
RunNow()

Re: Simple animated custom skybox fun.

Posted: Fri Oct 31, 2014 5:16 am
by applePi
now i see the stars , yesterday i was not able to see the twinkling stars may be because there was too light in the room or you have brightening the stars more, great demo, thanks, and happy Halloween!
Twinkle twinkle little star
How i wonder what you are
Up above the world so high
Like a diamond in the sky
http://www.youtube.com/watch?v=nu_fqaFWO_w

Re: Simple animated custom skybox fun.

Posted: Fri Oct 31, 2014 8:29 am
by Bananenfreak
Great example.
I like it much :)

Re: Simple animated custom skybox fun.

Posted: Fri Oct 31, 2014 5:45 pm
by heartbone
Thanks for sharing that excellent educational example DK_PETER.

Best of all, it ran on my computer! (Linux :))

Re: Simple animated custom skybox fun.

Posted: Mon Nov 03, 2014 1:37 pm
by DK_PETER
I'm glad you all liked it.

To forum members.
--------------------------------------------
What we're trying to mimic is the skybox effect and auroras
from Borderlands 2. Actually the teenagers I'm tutoring has
forced me to try to achieve the effects. I accepted the challenge. :-)
I will figure the effects out eventually myself - but if anyone has
any ideas - please, don't hold back - feel free to add your code or your ideas.
I might not be able to answer right away, but I'll drop by once in a while when time permits it.

Next example requires the following:

save the following images to a folder named "texture"

Image 1: https://www.dropbox.com/s/eb53a2eoa1s705p/a4.jpg?dl=0
Image 2: https://www.dropbox.com/s/3wa0kso1fv3lt6p/a5.jpg?dl=0

Save this script to a folder named "material"
Filename: au.material

Code: Select all

material "au1mat"
 {
    technique
    {
       pass
        {
       	  scene_blend add
       	  depth_write off
          texture_unit
          {
            texture a4.jpg
	    wave_xform scale_y sine 1.0 0.4 0.0 0.01
          }

          texture_unit
          {
            texture a5.jpg
            colour_op modulate
	    wave_xform scale_y sine 1.0 -0.2 0.0 0.05
          }
        }   
    }
 }

Code:

Code: Select all

;SkyBox + aurora example (aurora lights test 1 - WIP)
;By DK_PETER
;To those I teach: Not forum members.
;Danish
;Jeg har tilføjet en simpel nordlys effekt til skybox'en.
;Undersøg proceduren CreateAurora()
;Prøv at ændre værdier og tilføj ekstra lag. (AddMaterialLayer())
;Vi vil gå nærmere i dybden med scripts senere og udvide den viden som vi har lært her.
;Test demo på pc 1 til 8 (Bedsted)
;Test demo på pc 1 til 4 (Hurup)
;Vi ses.
;-----------------------------------------------------------------------------------------
;To those who are curious and want the translation:
;I've added a simple aurora effect to the skybox.
;Examine the procedure CreateAurora().
;We will study scripts further later and expand our knowledge on what we've learned here.
;--------------------------------------------

EnableExplicit
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
UseJPEGImageDecoder()

Structure _TheSet
  id.i
  ms.i
  ma.i
  cl.i
  tx.i
EndStructure

Structure _Sky
  lf._TheSet
  rt._TheSet
  up._TheSet
  dn._TheSet
  bk._TheSet
  fr._TheSet
  node.i
  twink.i
  SkySize.i
EndStructure

Structure _Vars
  Scw.i
  Sch.i
  FScr.i
  Win.i
  Cam.i
  Path.s
EndStructure

Declare.i SetResolution(Width.i = -1, Height.i = -1, FS.i = #False)
Declare.i CreateSkyboxImages(Size.i = 2048)
Declare.i DoBaseStars(Img.i, Total.i = 2000)
Declare.i DoNebulae(Fract.i = 3)
Declare.i CreateSkyboxImages(Size.i = 2048)
Declare.i CreateAurora()
Declare.i MyBox(Name.s)

Global va._Vars, sk._Sky, aura._TheSet, lgt.i

Procedure SetResolution(Width.i = -1, Height.i = -1, FS.i = #False)
  va\FScr = FS
  If Width = -1 Or Height= -1
    ExamineDesktops()
    va\Scw = DesktopWidth(0):va\Sch = DesktopHeight(0)
  Else
    va\Scw = Width:va\Sch = Height
  EndIf
  
  If FS = #False
    va\Win = OpenWindow(#PB_Any, 0, 0, va\Scw, va\Sch, "Launch",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(va\Win), 0, 0, va\Scw, va\Sch, #False, 0, 0)
  Else
    OpenScreen(va\Scw, va\Sch, 32, "Launch")
  EndIf
  va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(va\Cam, 0, 0, 0, #PB_Absolute)
  sk\node = CreateNode(#PB_Any, 0, 0, 0)
EndProcedure

Procedure.i DoBaseStars(Img.i, Total.i = 2000)
  Protected count.i, tmcol.i, alp.i
  StartDrawing(TextureOutput(Img))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  For count = 1 To Total
    tmcol = Random(255,100)
    alp   = Random(255,50)
    Circle(Random(TextureWidth(Img)-1, 1), Random(TextureHeight(Img)-1,1),2,RGBA(tmcol,tmcol,tmcol,alp))
  Next Count
  StopDrawing()
EndProcedure

Procedure.i DoTwink()
  Protected newtx.i, count.i
  newtx = CreateTexture(#PB_Any, sk\SkySize, sk\SkySize)
  StartDrawing(TextureOutput(newtx))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  Box(0,0,sk\SkySize, sk\SkySize, $0)
  For count = 1 To 4500
    Circle(Random(TextureWidth(newtx)-1, 1), Random(TextureHeight(newtx)-1,1),1,$58FFFFFF)
  Next Count
  StopDrawing()
  ProcedureReturn newtx
EndProcedure

Procedure.i DoNebulae(Fract.i = 3)
  Protected pox.i, poy.i, raax.i, raay.i,TheMax.i, x.i, y.i, tx.i
  tx = CreateTexture(#PB_Any, sk\SkySize, sk\SkySize)
  StartDrawing(TextureOutput(tx))
  Box(0, 0, TextureWidth(tx), TextureHeight(tx), $0)
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AlphaBlend)
  TheMax = TextureWidth(tx)/4
  For y = 0 To Fract
    BackColor(RGBA(Random(255,50),Random(255,80),Random(255,80),Random(30,10))):FrontColor($02111111)
    For x = 0 To 5
      pox = Random(TextureWidth(tx)-TheMax, TheMax)
      poy = Random(TextureWidth(tx)-TheMax, TheMax)
      raax = Random(TheMax,TheMax/2):raay = Random(TheMax,TheMax/2)
      EllipticalGradient(pox, poy, raax, raay)
      Ellipse(pox, poy, raax, raay)
    Next x
  Next y
  StopDrawing()
  ProcedureReturn tx
EndProcedure

Procedure.i CreateSkyboxImages(Size.i = 2048)
  sk\SkySize = Size
  sk\twink = DoTwink()
  sk\bk\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\bk\tx,Random(3000,1000))
  sk\bk\cl = DoNebulae(Random(4,0))
  sk\dn\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\dn\tx,Random(3000,1000))
  sk\dn\cl = DoNebulae(Random(4,0))
  sk\fr\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\fr\tx,Random(3000,1000))
  sk\fr\cl = DoNebulae(Random(4,0))
  sk\lf\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\lf\tx,Random(3000,1000))
  sk\lf\cl = DoNebulae(Random(4,0))
  sk\rt\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\rt\tx,Random(3000,1000))
  sk\rt\cl = DoNebulae(Random(4,0))
  sk\up\tx = CreateTexture(#PB_Any, Size, Size)
  DoBaseStars(sk\up\tx,Random(3000,1000))
  sk\up\cl = DoNebulae(Random(4,0))
EndProcedure

Procedure.i MakeSkybox(Name.s = "Sky")
  With sk\fr
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma),0 + MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, -90, 0, 0, #PB_Absolute)
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam), CameraZ(va\cam) + TextureWidth(\tx)/2, #PB_Absolute)
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\bk
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, 90, 180, 0, #PB_Absolute) 
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam), CameraZ(va\cam)-TextureWidth(\tx)/2, #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\up
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, 180, 0, 0, #PB_Absolute) 
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam)+TextureWidth(\tx)/2, CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\dn
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, 0, 0, 0, #PB_Absolute)
    MoveEntity(\id, CameraX(va\cam), CameraY(va\cam)-TextureWidth(\tx)/2, CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\rt
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, -90, 0, 90, #PB_Absolute)     
    MoveEntity(\id, CameraX(va\cam)+TextureWidth(\tx)/2, CameraY(va\cam), CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
  With sk\lf
    \ms = CreatePlane(#PB_Any, TextureWidth(\tx), TextureWidth(\tx), 1, 1, 1, 1)
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
    AddMaterialLayer(\ma, TextureID(sk\twink),#PB_Material_Modulate)
    AddMaterialLayer(\ma, TextureID(\cl), #PB_Material_AlphaBlend)
    ScrollMaterial(\ma, 0.001, 0.003, #PB_Material_Animated, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms),MaterialID(\ma), 0+MeshRadius(\ms)/2, MeshRadius(\ms)/2,-MeshRadius(\ms)/2)
    RotateEntity(\id, -90, 0, -90, #PB_Absolute)     
    MoveEntity(\id, CameraX(va\cam)-TextureWidth(\tx)/2, CameraY(va\cam), CameraZ(va\cam), #PB_Absolute)   
    AttachNodeObject(sk\node, EntityID(\id))
  EndWith
EndProcedure

Procedure.i CreateAuroraNoScript() ;No Script version
                                    ;Tilføj ekstra lag. Test dig frem.
                                    ;Create your own mesh..
                                    ;Add extra layers. Do tests.
  lgt = CreateLight(#PB_Any, $FFFFFF, 0, 0, 0, #PB_Light_Directional)
  LightLookAt(lgt, 0, 0.2, -2)
  aura\ms = CreatePlane(#PB_Any, 5, 2, 1, 1, 1, 1)
  aura\tx = LoadTexture(#PB_Any, "a4.jpg")
  aura\cl = LoadTexture(#PB_Any, "a4.jpg")
  aura\ma = CreateMaterial(#PB_Any, TextureID(aura\tx))
  MaterialBlendingMode(aura\ma, #PB_Material_Color)
  AddMaterialLayer(aura\ma, TextureID(aura\cl), #PB_Material_Modulate)
  ScrollMaterial(aura\ma, 0.06, 0.01, #PB_Material_Animated)
  aura\id = CreateEntity(#PB_Any, MeshID(aura\ms), MaterialID(aura\ma), 0, 0.2, -2)
  ScaleEntity(aura\id, 0.1, 1, 1)
  RotateEntity(aura\id, 90, 0, 90)
EndProcedure

Procedure.i CreateAurora() ;Script version 1
                           ;Jeg bruger sky formationer i dette eksempel.
                           ;Se scriptet: 'au.material'
                           ;I'm using a sky formation and a plane here as illustration
  lgt = CreateLight(#PB_Any, $FFFFFF, 0, 0, 0, #PB_Light_Directional)
  LightLookAt(lgt, 0, 0.2, -2)
  aura\ms = CreatePlane(#PB_Any, 5, 2, 1, 1, 1, 1)
  aura\ma = GetScriptMaterial(#PB_Any, "au1mat")
  aura\id = CreateEntity(#PB_Any, MeshID(aura\ms), MaterialID(aura\ma), 0, 0.2, -2)
  ScaleEntity(aura\id, 0.1, 1, 1)
  RotateEntity(aura\id, 90, 0, 90)
EndProcedure

Procedure.i RunNow()
  Protected ev.i
  
  Repeat
    If va\FScr = #False
      Repeat
        ev = WindowEvent()
      Until ev = 0
    EndIf
    ExamineMouse()
    
    RotateCamera(va\Cam, -MouseDeltaY() * 0.03, -MouseDeltaX() * 0.03, 0, #PB_Relative)
    ;MoveNode(sk\node, CameraX(va\Cam), CameraY(va\Cam), CameraZ(va\Cam))
    RenderWorld()
    
    ExamineKeyboard()
    
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape)
  End
EndProcedure

Add3DArchive("texture", #PB_3DArchive_FileSystem)
Add3DArchive("material", #PB_3DArchive_FileSystem)


Parse3DScripts()

SetResolution()
CreateSkyboxImages()
MakeSkybox()
CreateAuroraNoScript()  ;<-- no script version
;CreateAurora()            ;<-- script version
RunNow()

Re: Simple animated custom skybox fun.

Posted: Mon Nov 03, 2014 6:55 pm
by Samuel
Hello DK_PETER,

Thanks for sharing your examples. Very nice so far.
DK_PETER wrote: To forum members.
--------------------------------------------
What we're trying to mimic is the skybox effect and auroras
from Borderlands 2. Actually the teenagers I'm tutoring has
forced me to try to achieve the effects. I accepted the challenge. :-)
I will figure the effects out eventually myself - but if anyone has
any ideas - please, don't hold back - feel free to add your code or your ideas.
I might not be able to answer right away, but I'll drop by once in a while when time permits it.
Here's a good reference video for others interested in this.
http://www.youtube.com/watch?v=eKPh73x4-yE

I've heard that most games use a particle based system for generating an aurora borealis. A few planes alone won't cut it mainly because of the limited geometry shape.
With particles you can follow a curve easier which will replicate the effect more accurately. Not sure if OGRE's built in particle system is advanced enough for this though. You could always use a custom particle setup.

And just for a heads up all of Borderlands 2's sky effects are shader based which allows for faster real time rendering.
You can do all of this without shaders, but it may end up eating all of your CPU which will cause slow frame rates.

Re: Simple animated custom skybox fun.

Posted: Mon Nov 03, 2014 11:16 pm
by DK_PETER
Hi Samuel

Thanks for your input. I truly appreciate it.
Yeah, I've already guessed, that I need to say 'howdy' to
shaders at some point (soon).

You're right..A few planes won't cut it. I'm currently trying to
create special meshes, which 'in theory' might be able to
a'hmm 'eel' its way through the mesh. Just tried a snake shape...Didn't look that good.
We'll see what I'm able to concoct.

Using particles to mimic aurora borealis is not something I had considered. It's worth exploring and sounds
like a very plausible solution.

For now..All cpus on our computers runs steadily below 2%, so I'll see how
far I can take it before everything reverts to slow-motion.
Then it's to rewrite everything and take a serious dive into shaders.

Primary objective for now is to keep the teens curiosity at peak efficiency and it's great fun for me too. :-)

Nice vid. Exactly the dreamscene the kids talked about.
It certainly does look awesome! ;-)