
The demo change cycle in automatic mode.
Now use alpha and colors from light blue to white.
I hope you like.
Code: Select all
Global.b sal
;{ SISTEMA 3D
Procedure muestraModosPantalla()
If ExamineScreenModes()
While NextScreenMode()
Debug Str(ScreenModeWidth())+"x"+Str(ScreenModeHeight())+"x"+Str(ScreenModeDepth())+"@"+Str(ScreenModeRefreshRate())+"Hz"
Wend
EndIf
EndProcedure
Procedure iniDX(title.s="3D", width=800,height=600, fullscreen.b=#False, AA.i=#PB_AntialiasingMode_None, shadowmode= #PB_Shadow_Modulative, shadowres=4096, param=#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Protected.b screenTestOK
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
AntialiasingMode(AA)
If width=0 And height=0
ExamineDesktops()
width= DesktopWidth(0)
height= DesktopHeight(0)
pantallaCompleta= 0
param= #PB_Window_BorderLess
EndIf
If fullscreen
pantallaCompleta= 1
If ExamineScreenModes()
While NextScreenMode()
; Debug Str(ScreenModeWidth())+"x"+Str(ScreenModeHeight())+"x"+Str(ScreenModeDepth())+"@"+Str(ScreenModeRefreshRate())+"Hz"
If ScreenModeWidth()=width And ScreenModeHeight()=height And ScreenModeDepth()=32
screenTestOK= 1
EndIf
Wend
EndIf
If screenTestOK= 0
width=1280:height=720
EndIf
OpenScreen(width,height,32,title,#PB_Screen_NoSynchronization)
Else
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)
EndIf
KeyboardMode(#PB_Keyboard_International)
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Model", #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
; iniDX("Base 3D",1280,800,#True) ;pantalla completa
; iniDX("Base 3D - WASD=move (Umbrella recomended) :)",960,540,#False,#PB_AntialiasingMode_None,#PB_Shadow_Additive) ;modo ventana
iniDX("Base 3D",0,0,#False,#PB_AntialiasingMode_None,#PB_Shadow_Modulative, 512) ; pantalla completa en veentana
;}
;{ EVENTOS
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 KeyboardPushed(#PB_Key_Escape)
sal=1
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
;}
;{ FX RAIN
Structure lluviaMat_stru
tx3d.i
mate.i
enti.i
EndStructure
Structure lluvia_stru
mesh.i
nodo.i
List mats.lluviaMat_stru()
EndStructure
Global NewList lluvia.lluvia_stru()
Procedure lluvia3D(size= 128, caras.b=8, r.f=5, h.b=20, uS.f=4,vS.f=4)
;devuelve nodo de la lluvia
Protected i= CreateImage(#PB_Any,size*2,size*2,32,#PB_Image_Transparent)
Protected.b p
Protected n,x,y,l
Protected Dim xy(550,2)
AddElement(lluvia())
lluvia()\nodo= CreateNode(#PB_Any)
lluvia()\mesh= CreateCylinder(#PB_Any,r,h,8,1,#False)
;{ texturas
For n= 1 To 550
xy(n,0)= Random(ImageWidth(i)+30)-15
xy(n,1)= Random(ImageHeight(i)+30)-15
xy(n,2)= Random(18,3)
Next n
For p= 1 To 10
AddElement(lluvia()\mats())
StartDrawing(ImageOutput(i))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,OutputWidth(),OutputHeight(),$00000000)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
If p > 1
n=0
While n < 50+ ((p-1)*50)
LineXY(xy(n,0),xy(n,1),xy(n,0)+(xy(n,2)*0.5),xy(n,1)+xy(n,2),RGBA(155+Random(55),200+Random(55),255,Random((p*10)+155,(p*10)+55) ))
n+1
Wend
EndIf
StopDrawing()
ResizeImage(i,size,size)
lluvia()\mats()\tx3d= CreateTexture(#PB_Any,size,size)
StartDrawing(TextureOutput(lluvia()\mats()\tx3d))
DrawAlphaImage(ImageID(i),0,0)
StopDrawing()
lluvia()\mats()\mate= CreateMaterial(#PB_Any, TextureID(lluvia()\mats()\tx3d))
MaterialShadingMode(lluvia()\mats()\mate,#PB_Material_Flat)
DisableMaterialLighting(lluvia()\mats()\mate, 1)
MaterialBlendingMode(lluvia()\mats()\mate, #PB_Material_Add)
ScrollMaterial(lluvia()\mats()\mate,0.2,0.8,#PB_Material_Animated)
ScaleMaterial(lluvia()\mats()\mate,1/uS,1/vS)
SetMaterialAttribute(lluvia()\mats()\mate,#PB_Material_DepthWrite,0)
AddMaterialLayer(lluvia()\mats()\mate,TextureID(lluvia()\mats()\tx3d),#PB_Material_Add)
ScaleMaterial(lluvia()\mats()\mate,1/uS,1/vS,1)
ScrollMaterial(lluvia()\mats()\mate,0.3,0.5,#PB_Material_Animated,1)
MaterialCullingMode(lluvia()\mats()\mate,#PB_Material_NoCulling)
;}
lluvia()\mats()\enti= CreateEntity(#PB_Any,MeshID(lluvia()\mesh),MaterialID(lluvia()\mats()\mate))
EntityRenderMode(lluvia()\mats()\enti,#PB_Shadow_None)
RotateEntity(lluvia()\mats()\enti, 180,0,0,#PB_Absolute)
AttachNodeObject(lluvia()\nodo, EntityID(lluvia()\mats()\enti) )
HideEntity(lluvia()\mats()\enti,1)
Next p
FirstElement( lluvia()\mats() )
HideEntity(lluvia()\mats()\enti,0)
FreeImage(i)
EndProcedure
Procedure lluviaSet(fuerza.b)
If fuerza <= 0 : fuerza= 0 : EndIf
If fuerza >= ListSize(lluvia()\mats()) : fuerza= ListSize(lluvia()\mats())-1 : EndIf
For p= 0 To 9
SelectElement(lluvia()\mats(), p)
HideEntity(lluvia()\mats()\enti,1)
If p= fuerza
; SetEntityMaterial(lluvia()\enti, MaterialID(lluvia()\mats()\mate) )
HideEntity(lluvia()\mats()\enti,0)
EndIf
Next p
ProcedureReturn fuerza
EndProcedure
;}
;{ HUD
fnt1= LoadFont(#PB_Any,"Arial",9,#PB_Font_HighQuality)
spr1= CreateSprite(#PB_Any,100,100,#PB_Sprite_AlphaBlending)
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
;}
;{ 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.05,1000)
; CameraLookAt(camara,0,0,0)
;}
lluvia3D(256,8,0.5,20, 32,24)
SetFrameRate(50) ;- comment this line for speed test
k= 1
rainForce= 0
Repeat
eventosWindows()
eventos3D(camara)
MoveNode(lluvia()\nodo, CameraX(camara),CameraY(camara),CameraZ(camara),#PB_Absolute)
ElapsedTime = RenderWorld()
;{ HUD
txt.s= "FPS: "+Str( Engine3DStatus(#PB_Engine3D_CurrentFPS) )+#CR$+
"Rain test v2"+#CR$+
"Force= "+Str(rainForce)+#CR$+
"minimy 2024"
If contador % 25 = 0
If rainForce > 9
k= -1
ElseIf rainForce < 0
k= 1
EndIf
rainForce + k
lluviaSet(rainForce)
spr2DText(spr1,txt, fnt1, $ff00ffff )
EndIf
DisplayTransparentSprite(spr1, 10, 10)
;}
FlipBuffers()
contador+1
Delay(1)
Until sal=1