Pouring rain

Everything related to 3D programming
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Pouring rain

Post by DK_PETER »

Code: Select all

;Simple (no scripts) example of pouring rain...
;By DK_PETER 
;REQUIRES PB 5.30.

EnableExplicit

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

DeclareModule Rain
  Declare.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
  Declare.i RunDemo()
EndDeclareModule

Module Rain
  Structure RainData
    id.i
    mat.i
    tex.i[2]
    x.f
    y.f
    z.f
  EndStructure
  
  Structure _MeshData
    mesh.i
    id.i
    mat.i
    tex.i
    id2.i
  EndStructure
  
  Structure _LampsData
    pole._MeshData
    arm._MeshData
    light.i
  EndStructure
  
  Structure ObjectData
    rain.RainData
    splash.RainData
    road._MeshData
    street._MeshData
    clouds._MeshData
    List build._MeshData()
    List lamps._LampsData()
    Geo.i
  EndStructure
  
  Declare.i DoPouringRain()
  Declare.i DoStreetAndRoad()
  Declare.i DoBuildings()
  Declare.i DoClouds()
  Declare.i CreateBuildingTexture()
  Declare.i RandomI(min.i, Max.i, Res.i = 100000)
  
  
  Global Win.i, Scr.i, Cam.i, FS.i
  Global ob.ObjectData
  
  Procedure.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
    FS = FullScreen
    If FullScreen = #False
      Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "Rainy night", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      Scr = OpenWindowedScreen(WindowID(Win), 0 ,0 , Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
    Else
      Scr = OpenScreen(1024, 768, 32, "sjdhksah",#PB_Screen_SmartSynchronization, 60)
    EndIf
    
    Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(Cam, 0, 50, 220)
    CameraBackColor(Cam, $323234)
    Fog($323234, 250, 200, 2000)
  EndProcedure  
  
  Procedure.i RandomI(min.i, Max.i, Res.i = 100000)
    ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
  EndProcedure
  
  Procedure.i DoPouringRain()
    With ob\rain
      \id = CreateParticleEmitter(#PB_Any, 2000, 600, 2000, #PB_Particle_Box, 0, 0, 0)
      
      \tex[0] = CreateTexture(#PB_Any, 2 , 12)
      StartDrawing(TextureOutput(\tex[0]))
      LineXY(1, 0, 1, 10, $FFFFFF)
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex[0]))
      ScrollMaterial(\mat, 3 ,0 ,#PB_Material_Animated)
      ParticleMaterial(\id, MaterialID(\mat))
      ParticleTimeToLive(\id, 4, 6)
      ParticleVelocity(\id, 200, 400)
      ParticleEmitterDirection(\id, 0, -1, 0)
      ParticleSize(\id, 0.1, 150)
      ParticleEmissionRate(\id, 1500)
      ParticleSpeedFactor(\id, 4)
    EndWith
    
    With ob\splash
      \id = CreateParticleEmitter(#PB_Any, 2000, 2000, 5, #PB_Particle_Box, 0, 12, 0)
      
      \tex[0] = CreateTexture(#PB_Any, 8 , 10)
      StartDrawing(TextureOutput(\tex[0]))
      LineXY(4,10,2,2,$FFFFFF)
      LineXY(4,10,4,2,$FFFFFF)
      LineXY(4,10,6,2,$FFFFFF)
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex[0]))
      MaterialBlendingMode(\mat, #PB_Material_Color)
      ParticleMaterial(\id, MaterialID(\mat))
      ParticleTimeToLive(\id, 0.1, 0.1)
      ParticleVelocity(\id, 0.01, 0.01)
      ParticleEmitterDirection(\id, 0, 1, 0)
      ParticleSize(\id, 5, 1)
      ParticleEmissionRate(\id, 2700)
      ParticleSpeedFactor(\id, 2)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i DoStreetAndRoad()
    Protected tex.i
    ob\geo = CreateStaticGeometry(#PB_Any, 1000, 100, 1000, #True)
    With ob\road
      \mesh = CreatePlane(#PB_Any, 1000, 1000, 10, 10, 1, 1)
      \tex  = CreateTexture(#PB_Any, 512, 512)
      StartDrawing(TextureOutput(\tex))
      Box(0, 0, 512, 512, $484545)
      For x = 0 To 10000
        Plot(Random(511,1), Random(511,1), $737273)
      Next x
      Box(10,0,20,512, $C1C2BF)
      Box(502,0,20,512, $C1C2BF)
      For y = 0 To 9 Step 100
        Box(256, y, 80, 200, $C1C2BF)
      Next y
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      ScaleMaterial(\mat, 0.01, 0.01)
      MaterialFilteringMode(\mat, #PB_Material_Trilinear)
      ScrollMaterial(\mat, 0.6,0, #PB_Material_Fixed)
      \id = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), 0, 0, 0)
      ScaleEntity(\id, 10, 1, 10)
      AddStaticGeometryEntity(ob\Geo, EntityID(\id), 0, 0, 0)
    EndWith
    
    With ob\street
      \mesh = CreateCube(#PB_Any, 0.5)
      \tex  = CreateTexture(#PB_Any, 1000,1000)
      StartDrawing(TextureOutput(\tex))
      Box(0,0, 50, 1000, $978F8A)
      Box(950, 0, 50, 1000, $978F8A)
      Box(51,0, 900, 1000, $59554C)
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      \id  = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), -300, -20, 0)
      
      ScaleEntity(\id, 700,100, 10000)
      \id2 = CopyEntity(\id, #PB_Any)
      MoveEntity(\id2, 300,-20,0)
      AddStaticGeometryEntity(ob\Geo, EntityID(\id),-300, -20, 0)
      AddStaticGeometryEntity(ob\Geo, EntityID(\id2), 300,-20,0)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i CreateBuildingTexture()
    Protected tex.i, ColorGrey.i
    tex = CreateTexture(#PB_Any, 512, 512)
    StartDrawing(TextureOutput(tex))
    ColorGrey = Random(100,40)
    Box(0, 0, 512, 512, RGB(ColorGrey, ColorGrey, ColorGrey))
    Box(0, 0, 512, 30, $8B9075)
    For y = 60 To 460 Step 20
      For x = 0 To 512 Step 20
        ColorGrey = Random(255)
        Box(x,y, 10, 10, RGB(ColorGrey, ColorGrey, ColorGrey))
      Next x
    Next y
    Box(0, 480, 512, 32, $8B9075)
    For x = 10 To 512 Step 80
      Box(x, 484, 15, 30, $555555)
    Next x
    StopDrawing()
    ProcedureReturn tex
  EndProcedure
  
  Procedure.i DoBuildings()
    Protected  scalex.i, scaley.i, scalez.i
    For z = 0 To 5
      AddElement(ob\build())
      With ob\build()
        \mesh = CreateCube(#PB_Any, 150)
        \tex  = CreateBuildingTexture()
        \mat  = CreateMaterial(#PB_Any, TextureID(\tex))
        \id   = CreateEntity(#PB_Any, MeshID(\mesh),MaterialID(\mat), -180, 100, 0-z*300)
        \id2  = CopyEntity(\id, #PB_Any)
        MoveEntity(\id2, 180, 100, 0-z*300)
        AddStaticGeometryEntity(ob\Geo, EntityID(\id), -180, 120, z*300)
        AddStaticGeometryEntity(ob\Geo, EntityID(\id2), 180, 120, z*300)
      EndWith
    Next z
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i DoClouds()
    Protected tex.i, Col.i
    With ob\clouds
      \mesh = CreatePlane(#PB_Any, 5000, 5000, 10, 10, 1, 1)
      \tex  = CreateTexture(#PB_Any, 1024, 1024)
      StartDrawing(TextureOutput(\tex))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For y = 0 To 4000
        ypos = Random(922,101)
        xpos = Random(922, 101)
        For x = 0 To 200
          Col.i = Random(100,40)
          Plot(RandomI(xpos-100, xpos+100), RandomI(ypos-100, ypos+100),RGBA(Col,Col,Col, Random(150,50)))
        Next x
      Next y
      StopDrawing()
      
      tex  = CreateTexture(#PB_Any, 1024, 1024)
      StartDrawing(TextureOutput(tex))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For y = 0 To 4000
        xpos = Random(922, 101)
        ypos = Random(922, 101)
        For x = 0 To 200
          Col.i = Random(100,40)
          Plot(RandomI(xpos-100, xpos+100), RandomI(ypos-100, ypos+100),RGBA(Col,Col,Col, Random(150,50)))
        Next x
      Next y
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      ScaleMaterial(\mat, 5, 5)
      ScrollMaterial(\mat, -0.0002, 0.0002, #PB_Material_Animated)
      
      AddMaterialLayer(\mat, TextureID(tex),#PB_Material_Add)
      
      ScaleMaterial(\mat, 20, 20, 1)
      ScrollMaterial(\mat, 0.0002, 0.0002, #PB_Material_Animated, 1)
      
      \id = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), 0, 200, 200)
      
      RotateEntity(\id, 180, 0, 0)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i RunDemo()
    Quit = 0
    ret = DoPouringRain()
    ret = DoStreetAndRoad()
    ret = DoBuildings()
    ret = DoClouds()
    
    Repeat
      
      If FS = #False
        Repeat
          ev = WindowEvent()
          If ev = #PB_Event_CloseWindow
            Quit = 1
          EndIf
        Until  ev = 0
      EndIf
      
      RenderWorld()
      
      ExamineKeyboard()
      
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndProcedure
  
EndModule

Rain::SetResolution(1920,1080)
Rain::RunDemo()

Added fake driving animation

Code: Select all

;Simple example of pouring rain...
;By DK_PETER
;REQUIRES PB 5.30
;Added some simple animation..
;(mimics driving down the road).

EnableExplicit

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

DeclareModule Rain
  Declare.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
  Declare.i RunDemo()
EndDeclareModule

Module Rain
  Structure RainData
    id.i
    mat.i
    tex.i[2]
    x.f
    y.f
    z.f
  EndStructure
  
  Structure _MeshData
    mesh.i
    id.i
    mat.i
    tex.i
    id2.i
  EndStructure
  
  Structure _LampsData
    pole._MeshData
    arm._MeshData
    light.i
  EndStructure
  
  Structure ObjectData
    rain.RainData
    splash.RainData
    road._MeshData
    street._MeshData
    clouds._MeshData
    List build._MeshData()
  EndStructure
  
  Declare.i DoPouringRain()
  Declare.i DoStreetAndRoad()
  Declare.i DoBuildings()
  Declare.i DoClouds()
  Declare.i CreateBuildingTexture()
  Declare.i RandomI(min.i, Max.i, Res.i = 100000)
  Declare.i CheckBuild()
  
  Global Win.i, Scr.i, Cam.i, FS.i
  Global ob.ObjectData
  
  Procedure.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
    FS = FullScreen
    If FullScreen = #False
      Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "Pouring rain", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      Scr = OpenWindowedScreen(WindowID(Win), 0 ,0 , Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
    Else
      Scr = OpenScreen(1024, 768, 32, "Pouring rain",#PB_Screen_SmartSynchronization, 60)
    EndIf
    
    Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(Cam, 0, 50, 220)
    CameraBackColor(Cam, $323234)
    Fog($323234, 250, 200, 2000)
  EndProcedure  
  
  Procedure.i RandomI(min.i, Max.i, Res.i = 100000)
    ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
  EndProcedure
  
  Procedure.i DoPouringRain()
    With ob\rain
      \id = CreateParticleEmitter(#PB_Any, 2000, 600, 2000, #PB_Particle_Box, 0, 0, 0)
      
      \tex[0] = CreateTexture(#PB_Any, 2 , 12)
      StartDrawing(TextureOutput(\tex[0]))
      LineXY(1, 0, 1, 10, $FFFFFF)
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex[0]))
      ScrollMaterial(\mat, 3 ,0 ,#PB_Material_Animated)
      ParticleMaterial(\id, MaterialID(\mat))
      ParticleTimeToLive(\id, 4, 6)
      ParticleVelocity(\id, 200, 400)
      ParticleEmitterDirection(\id, 0, -1, 0)
      ParticleSize(\id, 0.1, 150)
      ParticleEmissionRate(\id, 1500)
      ParticleSpeedFactor(\id, 4)
    EndWith
    
    With ob\splash
      \id = CreateParticleEmitter(#PB_Any, 2000, 2000, 5, #PB_Particle_Box, 0, 12, 0)
      
      \tex[0] = CreateTexture(#PB_Any, 8 , 10)
      StartDrawing(TextureOutput(\tex[0]))
      LineXY(4,10,2,2,$FFFFFF)
      LineXY(4,10,4,2,$FFFFFF)
      LineXY(4,10,6,2,$FFFFFF)
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex[0]))
      MaterialBlendingMode(\mat, #PB_Material_Color)
      ParticleMaterial(\id, MaterialID(\mat))
      ParticleTimeToLive(\id, 0.1, 0.1)
      ParticleVelocity(\id, 0.01, 0.01)
      ParticleEmitterDirection(\id, 0, 1, 0)
      ParticleSize(\id, 5, 1)
      ParticleEmissionRate(\id, 2700)
      ParticleSpeedFactor(\id, 2)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i DoStreetAndRoad()
    Protected tex.i
    With ob\road
      \mesh = CreatePlane(#PB_Any, 1000, 1000, 10, 10, 1, 1)
      \tex  = CreateTexture(#PB_Any, 512, 512)
      StartDrawing(TextureOutput(\tex))
      Box(0, 0, 512, 512, $484545)
      For x = 0 To 10000
        Plot(Random(511,1), Random(511,1), $737273)
      Next x
      Box(10,0,20,512, $C1C2BF)
      Box(502,0,20,512, $C1C2BF)
      For y = 0 To 9 Step 100
        Box(256, y, 80, 200, $C1C2BF)
      Next y
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      ScaleMaterial(\mat, 0.01, 0.01)
      MaterialFilteringMode(\mat, #PB_Material_Trilinear)
      ScrollMaterial(\mat, 0.6,0, #PB_Material_Fixed)
      ScrollMaterial(\mat, 0,-1, #PB_Material_Animated)
      \id = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), 0, 0, 0)
      ScaleEntity(\id, 10, 1, 10)
    EndWith
    
    With ob\street
      \mesh = CreateCube(#PB_Any, 0.5)
      \tex  = CreateTexture(#PB_Any, 1000,1000)
      StartDrawing(TextureOutput(\tex))
      Box(0,0, 50, 1000, $978F8A)
      Box(950, 0, 50, 1000, $978F8A)
      Box(51,0, 900, 1000, $59554C)
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      \id  = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), -300, -20, 0)
      
      ScaleEntity(\id, 700,100, 10000)
      \id2 = CopyEntity(\id, #PB_Any)
      MoveEntity(\id2, 300,-20,0)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i CreateBuildingTexture()
    Protected tex.i, ColorGrey.i
    tex = CreateTexture(#PB_Any, 512, 512)
    StartDrawing(TextureOutput(tex))
    ColorGrey = Random(100,40)
    Box(0, 0, 512, 512, RGB(ColorGrey, ColorGrey, ColorGrey))
    Box(0, 0, 512, 30, $8B9075)
    For y = 60 To 460 Step 20
      For x = 0 To 512 Step 20
        ColorGrey = Random(255)
        Box(x,y, 10, 10, RGB(ColorGrey, ColorGrey, ColorGrey))
      Next x
    Next y
    Box(0, 480, 512, 32, $8B9075)
    For x = 10 To 512 Step 80
      Box(x, 484, 15, 30, $555555)
    Next x
    StopDrawing()
    ProcedureReturn tex
  EndProcedure
  
  Procedure.i DoBuildings()
    Protected  scalex.i, scaley.i, scalez.i
    For z = 0 To 5
      AddElement(ob\build())
      With ob\build()
        \mesh = CreateCube(#PB_Any, 150)
        \tex  = CreateBuildingTexture()
        \mat  = CreateMaterial(#PB_Any, TextureID(\tex))
        \id   = CreateEntity(#PB_Any, MeshID(\mesh),MaterialID(\mat), -180, 100, 0-z*300)
        \id2  = CopyEntity(\id, #PB_Any)
        MoveEntity(\id2, 180, 100, 0-z*300)
      EndWith
    Next z
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i DoClouds()
    Protected tex.i, Col.i
    With ob\clouds
      \mesh = CreatePlane(#PB_Any, 5000, 5000, 10, 10, 1, 1)
      \tex  = CreateTexture(#PB_Any, 1024, 1024)
      StartDrawing(TextureOutput(\tex))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For y = 0 To 4000
        ypos = Random(922,101)
        xpos = Random(922, 101)
        For x = 0 To 200
          Col.i = Random(100,40)
          Plot(RandomI(xpos-100, xpos+100), RandomI(ypos-100, ypos+100),RGBA(Col,Col,Col, Random(150,50)))
        Next x
      Next y
      StopDrawing()
      
      tex  = CreateTexture(#PB_Any, 1024, 1024)
      StartDrawing(TextureOutput(tex))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For y = 0 To 4000
        xpos = Random(922, 101)
        ypos = Random(922, 101)
        For x = 0 To 200
          Col.i = Random(100,40)
          Plot(RandomI(xpos-100, xpos+100), RandomI(ypos-100, ypos+100),RGBA(Col,Col,Col, Random(150,50)))
        Next x
      Next y
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      ScaleMaterial(\mat, 5, 5)
      ScrollMaterial(\mat, -0.0002, 0.0002, #PB_Material_Animated)
      
      AddMaterialLayer(\mat, TextureID(tex),#PB_Material_Add)
      
      ScaleMaterial(\mat, 20, 20, 1)
      ScrollMaterial(\mat, 0.0002, 0.0002, #PB_Material_Animated, 1)
      
      \id = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), 0, 200, 200)
      
      RotateEntity(\id, 180, 0, 0)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i CheckBuild()
    ForEach ob\build()
      If EntityZ(ob\build()\id,#PB_Absolute) > 180
        MoveEntity(ob\build()\id, -180, 100, -1600, #PB_Absolute)
        MoveEntity(ob\build()\id2, 180, 100, -1600, #PB_Absolute)
      Else
        MoveEntity(ob\build()\id, 0, 0, 1,#PB_Relative)
        MoveEntity(ob\build()\id2, 0, 0, 1,#PB_Relative)
      EndIf
    Next
  EndProcedure
  
  Procedure.i RunDemo()
    Quit = 0
    ret = DoPouringRain()
    ret = DoStreetAndRoad()
    ret = DoBuildings()
    ret = DoClouds()
    
    Repeat
      
      If FS = #False
        Repeat
          ev = WindowEvent()
          If ev = #PB_Event_CloseWindow
            Quit = 1
          EndIf
        Until  ev = 0
      EndIf
      
      ret = CheckBuild()
      
      RenderWorld()
      
      ExamineKeyboard()
      
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndProcedure
  
EndModule

Rain::SetResolution(1920,1080)
Rain::RunDemo()
Last edited by DK_PETER on Thu Jul 03, 2014 7:13 am, edited 2 times in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Pouring rain

Post by falsam »

I love it. Thank for sharing :)

PS : Only works with PB 5.30 ParticleSpeedFactor() error with PB 5.22

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Pouring rain

Post by djes »

Nice sample, a bit depressing ! ;)
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Pouring rain

Post by falsam »

djes wrote:a bit depressing ! ;)
This is the same weather in Pas de Calais :mrgreen:

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Pouring rain

Post by DK_PETER »

falsam wrote:
djes wrote:a bit depressing ! ;)
This is the same weather in Pas de Calais :mrgreen:
Glad you liked it :-)
This is the weather I'm having right now. Boring rain, grey...Was hoping for an outdoor barbecue, but nooooo..
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Pouring rain

Post by djes »

falsam wrote:
djes wrote:a bit depressing ! ;)
This is the same weather in Pas de Calais :mrgreen:
Sorry for you, but sun is shining and sky is blue, like 365 times a year (*)


(*) concentrated on 3 glorious and magnificent days
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Pouring rain

Post by applePi »

thanks for this, i like the rain
it seems the clouds have some chemical pollution so the rain
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Pouring rain

Post by IdeasVacuum »

Home sweet home - thanks for sharing!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Fred
Administrator
Administrator
Posts: 18171
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Pouring rain

Post by Fred »

Looks good :)
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Pouring rain

Post by luis »

Nice, I like it's all generated at runtime :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Pouring rain

Post by DK_PETER »

Updated first post.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: Pouring rain

Post by Rings »

great stuff, thx for sharing !!!
SPAMINATOR NR.1
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Pouring rain

Post by DK_PETER »

Rings wrote:great stuff, thx for sharing !!!
Glad you all liked it :-)

Last version. "Driving miss Daisy.."

Code: Select all

;Last update for pouring rain
;Renamed to "Driving miss Daisy"
;Added cartoony cabin and rear mirror
;Fixed rain to look a little more realistic.
;By DK_PETER
;REQUIRES PB 5.30


EnableExplicit

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

DeclareModule Rain
  Declare.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
  Declare.i RunDemo()
EndDeclareModule

Module Rain
  
  Structure RainData
    id.i
    mat.i
    tex.i[2]
    x.f
    y.f
    z.f
  EndStructure
  
  Structure _MeshData
    mesh.i
    id.i
    mat.i
    tex.i
    id2.i
    node.i
  EndStructure
  
  Structure ObjectData
    rain.RainData
    splash.RainData
    road._MeshData
    street._MeshData
    clouds._MeshData
    List build._MeshData()
    Winscreen.i
    steer.i
    lig.RainData
  EndStructure
  
  Declare.i DoPouringRain()
  Declare.i DoStreetAndRoad()
  Declare.i DoBuildings()
  Declare.i DoClouds()
  Declare.i CreateBuildingTexture()
  Declare.i RandomI(min.i, Max.i, Res.i = 100000)
  Declare.i CheckBuild()
  Declare.i DoSteering()
  Declare.i DoLightning()
  
  Global Win.i, Scr.i, Cam.i, Cam2.i, FS.i,TM.i
  Global ob.ObjectData

  Procedure.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
    FS = FullScreen
    If FullScreen = #False
      Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "Driving miss Daisy", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      Scr = OpenWindowedScreen(WindowID(Win), 0 ,0 , Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
    Else
      Scr = OpenScreen(1024, 768, 32, "Driving miss Daisy",#PB_Screen_SmartSynchronization, 60)
    EndIf
    Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    If ScreenWidth()=1024
      Cam2 = CreateCamera(#PB_Any,45,21,10,5)
    Else
      Cam2 = CreateCamera(#PB_Any,45,15,10,5)
    EndIf
    MoveCamera(Cam, 0, 50, 120)
    MoveCamera(cam2, 0, 50, -320)
    RotateCamera(cam2, 180,0,180)
    CameraBackColor(Cam, $323234)
    CameraBackColor(Cam2, $323234)
    Fog($323234, 150, 500, 2000)
    Add3DArchive("\",#PB_3DArchive_FileSystem)
  EndProcedure  
  
  Procedure.i RandomI(min.i, Max.i, Res.i = 100000)
    ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
  EndProcedure
  
  Procedure.i DoPouringRain()
    With ob\rain
      \id = CreateParticleEmitter(#PB_Any, 2000, 600, 2000, #PB_Particle_Box, 0, 0, 0)
      \tex[0] = CreateTexture(#PB_Any, 1 , 12)
      StartDrawing(TextureOutput(\tex[0]))
      LineXY(0, 0, 0, 10, $AAAAAA)
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex[0]))
      ParticleMaterial(\id, MaterialID(\mat))
      ParticleTimeToLive(\id, 4, 6)
      ParticleVelocity(\id, 200, 400)
      ParticleEmitterDirection(\id, 0, -1, 0)
      ParticleSize(\id, 0.03, 150)
      ParticleEmissionRate(\id, 1500)
      ParticleSpeedFactor(\id, 4)
    EndWith
    
    With ob\splash
      \id = CreateParticleEmitter(#PB_Any, 2000, 2000, 5, #PB_Particle_Box, 0, 12, 0)
      
      \tex[0] = CreateTexture(#PB_Any, 8 , 10)
      StartDrawing(TextureOutput(\tex[0]))
      LineXY(4,10,2,2,$FFFFFF)
      LineXY(4,10,4,2,$FFFFFF)
      LineXY(4,10,6,2,$FFFFFF)
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex[0]))
      MaterialBlendingMode(\mat, #PB_Material_Color)
      ParticleMaterial(\id, MaterialID(\mat))
      ParticleTimeToLive(\id, 0.1, 0.1)
      ParticleVelocity(\id, 0.01, 0.01)
      ParticleEmitterDirection(\id, 0, 1, 0)
      ParticleSize(\id, 5, 1)
      ParticleEmissionRate(\id, 2700)
      ParticleSpeedFactor(\id, 2)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i DoStreetAndRoad()
    Protected tex.i
    With ob\road
      \mesh = CreatePlane(#PB_Any, 1000, 1000, 10, 10, 1, 1)
      \tex  = CreateTexture(#PB_Any, 512, 512)
      StartDrawing(TextureOutput(\tex))
      Box(0, 0, 512, 512, $484545)
      For x = 0 To 10000
        Plot(Random(511,1), Random(511,1), $737273)
      Next x
      Box(10,0,20,512, $C1C2BF)
      Box(502,0,20,512, $C1C2BF)
      For y = 0 To 9 Step 100
        Box(256, y, 80, 200, $C1C2BF)
      Next y
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      ScaleMaterial(\mat, 0.01, 0.01)
      MaterialFilteringMode(\mat, #PB_Material_Trilinear)
      ScrollMaterial(\mat, 0.6,0, #PB_Material_Fixed)
      ScrollMaterial(\mat, 0,-1, #PB_Material_Animated)
      \id = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), 0, 0, 0)
      ScaleEntity(\id, 10, 1, 10)
    EndWith
    
    With ob\street
      \mesh = CreateCube(#PB_Any, 0.5)
      \tex  = CreateTexture(#PB_Any, 1000,1000)
      StartDrawing(TextureOutput(\tex))
      Box(0,0, 50, 1000, $978F8A)
      Box(950, 0, 50, 1000, $978F8A)
      Box(51,0, 900, 1000, $59554C)
      StopDrawing()
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      \id  = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), -300, -20, 0)
      
      ScaleEntity(\id, 700,100, 10000)
      \id2 = CopyEntity(\id, #PB_Any)
      MoveEntity(\id2, 300,-20,0)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i CreateBuildingTexture()
    Protected tex.i, ColorGrey.i
    tex = CreateTexture(#PB_Any, 512, 512)
    StartDrawing(TextureOutput(tex))
    ColorGrey = Random(100,40)
    Box(0, 0, 512, 512, RGB(ColorGrey, ColorGrey, ColorGrey))
    Box(0, 0, 512, 30, $8B9075)
    For y = 60 To 460 Step 20
      For x = 0 To 512 Step 20
        ColorGrey = Random(255)
        Box(x,y, 10, 10, RGB(ColorGrey, ColorGrey, ColorGrey))
      Next x
    Next y
    Box(0, 480, 512, 32, $8B9075)
    For x = 10 To 512 Step 80
      Box(x, 484, 15, 30, $555555)
    Next x
    StopDrawing()
    ProcedureReturn tex
  EndProcedure
  
  Procedure.i DoBuildings()
    Protected  scalex.i, scaley.i, scalez.i
    For z = 0 To 5
      AddElement(ob\build())
      With ob\build()
        \mesh = CreateCube(#PB_Any, 150)
        \tex  = CreateBuildingTexture()
        \mat  = CreateMaterial(#PB_Any, TextureID(\tex))
        \id   = CreateEntity(#PB_Any, MeshID(\mesh),MaterialID(\mat), -180, 100, 0-z*300)
        \id2  = CopyEntity(\id, #PB_Any)
        MoveEntity(\id2, 180, 100, 0-z*300)
      EndWith
    Next z
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i DoLightning()
    ob\lig\id=CreateParticleEmitter(#PB_Any, 400,400,40,#PB_Particle_Box,0,100,100)
    ob\lig\tex[0] = LoadTexture(#PB_Any,"li.jpg")
    ob\lig\mat = CreateMaterial(#PB_Any, TextureID(ob\lig\tex[0]))
    MaterialBlendingMode(ob\lig\mat,#PB_Material_Add)
    ParticleMaterial(ob\lig\id,MaterialID(ob\lig\mat))
    ParticleColorRange(ob\lig\id, $F1FFDD,$FFFFFF)
    ParticleEmissionRate(ob\lig\id,20)
    ParticleTimeToLive(ob\lig\id, 0.1,0.2)
    ParticleSize(ob\lig\id, 10,100)
    ParticleVelocity(ob\lig\id,0,0)
    ParticleEmitterDirection(ob\lig\id,0,-1,0)
  EndProcedure
  
  Procedure.i DoClouds()
    Protected tex.i, Col.i
    With ob\clouds
      \mesh = CreatePlane(#PB_Any, 5000, 5000, 10, 10, 1, 1)
      \tex  = CreateTexture(#PB_Any, 1024, 1024)
      StartDrawing(TextureOutput(\tex))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For y = 0 To 4000
        ypos = Random(922,101)
        xpos = Random(922, 101)
        For x = 0 To 200
          Col.i = Random(100,40)
          Plot(RandomI(xpos-100, xpos+100), RandomI(ypos-100, ypos+100),RGBA(Col,Col,Col, Random(150,50)))
        Next x
      Next y
      StopDrawing()
      
      tex  = CreateTexture(#PB_Any, 1024, 1024)
      StartDrawing(TextureOutput(tex))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For y = 0 To 4000
        xpos = Random(922, 101)
        ypos = Random(922, 101)
        For x = 0 To 200
          Col.i = Random(100,40)
          Plot(RandomI(xpos-100, xpos+100), RandomI(ypos-100, ypos+100),RGBA(Col,Col,Col, Random(150,50)))
        Next x
      Next y
      StopDrawing()
      
      \mat = CreateMaterial(#PB_Any, TextureID(\tex))
      ScaleMaterial(\mat, 5, 5)
      ScrollMaterial(\mat, -0.0002, 0.0002, #PB_Material_Animated)
      AddMaterialLayer(\mat, TextureID(tex),#PB_Material_Add)
      ScaleMaterial(\mat, 20, 20, 1)
      ScrollMaterial(\mat, 0.0002, 0.0002, #PB_Material_Animated, 1)
      \id = CreateEntity(#PB_Any, MeshID(\mesh), MaterialID(\mat), 0, 200, 200)
      RotateEntity(\id, 180, 0, 0)
    EndWith
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i CheckBuild()
    ForEach ob\build()
      If EntityZ(ob\build()\id,#PB_Absolute) > 680
        MoveEntity(ob\build()\id, -180, 100, -1600, #PB_Absolute)
        MoveEntity(ob\build()\id2, 180, 100, -1600, #PB_Absolute)
      Else
        MoveEntity(ob\build()\id, 0, 0, 1,#PB_Relative)
        MoveEntity(ob\build()\id2, 0, 0, 1,#PB_Relative)
      EndIf
    Next
  EndProcedure
  
  Procedure.i DoMyWindScreen()
    Protected w.i = ScreenWidth():h.i=ScreenHeight()
    ob\Winscreen = CreateSprite(#PB_Any, ScreenWidth(), ScreenHeight(),#PB_Sprite_AlphaBlending)
    StartDrawing(SpriteOutput(ob\Winscreen))
    DrawingMode(#PB_2DDrawing_Outlined)
    LineXY(100,140,80,ScreenHeight()-100,$111111)
    LineXY(ScreenWidth()-100,140,ScreenWidth()-80,ScreenHeight()-100,$111111)
    LineXY(100,140,ScreenWidth()-100,140,$111111)
    LineXY(80,ScreenHeight()-100,ScreenWidth()-80,ScreenHeight()-100,$111111)
    LineXY(0, 140, 60, 180,$111111)
    LineXY(60, 180, 70, ScreenHeight()-100,$111111)
    LineXY(70, ScreenHeight()-100, 0, ScreenHeight()-80,$111111)
    LineXY(ScreenWidth()-60, 180, ScreenWidth()-70, ScreenHeight()-100,$111111)
    LineXY(ScreenWidth()-70, ScreenHeight()-100, ScreenWidth(), ScreenHeight()-80,$111111)
    LineXY(ScreenWidth(), 140, ScreenWidth()-60, 180,$111111)
    FillArea(0,0,$111111,$3A5164) 
    DrawingMode(#PB_2DDrawing_Default)
    Box(ScreenWidth()/2-5,140,10,20,$3A5164)
     StopDrawing()
    TransparentSpriteColor(ob\Winscreen, 0)
  EndProcedure
  
  
  Procedure.i DoSteering()
    Protected w.i, h.i
    w = ScreenWidth()/3
    h = ScreenHeight()/3
    ob\steer = CreateSprite(#PB_Any, w, h)
    StartDrawing(SpriteOutput(ob\steer))
    DrawingMode(#PB_2DDrawing_Outlined )
    Box(0, 0, w, h, $000000)
    Circle(w/2, h/2, h/2, $222222)
    Circle(w/2, h/2, h/2-25, $222222)
    FillArea(w/2,2, $222222,$222212)
    DrawingMode(#PB_2DDrawing_Default)
    Box(w/4, h/2-30, w - w/2, h/3, $222212)
    StopDrawing()
    TransparentSpriteColor(ob\steer, 0)
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i RunDemo()
    
    Quit = 0
    ret = DoPouringRain()
    ret = DoStreetAndRoad()
    ret = DoBuildings()
    ret = DoClouds()
    ret = DoMyWindScreen()
    ret = DoSteering()
    ret = DoLightning()
    
    Repeat
      
      If FS = #False
        Repeat
          ev = WindowEvent()
          If ev = #PB_Event_CloseWindow
            Quit = 1
          EndIf
        Until  ev = 0
      EndIf
      
      ret = CheckBuild()
      
      RenderWorld()
      
      ExamineKeyboard()

      DisplayTransparentSprite(ob\Winscreen, 0, 0)
      DisplayTransparentSprite(ob\steer, ScreenWidth()/80, ScreenHeight() - (SpriteHeight(ob\steer)/2)-30)
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndProcedure
  
EndModule

Rain::SetResolution(1920,1080) ;or (1024,768)
Rain::RunDemo()
Last edited by DK_PETER on Sun Aug 10, 2014 5:10 am, edited 1 time in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Pouring rain

Post by falsam »

Thank you for this walk in an automatic bus through the streets. What a wonderful time .... :mrgreen:

PS : Same weather in Paris

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Pouring rain

Post by DK_PETER »

falsam wrote:Thank you for this walk in an automatic bus through the streets. What a wonderful time .... :mrgreen:

PS : Same weather in Paris
It's my pleasure Falsam. :-)
Sun is finally shining here.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply