It is currently Thu Feb 27, 2020 8:18 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Easy solution to 'volumetric clouds' using particles
PostPosted: Tue Apr 04, 2017 10:37 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 823
Location: Denmark
For PB 5.60+ only
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:
;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)

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Last edited by DK_PETER on Thu Nov 22, 2018 2:19 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Easy solution to 'volumetric clouds' using particles
PostPosted: Tue Apr 04, 2017 11:33 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 607
Location: France
Very cool DK_PETER. Thanks.

_________________

➽ Windows 10 - PB 5.62 & PB 5.70 LTS

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: Easy solution to 'volumetric clouds' using particles
PostPosted: Wed Apr 05, 2017 8:24 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Sep 10, 2012 10:41 am
Posts: 128
Location: Savoie
Works fine on my Mac
Thanks DK_PETER !

_________________
MacBook Pro 13" Retina - 16 Gb - OSX 10.14 - Iphone X - iPad at home
...and unfortunately... Windows at work...


Top
 Profile  
Reply with quote  
 Post subject: Re: Easy solution to 'volumetric clouds' using particles
PostPosted: Mon Nov 19, 2018 10:52 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1905
Doesn't work anymore; needs InitEngine3D() with flags of which I know not. Can we get an update, DK_PETER?


Top
 Profile  
Reply with quote  
 Post subject: Re: Easy solution to 'volumetric clouds' using particles
PostPosted: Thu Nov 22, 2018 1:25 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 823
Location: Denmark
Dude wrote:
Doesn't work anymore; needs InitEngine3D() with flags of which I know not. Can we get an update, DK_PETER?

Hey dude.

This one and the ocean by pf shadoko works just fine here. (Windows 7 / Windows 10)
There's no need for any parameter flag in InitEngine()

Two things you could try to make it work for you:
1. Try using 'OpenGL' in as subsystem.
2. Try reinstalling DX9c

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: Easy solution to 'volumetric clouds' using particles
PostPosted: Thu Nov 22, 2018 9:58 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1905
DK_PETER wrote:
Try using 'OpenGL' in as subsystem

Thanks, that made it work. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye