Simple rain test

Everything related to 3D programming
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Simple rain test

Post by minimy »

Hi PB people! This is an example of simple rain (take your umbrella) :lol:
If you can do better... do it and share! :mrgreen:

Code: Select all


  Global.b sal

  Procedure   spr2DText(spr, txt.s, font, ink.l=$ff00ff00)
    Protected n,y=2,tl= CountString(txt,#CR$)
    Protected tx.s
    StartDrawing(SpriteOutput(spr))
    DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0,0,OutputWidth(),OutputHeight(),$00000000)
    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
      Box(0,0,OutputWidth(),OutputHeight(),$aa000000)
      DrawingFont(FontID(font))
      For n=1 To tl+1
        tx= StringField(txt,n,#CR$)
        DrawText(5,y,tx,ink)
        y+16
      Next n
      DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Outlined)
      Box(0,0,OutputWidth(),OutputHeight(),ink)
    StopDrawing()
  EndProcedure

  Procedure   iniDX(title.s="3D", width=800,height=600, shadowmode= #PB_Shadow_Modulative, shadowres=4096, param=#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    InitEngine3D()
      InitSprite()
      InitKeyboard()
      InitMouse()
      
      OpenWindow(0, 0, 0, width, height, title, param)
        SetWindowColor(0,$444444)
      
      OpenWindowedScreen(WindowID(0), 0, 0, (width * DesktopResolutionX()), (height * DesktopResolutionY()),0,0,0,#PB_Screen_NoSynchronization)
        KeyboardMode(#PB_Keyboard_International)
        Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
        Add3DArchive("Data/Model", #PB_3DArchive_FileSystem)
        Add3DArchive("Data", #PB_3DArchive_FileSystem)
        Parse3DScripts()

        Protected.b s= 100
        If shadowmode= #PB_Shadow_TextureAdditive Or shadowmode= #PB_Shadow_TextureModulative
          WorldShadows(shadowmode, -1, RGB(s,s,s), shadowres)
        Else  
          WorldShadows(shadowmode, -1, RGB(s,s,s))
        EndIf
  EndProcedure
  
  Procedure   eventosWindows()
    Repeat
      event= WindowEvent()
      Select event
        Case #PB_Event_Gadget
          EventGadget=  EventGadget()
          EventType=    EventType()
          
        Case #PB_Event_CloseWindow
          sal= 1
      EndSelect
    Until event= 0
  EndProcedure
  Procedure   eventos3D(camara.i=0, speed.f=0.1, mousespeed.d=0.025)
    Protected.f KeyX,KeyY
    If ExamineKeyboard()
      ;{
      If KeyboardReleased(#PB_Key_F1)
        CameraRenderMode(camara, #PB_Camera_Wireframe)
      EndIf
      If KeyboardReleased(#PB_Key_F2)
        CameraRenderMode(camara, #PB_Camera_Textured)
      EndIf
      If KeyboardReleased(#PB_Key_F3)
        WorldDebug(#PB_World_DebugNone)
      EndIf
      If KeyboardReleased(#PB_Key_F4)
        WorldDebug(#PB_World_DebugBody)
      EndIf
      
      If KeyboardReleased(#PB_Key_Pad9)
        Debug "OK"
      EndIf
      
      If KeyboardPushed(#PB_Key_Escape)
        sal=1
      EndIf
      
      If KeyboardPushed(#PB_Key_Left)
        KeyX = -speed
      ElseIf KeyboardPushed(#PB_Key_Right)
        KeyX = speed
      Else
        KeyX = 0
      EndIf
      
      If KeyboardPushed(#PB_Key_Up)
        KeyY = -speed
      ElseIf KeyboardPushed(#PB_Key_Down)
        KeyY = speed
      Else
        KeyY = 0
      EndIf
      ;}
      
      If KeyboardPushed(#PB_Key_A)
        KeyX = -speed
      ElseIf KeyboardPushed(#PB_Key_D)
        KeyX = speed
      Else
        KeyX = 0
      EndIf
      
      If KeyboardPushed(#PB_Key_W)
        KeyY = -speed
      ElseIf KeyboardPushed(#PB_Key_S)
        KeyY = speed
      Else
        KeyY = 0
      EndIf
    EndIf
    
    If ExamineMouse()
      MouseX = -MouseDeltaX() * mousespeed
      MouseY = -MouseDeltaY() * mousespeed
      mouseW = MouseWheel()
    EndIf
    
    RotateCamera(camara, MouseY, MouseX, 0, #PB_Relative)
    MoveCamera  (camara, KeyX, 0, KeyY)
  EndProcedure
  
  Procedure   creaLLuvia(size= 128, HQ.b=0)
    Protected   lluvia_imag, lluvia_mate, lluvia_bb, lluvia_nodo, lluvia_tx3d
    Protected   n,x,y,l
    lluvia_imag= CreateImage(#PB_Any,size*2,size*2,32,#PB_Image_Transparent)
    StartDrawing(ImageOutput(lluvia_imag))
      DrawingMode(#PB_2DDrawing_AlphaChannel)
        Box(0,0,OutputWidth(),OutputHeight(),$00ffffff)
      DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
      For y= 0 To OutputHeight() Step 15
      For x= 0 To OutputWidth() Step 15
        If Random(10)>8
          l= Random(18,3)
          LineXY(x,y,x+(l*0.5),y+l,$55ffffff)
;           LineXY(x+1,y+1,x+1+(l*0.5),y+1+l,$88ffffff)
          LineXY(-128+x,y,-128+x+(l*0.5),y+l,RGBA(255,255,255,n*15) )
        EndIf
      Next x
      Next y
    StopDrawing()
    ResizeImage(lluvia_imag,size,size)
    lluvia_tx3d= CreateTexture(#PB_Any,size,size,"rainTx3d")
    StartDrawing(TextureOutput(lluvia_tx3d))
      DrawAlphaImage(ImageID(lluvia_imag),0,0)
    StopDrawing()
    
    lluvia_mate= CreateMaterial(#PB_Any, TextureID(lluvia_tx3d))
      MaterialShadingMode(lluvia_mate,#PB_Material_Flat)
      DisableMaterialLighting(lluvia_mate, 1)
      MaterialBlendingMode   (lluvia_mate, #PB_Material_Add)
      ScrollMaterial(lluvia_mate,0.2,0.8,#PB_Material_Animated)
      ScaleMaterial(lluvia_mate,1/4,1/4)
      SetMaterialAttribute(lluvia_mate,#PB_Material_DepthWrite,0)
    lluvia_nodo= CreateNode(#PB_Any,0,0,0)
    lluvia_bb= CreateBillboardGroup(#PB_Any, MaterialID(lluvia_mate),10,10)
    AddBillboard(lluvia_bb,0,0,0)
    AttachNodeObject(lluvia_nodo, BillboardGroupID(lluvia_bb))
    If HQ
    lluvia_mate2= CopyMaterial(lluvia_mate,#PB_Any)
      ScrollMaterial(lluvia_mate2,0.1,0.6,#PB_Material_Animated)
    lluvia_bb2= CreateBillboardGroup(#PB_Any, MaterialID(lluvia_mate2),10,10)
    AddBillboard(lluvia_bb2,0,0,0)
    AttachNodeObject(lluvia_nodo, BillboardGroupID(lluvia_bb2))
    EndIf
;     ResizeBillboard(0 , bb_lluvia, 10,10) ; NO FUNCIONA (error memory address???)
    ScaleNode(lluvia_nodo,4,4,4,#PB_Absolute)
    FreeImage(lluvia_imag)
    ProcedureReturn lluvia_nodo
  EndProcedure
  Procedure   posLLuvia(nodo, x.f,y.f,z.f, a.f,dist=10)
    Protected.f nx,nz, na,aa
    If a<0
      na= Abs(a)
    Else
      na= (180-Abs(a))+180
    EndIf
    If na>=360:na-360:EndIf
    aa= Radian(na-90)
    nx= x + (Cos(aa) * dist)
    nz= z + (Sin(aa) * dist)
    MoveNode(nodo, nx, y, nz,#PB_Absolute)
  EndProcedure
  
  iniDX("Rain test v1 - [WASD+Mouse= Move]",1280,720)
  
  ;{ HUD
  fnt1= LoadFont(#PB_Any,"Arial",9,#PB_Font_HighQuality)
  spr1= CreateSprite(#PB_Any,100,100,#PB_Sprite_AlphaBlending)    
  ;}  
  
  ;{ SUELO
  suelo_tx3D=   CreateTexture(#PB_Any,128,128)
  StartDrawing(TextureOutput(suelo_tx3D))
    Box(0,0,OutputWidth(),OutputHeight(),$0)
    Box(10,10,OutputWidth()-20,OutputHeight()-20,$ff0000)
  StopDrawing()
  size= 50  
  suelo_mesh=   CreatePlane(#PB_Any,size,size,1,1,1,1)
  suelo_mate=   CreateMaterial(#PB_Any,TextureID(suelo_tx3D))
                ScaleMaterial(suelo_mate,1/size,1/size)
  suelo=        CreateEntity(#PB_Any, MeshID(suelo_mesh), MaterialID(suelo_mate))
  ;}
  
  ;{ CÁMARA Y LUZ
  luz=          CreateLight(#PB_Any,$ffffff,0,50,0,#PB_Light_Directional)
                LightDirection(luz,0.2,-0.4,0.3)
  
  camara=       CreateCamera(#PB_Any,0,0,100,100)
                MoveCamera(camara,0,10,15)
                CameraRange(camara,0.1,1000)
                CameraLookAt(camara,0,0,0)
  ;}
                
  lluvia_nodo=  creaLLuvia(256)
  
  SetFrameRate(50) ;- active frame rate for smooth camera move / disable for speed test
                
  Repeat
    eventosWindows()
    eventos3D(camara)
    
    posLLuvia(lluvia_nodo, CameraX(camara),CameraY(camara),CameraZ(camara), CameraYaw(camara), 20)
    
    ElapsedTime = RenderWorld()
    
    ;{ HUD
    txt.s=  "FPS: "+Str( Engine3DStatus(#PB_Engine3D_CurrentFPS) )+#CR$+#CR$+
            "Rain test v1"+#CR$+
            "minimy 2024"
    
    If contador % 25 = 0
      spr2DText(spr1,txt, fnt1, $ff00ffff )
    EndIf
    DisplayTransparentSprite(spr1, 10, 10)
    ;}
    
    FlipBuffers()
    
    contador+1
    Delay(1)
  Until sal=1
  
  
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: Simple rain test

Post by pf shadoko »

an old code that simulates rain with particles
(originally to demonstrate the use of CreateAnimatedMaterial)

Code: Select all

;#################################################################################################################
;                                              material_anim
;#################################################################################################################

Procedure copyimagetotexture(im,tx)
  Protected n=CreateTexture(tx,ImageWidth(im),ImageHeight(im))
  If tx=-1:tx=n:EndIf
  StartDrawing(TextureOutput(tx))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawImage(ImageID(im),0,0)
  StopDrawing()
  ProcedureReturn tx
EndProcedure

Procedure.f Min(v1.f,v2.f)
  If v1<v2:ProcedureReturn v1:Else:ProcedureReturn v2:EndIf
EndProcedure

;============================================================================================================

Procedure material_anim(num0,nb,dx,dy,nbp,contraste.f) 
  Structure spt:x.l:y.l:EndStructure
  Protected.l i,j,ii,jj,c,num,lum,rx,ry,d=1
  Protected Dim p.spt(nbp)
  
  For i=0 To nbp-1
    p(i)\x=Random(dx)
    p(i)\y=Random(dy)
  Next
  For j=0 To nb-1 
    num=num0+j
    CreateImage(0,dx,dy,32,#PB_Image_Transparent)
    StartVectorDrawing(ImageVectorOutput(0))
    VectorSourceColor($ff888888):FillVectorOutput()
    For i=0 To nbp-1
      r=(nb*i/nbp+j) % nb
      a=contraste*(1.0-r/nb)
      For ii=-1 To 1
        For jj=-1 To 1
          AddPathCircle(p(i)\x+d+ii*dx,p(i)\y+d+jj*dy,r):VectorSourceColor(RGBA(255,255,255,min(a,255))):StrokePath(d)
          AddPathCircle(p(i)\x-d+ii*dx,p(i)\y-d+jj*dy,r):VectorSourceColor(RGBA(0,0,0,min(a,255))):StrokePath(d)
          Next
      Next
    Next
    StopVectorDrawing()
    CreateTexture(num,dx,dy)
    copyimagetotexture(0,num)
  Next
EndProcedure

Procedure init()
  Protected ex,ey,i,j,k
  ExamineDesktops()
  ex=DesktopWidth(0)
  ey=DesktopHeight(0)
  InitEngine3D(#PB_Engine3D_DebugOutput):InitSprite():InitKeyboard():InitMouse()
  OpenWindow(0, 0, 0, ex,ey, "",#PB_Window_BorderLess):OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)
  
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures",#PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,2,-1):CameraLookAt(0,0,2,0):CameraBackColor(0,$888888)
  CreateLight(0,$aaaaaa,100,100,0)
  AmbientColor($444444)
  Fog($888888,1,0,50)
  
  LoadTexture(1, "grass.jpg")
  CreateMaterial(1, TextureID(1))
  DisableDebugger:SetMaterialAttribute(1,21,3):EnableDebugger
  
  ;;----------------------- terrain
 Protected n=128,n2=n/2
 Dim t.MeshVertex(n,n)
  For j=0 To n
    For i=0 To n
      With t(i,j)
        \u=i
        \v=j
        \x=i-n2
        \z=j-n2
        \y=Random(100)/200-0.25
        If \y<0:If Random(1): \color=$ff004488:Else:\color=$ff008844:EndIf:Else:\Color=$ffffffff:EndIf
      EndWith
    Next
  Next
  CreateDataMesh(1,t())
  NormalizeMesh(1)
  CreateEntity(1,MeshID(1),MaterialID(1))
  
  ;;----------------------- herbes
  Protected.f a,co,si,h,  p.l
  CreateMesh(3)
  For j=0 To n
    For i=0 To n
      With t(i,j)
        If \y>0.15
          h=Random(300,100)/300
          a=Random(628)/100
          For k=0 To 1
            co=Cos(a)*h
            si=Sin(a)*h
            MeshVertex(\x-co,\y-0.2,\z-si,0,1,$ff002222)
            MeshVertex(\x+co,\y-0.2,\z+si,1,1,$ff002222)
            MeshVertex(\x+co,\y+h  ,\z+si,1,0,$ff003322)
            MeshVertex(\x-co,\y+h  ,\z-si,0,0,$ff003322)
            MeshFace(p  ,p+1,p+3)
            MeshFace(p+3,p+1,p+2)
            p+4:a+#PI/2
          Next
        EndIf
      EndWith
    Next
  Next
  FinishMesh(1)
  
  LoadTexture(3,"grass2.png")
  CreateMaterial(3,TextureID(3))
  SetMaterialAttribute(3,#PB_Material_AlphaReject,127)
  SetMaterialAttribute(3,#PB_Material_TAM,#PB_Material_ClampTAM)
  DisableMaterialLighting(3,1)
  MaterialCullingMode(3,#PB_Material_NoCulling)
  CreateEntity(3,MeshID(3),MaterialID(3))
  
  ;;----------------------- ciel
   CreateMaterial(4,0,$77aaaaaa)
   SetMaterialColor(4,#PB_Material_SelfIlluminationColor,$aaaaaa)
   MaterialCullingMode(4,#PB_Material_AntiClockWiseCull)
   CreatePlane(4,10000,10000,1,1,40,40)
   CreateEntity(4,MeshID(4),MaterialID(4),0,10,0)

  
  ;;----------------------- pluie
  CreateTexture(2,16,1024)
  StartDrawing(TextureOutput(2)):DrawingMode(#PB_2DDrawing_AllChannels)
  For j=8 To 1024 Step 200:Circle(8,j,8,$ff666666):Next
  StopDrawing()
  CreateMaterial(2, TextureID(2))  
  DisableMaterialLighting(2, 1)
  SetMaterialAttribute(2,#PB_Material_AlphaReject,127)
  ;MaterialBlendingMode(2,#PB_Material_AlphaBlend)
  SetMaterialAttribute(2,#PB_Material_TAM,#PB_Material_ClampTAM)
  
  CreateParticleEmitter(0, 6, 6, 0, #PB_Particle_Point)
  ParticleMaterial    (0, MaterialID(2))
  ParticleSize        (0, 0.005,1)
  ParticleEmitterDirection(0, 0, 1, 0)
  ParticleTimeToLive  (0, 1.5,1.5)
  ParticleVelocity(0, #PB_Particle_Velocity,-2)
  ParticleEmissionRate(0, 800)  
  
  ;----------------------- eau
  material_anim(100,60,128,128,32,255)  
  Dim tid(60-1):For i=0 To 60-1:tid(i)=TextureID(100+i):Next
  CreateAnimatedMaterial(100,tid(),1)
  ;reflexion
  CreateCamera(1,0,0,100,100)
  CreateRenderTexture(10,CameraID(1),ScreenWidth()/2,ScreenHeight()/2)
  AddMaterialLayer(100,TextureID(10),#PB_Material_Modulate)
  SetMaterialAttribute(100,#PB_Material_ProjectiveTexturing,1,1)
  
  MaterialBlendingMode(100,#PB_Material_AlphaBlend)
  DisableMaterialLighting(100,1)
  CreatePlane(0,256,256,128,128,256*2,256*2)
  CreateEntity(0,MeshID(0),MaterialID(100))
EndProcedure  

Procedure rendu()
  Protected.l i,col
  Protected.f keyx,keyz,MouseX,Mousey
  Repeat
    While WindowEvent():Wend
    ExamineMouse()
    ExamineKeyboard()
    MouseX = -MouseDeltaX() *  0.05
    MouseY = -MouseDeltaY() *  0.05
    keyx=(-Bool(KeyboardPushed(#PB_Key_Left)<>0)+Bool(KeyboardPushed(#PB_Key_Right)<>0))*0.05
    keyz=(-Bool(KeyboardPushed(#PB_Key_Down)<>0)+Bool(KeyboardPushed(#PB_Key_Up   )<>0))*0.05+MouseWheel()*2
    RotateCamera(0, MouseY, MouseX, 0, #PB_Relative):MoveCamera(0, keyx, 0, -keyz,#PB_Local ):MoveCamera(0,CameraX(0),1.6,CameraZ(0),#PB_Absolute )
    MoveParticleEmitter(0,CameraX(0)+CameraDirectionX(0)*2,CameraY(0)+CameraDirectionY(0)*2+1,CameraZ(0)+CameraDirectionZ(0)*2,#PB_Absolute)
      CameraReflection(1,0,EntityID(0))  
    RenderWorld()
    FlipBuffers()    
  Until MouseButton(#PB_MouseButton_Left) Or KeyboardReleased(#PB_Key_Escape)
EndProcedure

init()
rendu()
Cyllceaux
Enthusiast
Enthusiast
Posts: 511
Joined: Mon Jun 23, 2014 1:18 pm

Re: Simple rain test

Post by Cyllceaux »

Everytime I see demos from you, I feel like dumb a.f.

So less code, so impressive
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Simple rain test

Post by threedslider »

Both demos are awesome ! :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Simple rain test

Post by Psychophanta »

threedslider wrote: Sun Mar 24, 2024 10:27 am Both demos are awesome ! :)
+1
The one from pf shadoko reminded me of walking dead :shock:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Simple rain test

Post by minimy »

Wow pf shadoko! really nice demo! You are a 3D master!
Thanks pfshadoko for share, and Cylleaux and threeslider for comments!!

I got another simple code using CreateAnimatedMaterial. Now rain 3D. Can see the effect when move camera, and use 2 layers for more realistic rain.

if change the last parameter of 'creaLLuvia3D(256,8,3,20,0)' to 1 is snow. But the effect is not so good as the rain... :cry:

I hope you like.
Feel free to add thunders and rays :mrgreen:

Code: Select all


  Global.b sal

  Procedure   spr2DText(spr, txt.s, font, ink.l=$ff00ff00)
    Protected n,y=2,tl= CountString(txt,#CR$)
    Protected tx.s
    StartDrawing(SpriteOutput(spr))
    DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0,0,OutputWidth(),OutputHeight(),$00000000)
    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
      Box(0,0,OutputWidth(),OutputHeight(),$aa000000)
      DrawingFont(FontID(font))
      For n=1 To tl+1
        tx= StringField(txt,n,#CR$)
        DrawText(5,y,tx,ink)
        y+16
      Next n
      DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Outlined)
      Box(0,0,OutputWidth(),OutputHeight(),ink)
    StopDrawing()
  EndProcedure

  Procedure   iniDX(title.s="3D", width=800,height=600, AA.i=#PB_AntialiasingMode_None, shadowmode= #PB_Shadow_Modulative, shadowres=4096, param=#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    InitEngine3D()
      InitSprite()
      InitKeyboard()
      InitMouse()
      AntialiasingMode(#PB_AntialiasingMode_None)
      
      OpenWindow(0, 0, 0, width, height, title, param)
        SetWindowColor(0,$444444)
;         creaGadgets(width,height)
      
      OpenWindowedScreen(WindowID(0), 0, 0, (width * DesktopResolutionX()), (height * DesktopResolutionY()),0,0,0,#PB_Screen_NoSynchronization)
        KeyboardMode(#PB_Keyboard_International)
        Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
        Add3DArchive("Data/Model", #PB_3DArchive_FileSystem)
        Add3DArchive("Data", #PB_3DArchive_FileSystem)
        Parse3DScripts()

        Protected.b s= 100
        If shadowmode= #PB_Shadow_TextureAdditive Or shadowmode= #PB_Shadow_TextureModulative
          WorldShadows(shadowmode, -1, RGB(s,s,s), shadowres)
        Else  
          WorldShadows(shadowmode, -1, RGB(s,s,s))
        EndIf
;         WorldShadows(#PB_Shadow_Modulative, -1, RGB(s,s,s))
;         WorldShadows(#PB_Shadow_Additive, -1, RGB(s,s,s))
;         WorldShadows(#PB_Shadow_TextureAdditive, 1000, RGB(s,s,s), 4096)
;         WorldShadows(#PB_Shadow_TextureModulative, -1, RGB(s,s,s))
  EndProcedure
  
  Procedure   eventosWindows()
    Repeat
      event= WindowEvent()
      Select event
        Case #PB_Event_Gadget
          EventGadget=  EventGadget()
          EventType=    EventType()
          
        Case #PB_Event_CloseWindow
          sal= 1
      EndSelect
    Until event= 0
  EndProcedure
  Procedure   eventos3D(camara.i=0, speed.f=0.1, mousespeed.d=0.025)
    Protected.f KeyX,KeyY
    If ExamineKeyboard()
      ;{
      If KeyboardReleased(#PB_Key_F1)
        CameraRenderMode(camara, #PB_Camera_Wireframe)
      EndIf
      If KeyboardReleased(#PB_Key_F2)
        CameraRenderMode(camara, #PB_Camera_Textured)
      EndIf
      If KeyboardReleased(#PB_Key_F3)
        WorldDebug(#PB_World_DebugNone)
      EndIf
      If KeyboardReleased(#PB_Key_F4)
        WorldDebug(#PB_World_DebugBody)
      EndIf
      
      If KeyboardReleased(#PB_Key_Pad9)
        Debug "OK"
      EndIf
      
      If KeyboardPushed(#PB_Key_Escape)
        sal=1
      EndIf
      
      If KeyboardPushed(#PB_Key_Left)
        KeyX = -speed
      ElseIf KeyboardPushed(#PB_Key_Right)
        KeyX = speed
      Else
        KeyX = 0
      EndIf
      
      If KeyboardPushed(#PB_Key_Up)
        KeyY = -speed
      ElseIf KeyboardPushed(#PB_Key_Down)
        KeyY = speed
      Else
        KeyY = 0
      EndIf
      ;}
      
      If KeyboardPushed(#PB_Key_A)
        KeyX = -speed
      ElseIf KeyboardPushed(#PB_Key_D)
        KeyX = speed
      Else
        KeyX = 0
      EndIf
      
      If KeyboardPushed(#PB_Key_W)
        KeyY = -speed
      ElseIf KeyboardPushed(#PB_Key_S)
        KeyY = speed
      Else
        KeyY = 0
      EndIf
    EndIf
    
    If ExamineMouse()
      MouseX = -MouseDeltaX() * mousespeed
      MouseY = -MouseDeltaY() * mousespeed
      mouseW = MouseWheel()
    EndIf
    
    RotateCamera(camara, MouseY, MouseX, 0, #PB_Relative)
    MoveCamera  (camara, KeyX, 0, KeyY)
  EndProcedure
  
  Procedure   creaLLuvia3D(size= 128, caras.b=8, r.b=5, h.b=20, tipo.b=1)
    ;devuelve entidad con la lluvia
    Protected   lluvia_imag, lluvia_tx3d, lluvia_tx3d2, lluvia_mate, lluvia_mesh, lluvia_enti
    Protected   n,x,y,l
    ;{ textura
    lluvia_imag= CreateImage(#PB_Any,size*2,size*2,32,#PB_Image_Transparent)
          Select tipo
            Case 0 ;lluvia
              StartDrawing(ImageOutput(lluvia_imag))
                DrawingMode(#PB_2DDrawing_AlphaChannel)
                  Box(0,0,OutputWidth(),OutputHeight(),$00ffffff)
                DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
              For y= 0 To OutputHeight() Step 15
                For x= 0 To OutputWidth() Step 15
                  If Random(10)>8
                    l= Random(18,3)
                    LineXY(x,y,x+(l*0.5),y+l,$55ffffff)
          ;           LineXY(x+1,y+1,x+1+(l*0.5),y+1+l,$88ffffff)
                    LineXY(-128+x,y,-128+x+(l*0.5),y+l,RGBA(255,255,255,n*15) )
                  EndIf
                Next x
              Next y
              StopDrawing()
              ResizeImage(lluvia_imag,size,size)
              lluvia_tx3d= CreateTexture(#PB_Any,size,size)
              StartDrawing(TextureOutput(lluvia_tx3d))
                DrawAlphaImage(ImageID(lluvia_imag),0,0)
              StopDrawing()
            Case 1 ;nieve
              StartDrawing(ImageOutput(lluvia_imag))
                DrawingMode(#PB_2DDrawing_AlphaChannel)
                  Box(0,0,OutputWidth(),OutputHeight(),$00ffffff)
                DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Gradient)
              For y= 0 To OutputHeight() Step 15
                For x= 0 To OutputWidth() Step 15
                  If Random(10)>8
                    l= Random(5,2)
                    BackColor($88ffffff)
                    FrontColor($00ffffff)
                    CircularGradient(x, y, l)
                    Circle(x, y, l)
                  EndIf
                Next x
              Next y
              StopDrawing()
              ResizeImage(lluvia_imag,size,size)
              lluvia_tx3d= CreateTexture(#PB_Any,size,size)
              StartDrawing(TextureOutput(lluvia_tx3d))
                DrawAlphaImage(ImageID(lluvia_imag),0,0)
              StopDrawing()
              FreeImage(lluvia_imag)
                ;capa2
              lluvia_imag= CreateImage(#PB_Any,size*2,size*2,32,#PB_Image_Transparent)
              StartDrawing(ImageOutput(lluvia_imag))
                DrawingMode(#PB_2DDrawing_AlphaChannel)
                  Box(0,0,OutputWidth(),OutputHeight(),$00ffffff)
                DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Gradient)
              For y= 0 To OutputHeight() Step 15
                For x= 0 To OutputWidth() Step 15
                  If Random(20)>18
                    l= Random(7,3)
                    BackColor($88ffffff)
                    FrontColor($00ffffff)
                    CircularGradient(x, y, l)
                    Circle(x, y, l)
                  EndIf
                Next x
              Next y
              StopDrawing()
              ResizeImage(lluvia_imag,size,size)
              lluvia_tx3d2= CreateTexture(#PB_Any,size,size)
              StartDrawing(TextureOutput(lluvia_tx3d2))
                DrawAlphaImage(ImageID(lluvia_imag),0,0)
              StopDrawing()
          EndSelect
    ;}
    ;{ material
    Select tipo
      Case 0 ;lluvia
        lluvia_mate= CreateMaterial(#PB_Any, TextureID(lluvia_tx3d))
          MaterialShadingMode(lluvia_mate,#PB_Material_Flat)
          DisableMaterialLighting(lluvia_mate, 1)
          MaterialBlendingMode(lluvia_mate, #PB_Material_Add)
    ;       MaterialCullingMode(lluvia_mate,#PB_Material_NoCulling)
          ScrollMaterial(lluvia_mate,0.2,0.8,#PB_Material_Animated)
          ScaleMaterial(lluvia_mate,1/4,1/4)
          SetMaterialAttribute(lluvia_mate,#PB_Material_DepthWrite,0)
        AddMaterialLayer(lluvia_mate,TextureID(lluvia_tx3d),#PB_Material_Add)
          ScaleMaterial(lluvia_mate,1/4,1/4,1)
          ScrollMaterial(lluvia_mate,0.3,0.7,#PB_Material_Animated,1)
      Case 1 ;nieve
        lluvia_mate= CreateMaterial(#PB_Any, TextureID(lluvia_tx3d2))
          MaterialShadingMode(lluvia_mate,#PB_Material_Flat)
          DisableMaterialLighting(lluvia_mate, 1)
          MaterialBlendingMode(lluvia_mate, #PB_Material_Add)
          ScrollMaterial(lluvia_mate,0.1,0.3,#PB_Material_Animated)
          ScaleMaterial(lluvia_mate,1/4,1/24)
          SetMaterialAttribute(lluvia_mate,#PB_Material_DepthWrite,0)
        AddMaterialLayer(lluvia_mate,TextureID(lluvia_tx3d),#PB_Material_Add)
          ScaleMaterial(lluvia_mate,1/4,1/24,1)
          ScrollMaterial(lluvia_mate,0.2,0.2,#PB_Material_Animated,1)
    EndSelect
    
    ;}
    ;{ objeto  
    Protected.f nx1,nz1,nx2,nz2
    Protected.f a=0, pa.f=360/caras, hh=h/2
    lluvia_mesh= CreateMesh(#PB_Any)
    x=0:y=0
    For p=0 To caras-1
      a= p*pa
      a= Radian(a-90)
      nx1= x + (Cos(a) * r)
      nz1= z + (Sin(a) * r)
      a= (p+1)*pa
      a= Radian(a-90)
      nx2= x + (Cos(a) * r)
      nz2= z + (Sin(a) * r)
      If p>0:AddSubMesh(#PB_Mesh_TriangleList):EndIf
      MeshVertex(nx1, hh,nz1, 0,0, $ffffff, 0,0,0)
      MeshVertex(nx2, hh,nz2, 1,0, $ffffff, 0,0,0)
      MeshVertex(nx2,-hh,nz2, 1,1, $ffffff, 0,0,0)
      MeshVertex(nx1,-hh,nz1, 0,1, $ffffff, 0,0,0)
;       Debug StrF(nx1,2)+"  "+ StrF(nz1,2)
      MeshFace(3,2,1,0)
    Next p
    FinishMesh(1)
    lluvia_enti= CreateEntity(#PB_Any,MeshID(lluvia_mesh),MaterialID(lluvia_mate))
    EntityRenderMode(lluvia_enti,#PB_Shadow_None)
    ;}
    
    FreeImage(lluvia_imag)
    ProcedureReturn lluvia_enti
  EndProcedure
  
  iniDX("Rain test v1 - [WASD+Mouse= Move]",1280,720)
  
  ;{ HUD
  fnt1= LoadFont(#PB_Any,"Arial",9,#PB_Font_HighQuality)
  spr1= CreateSprite(#PB_Any,100,100,#PB_Sprite_AlphaBlending)    
  ;}  
  
  ;{ SUELO
  suelo_tx3D=   CreateTexture(#PB_Any,128,128)
  StartDrawing(TextureOutput(suelo_tx3D))
    Box(0,0,OutputWidth(),OutputHeight(),$0)
    Box(10,10,OutputWidth()-20,OutputHeight()-20,$ff0000)
  StopDrawing()
  size= 50  
  suelo_mesh=   CreatePlane(#PB_Any,size,size,1,1,1,1)
  suelo_mate=   CreateMaterial(#PB_Any,TextureID(suelo_tx3D))
                ScaleMaterial(suelo_mate,1/size,1/size)
  suelo=        CreateEntity(#PB_Any, MeshID(suelo_mesh), MaterialID(suelo_mate))
  ;}
  
  ;{ CÁMARA Y LUZ
  AmbientColor($444444)
  luz=          CreateLight(#PB_Any,$ffffff,0,50,0,#PB_Light_Directional)
                LightDirection(luz,0.2,-0.4,0.3)
  
  camara=       CreateCamera(#PB_Any,0,0,100,100)
                MoveCamera(camara,0,10,15)
                CameraRange(camara,0.1,1000)
                CameraLookAt(camara,0,0,0)
  ;}
                
  lluvia_enti=  creaLLuvia3D(256,8,3,20,0)
  
  
  SetFrameRate(50) ;- active frame rate for smooth camera move / disable for speed test
                
  Repeat
    eventosWindows()
    eventos3D(camara)
    
    MoveEntity(lluvia_enti, CameraX(camara),CameraY(camara),CameraZ(camara),#PB_Absolute)
    
    ElapsedTime = RenderWorld()
    
    ;{ HUD
    txt.s=  "FPS: "+Str( Engine3DStatus(#PB_Engine3D_CurrentFPS) )+#CR$+#CR$+
            "Rain test v1"+#CR$+
            "minimy 2024"
    
    If contador % 25 = 0
      spr2DText(spr1,txt, fnt1, $ff00ffff )
    EndIf
    DisplayTransparentSprite(spr1, 10, 10)
    ;}
    
    FlipBuffers()
    
    contador+1
    Delay(1)
  Until sal=1
  
  
  
  
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Simple rain test

Post by Psychophanta »

@minimy , it is the most real rain :!:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Simple rain test

Post by minimy »

Hey psychophanta! Coming from a master like you, your comment makes me very happy.
Thanks psychophanta!!
Have nice day!
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Simple rain test

Post by Psychophanta »

:lol:
Master?
Nooope! Forever learner :!:

I would give everything I know for a thousandth of what I don't know = Daría todo lo que sé, por la milésima parte de lo que no sé
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply