Edit: Use your own images and save them to the same location as the code.
Images should be named as:
1.png, 2.png, 3.png, 4.png (clouds)
flatland.jpg (ground)
Now...Here's the code:
Code: Select all
;Simple and efficient solution to 'volumetric' clouds using particles
;By DK_Peter
;------------------------------------------
UsePNGImageDecoder()
UseJPEGImageDecoder()
InitEngine3D()
InitSprite()
InitKeyboard()
Structure _Object
id.i
ma.i
ms.i
tx.i
EndStructure
Global sun._Object, earth._Object
Structure _Par
id.i
ma.i
tx.i
EndStructure
Global Dim p._Par(4), x.i, elap.i, elevate.f = -3.5
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "Clouds - use arrow keys up and down", #PB_Window_SystemMenu|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0))
Add3DArchive(".", #PB_3DArchive_FileSystem)
WorldShadows(#PB_Shadow_TextureAdditive, 10, $00AAD3, 1024)
CreateCamera(0, 0, 0, 100, 100)
CameraFOV(0, 40)
CameraBackColor(0, $FF9121)
MoveCamera(0, 0, elevate, 0)
For x = 1 To 4
With p(x)
\id = CreateParticleEmitter(#PB_Any, 1000, 0, 100, #PB_Particle_Box, 0, 0, -130)
\tx = LoadTexture(#PB_Any, Str(x) + ".png")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_AlphaBlend)
AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Modulate)
ScrollMaterial(\ma, -0.01, 0, #PB_Material_Animated,2)
MaterialFog(\ma, $FFFFFF, 200, 0, 300)
ParticleMaterial(\id, MaterialID(\ma))
ParticleEmissionRate(\id, 100)
ParticleEmitterDirection(\id, 0, 0, 1)
ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 4)
ParticleVelocity(\id, #PB_Particle_Velocity, 9)
ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 15)
ParticleEmitterAngle(\id, 0)
ParticleColorRange(\id, $00B7E4, $FFFFFF)
ParticleTimeToLive(\id, 30, 50)
ParticleColorFader(\id, -0.1, 0.2, 0.2, 0.1)
ParticleSize(\id, 50, 15)
EndWith
Next x
earth\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
earth\tx = LoadTexture(#PB_Any, "flatland.jpg")
earth\ma = CreateMaterial(#PB_Any, TextureID(earth\tx))
MaterialFilteringMode(earth\ma, #PB_Material_Anisotropic, 16)
ScaleMaterial(earth\ma, 0.4, 0.4)
ScrollMaterial(earth\ma, 0, -0.01, #PB_Material_Animated)
earth\id = CreateEntity(#PB_Any, MeshID(earth\ms), MaterialID(earth\ma), 0, -100, -100)
ScaleEntity(earth\id, 3000, 1, 3000)
Repeat
Repeat
ev = WindowEvent()
Until ev = 0
MoveCamera(0, 0, elevate, 0, #PB_Absolute)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) And elevate < 3.5
elevate + 0.1
ElseIf KeyboardPushed(#PB_Key_Down) And elevate > -3.5
elevate - 0.1
EndIf
Until KeyboardPushed(#PB_Key_Escape)