Page 1 sur 1

Problème de performances

Publié : mer. 19/mars/2008 16:01
par kelebrindae
Bonjour à tous,

Dans le but de me faire un peu la main en 3D avec PB, je me suis lancé dans la migration en PB d'un économiseur d'écran que j'avais développé il y a quelques années:
http://keleb.free.fr/codecorner/screensavers01.htm
Le principal est fait, et le résultat assez convaincant; ça fait des jolis cubes en couleurs qui volent dans tous les sens. :)

Par contre, les perfs m'inquiètent un peu: avec 512 cubes ça va bien, mais avec 1024 cubes le frame rate tombe en dessous de 20 FPS (alors qu'il n'y a que 12500 polys et 6-7 textures); ça, c'est sur mon P4 3.06Ghz sous XP avec 1.5 Go de Ram et GPU Intel 910GL (GPU bureautique, mais suffisant pour faire tourner des jeux récents si on se limite aux niveaux de détails bas)
Mais le pire, c'est sur mon portable Core 2 Duo T7300 sous Vista avec 2 Go de Ram et une GeForce 8600M GT, où même avec 512 cubes je n'obtiens que 15-16 FPS !
Je veux dire, c'est pas Crysis, quand même; ce n'est pas supposé se traîner comme ça... :?

Je vous donne le code; quelqu'un peut me dire ce qui ne va pas ?
Merci d'avance!

Code : Tout sélectionner

; Author: Kelebrindae (+ code from the "cylinder 3D" demo, from Comtois)
; Date: march,14, 2006
; PB version: v4.00
; OS: Windows XP
; Demo: Yes


;- Initialisation 
Resultat = MessageRequester("Platonic Solids","Full Screen ?",#PB_MessageRequester_YesNo) 
If Resultat = 6      
  FullScreen=1 
Else            
  FullScreen=0 
EndIf 

If InitEngine3D() = 0 
   MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 ) 
   End 
ElseIf InitSprite() = 0 Or InitKeyboard() = 0 
   MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 ) 
   End 
EndIf 

If Fullscreen  
  OpenScreen(1024,768,32,"Platonic Solids") 
Else 
  OpenWindow(0,0, 0, 1024 , 768,"Platonic Solids",#PB_Window_ScreenCentered) 
  OpenWindowedScreen(WindowID(0),0,0, 1024 , 768,0,0,0) 
EndIf 

;- Data structures and definitions
Global CameraMode.l 

Structure Vertex 
  px.f 
  py.f 
  pz.f 
  nx.f 
  ny.f 
  nz.f 
  Couleur.l 
  U.f 
  V.f 
EndStructure 

Structure FaceTri 
  f1.w 
  f2.w 
  f3.w 
EndStructure 

Enumeration
  #tetrahedron
  #cube
  #octahedron
  #dodecahedron
  #icosahedron
EndEnumeration

Structure quaternion
  x.f
  y.f
  z.f
  w.f
EndStructure

Structure vector3
  x.f
  y.f
  z.f
EndStructure

Global numcube.l = 512 ; Change this to alter the number of objects on screen
Global cQuat.quaternion
Global pResultVector.vector3

;- ---- Procedures ----
;************************************************************************************
; Name: CreatePlatonicMesh
; Purpose: Create a platonic solid mesh, scaled
; Parameters:
;   - solide: #tetrahedron,#cube,#octahedron,#dodecahedron, or #icosahedron
;   - X size
;   - Y size
;   - Z size
;   - origin of mapping coord U 
;   - origin of mapping coord V
;   - Vertices color
; Return value: mesh number, or -1 if an error occurs
;************************************************************************************
Procedure.l CreatePlatonicMesh(solid.l,sizeX.f,sizeY.f,sizeZ.f,Uorigin.f,Vorigin.f,Uscale.f,Vscale.f,color.l) 

  Protected nbVert.l , nbTri.l              ; Number of vertices and faces
  Protected x.f,y.f,z.f                     ; vertex position
  Protected nx.f,ny.f,nz.f                  ; vertex normals
  Protected u.f,v.f                         ; vertex UV coords (texture mapping)
  Protected *PtrV.Vertex,*vertexBuffer.l    ; vertices buffer in memory
  Protected *PtrF.FaceTri,*facetriBuffer.l  ; Faces buffer in memory
  Protected newmesh.l                       ; Procedure Result
  
  ; Restore the good set of meshdatas
  Select solid
    Case #tetrahedron
      Restore tetrahedron
    
    Case #cube
      Restore cube
    
    Case #octahedron
      Restore octahedron
    
    Case #dodecahedron
      Restore dodecahedron
      
    Case #icosahedron
      Restore icosahedron
    
    Default
      ProcedureReturn -1 
  EndSelect 

  ; Read number of vertices and triangles
  Read nbVert
  Read nbTri

  ; Allocate the needed memory for vertices
  *vertexBuffer = AllocateMemory(SizeOf(Vertex)*nbVert) 
  *PtrV = *vertexBuffer 

  ; Read and store vertices position, normals, uv coords
  For i = 1 To nbVert
    Read x
    Read y
    Read z
    Read nx
    Read ny
    Read nz
    Read u
    Read v
  
    *PtrV\px = x * sizex
    *PtrV\py = y * sizey
    *PtrV\pz = z * sizez
    
    *PtrV\nx = nx 
    *PtrV\ny = ny
    *PtrV\nz = nz 
    *PtrV\couleur = Color 
    *PtrV\u = uorigin + (u * uscale)
    *PtrV\v = vorigin + (v * vscale)
    *PtrV + SizeOf(Vertex) 
  Next i    


  ; Allocate the needed memory for faces
  *facetriBuffer=AllocateMemory(SizeOf(FaceTri)*nbTri) 
  *PtrF=*facetriBuffer 
  
  ;Read and store faces infos
  For i=1 To nbTri 
    Read v1
    Read v2
    Read v3 
     
    *PtrF\f1=v1  
    *PtrF\f2=v2 
    *PtrF\f3=v3 
    *PtrF + SizeOf(FaceTri) 
  Next i 
     
  ; Create mesh from stored infos
  newmesh = CreateMesh(#PB_Any,100)
  If IsMesh(newmesh) 
    SetMeshData(newmesh,#PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color,*vertexBuffer,nbVert) 
    SetMeshData(newmesh,#PB_Mesh_Face,*facetriBuffer,nbTri) 
    ; and don't forget to free memory
    FreeMemory(*vertexBuffer)
    FreeMemory(*facetriBuffer)
    ProcedureReturn newmesh 
  Else 
    ; even if "createMesh" has failed
    FreeMemory(*vertexBuffer)
    FreeMemory(*facetriBuffer)
    ProcedureReturn -1    
  EndIf 
    
EndProcedure    

;************************************************************************************
; Name: EulerAnglesToQuat
; Purpose: convert three Euler angles X,Y,Z to a quaternion
; Parameters: X,Y,Z angles, in radians
; Return-Value: nothing, but store the result in the quaternion called "cQuat"
;************************************************************************************

Procedure EulerAnglesToQuat(x.f,y.f,z.f)
    Protected roll.f,pitch.f,yaw.f
    Protected cyaw.f, cpitch.f, croll.f, syaw.f, spitch.f, sroll.f
    Protected cyawcpitch.f, syawspitch.f, cyawspitch.f, syawcpitch.f
    Protected norm.f
    
    roll = x
    pitch= y
    yaw  = z

    cyaw = Cos(0.5 * yaw)
    cpitch = Cos(0.5 * pitch)
    croll = Cos(0.5 * roll)
    syaw = Sin(0.5 * yaw)
    spitch = Sin(0.5 * pitch)
    sroll = Sin(0.5 * roll)

    cyawcpitch = cyaw*cpitch
    syawspitch = syaw*spitch
    cyawspitch = cyaw*spitch
    syawcpitch = syaw*cpitch


    norm = (cyawcpitch * croll + syawspitch * sroll)

    cQuat\x = (cyawcpitch * sroll - syawspitch * croll)
    cQuat\y = (cyawspitch * croll + syawcpitch * sroll)
    cQuat\z = (syawcpitch * croll - cyawspitch * sroll)
    cQuat\w = norm
EndProcedure

;************************************************************************************
; Name: QuaternionTransform
; Purpose: apply a vector3 transform to the quaternion cQuat (=> translation)
; Parameters: X,Y,Z values
; Return-Value: nothing, but store the result in the vector3 called "pResult"
;************************************************************************************
Procedure QuaternionTransform(x.f,y.f,z.f)

	pResultVector\x = cQuat\w*cQuat\w*x + 2*cQuat\y*cQuat\w*z - 2*cQuat\z*cQuat\w*y + cQuat\x*cQuat\x*x + 2*cQuat\y*cQuat\x*y + 2*cQuat\z*cQuat\x*z - cQuat\z*cQuat\z*x - cQuat\y*cQuat\y*x
	pResultVector\y = 2*cQuat\x*cQuat\y*x + cQuat\y*cQuat\y*y + 2*cQuat\z*cQuat\y*z + 2*cQuat\w*cQuat\z*x - cQuat\z*cQuat\z*y + cQuat\w*cQuat\w*y - 2*cQuat\x*cQuat\w*z - cQuat\x*cQuat\x*y;
	pResultVector\z = 2*cQuat\x*cQuat\z*x + 2*cQuat\y*cQuat\z*y + cQuat\z*cQuat\z*z - 2*cQuat\w*cQuat\y*x - cQuat\y*cQuat\y*z + 2*cQuat\w*cQuat\x*y - cQuat\x*cQuat\x*z + cQuat\w*cQuat\w*z;
	
EndProcedure

;************************************************************************************
; Name: CurveValue
; Purpose: provide a smooth transition between "actuelle" and "Cible" values
; Parameters:
;   - Cible : target value
;   - actuelle: current value
;   - P : nb steps between the two values
; Return-Value: result
;************************************************************************************
Procedure.f CurveValue(Cible.f, actuelle.f, P.f)
  ;Calcule une valeur progressive allant de la valeur actuelle à la valeur cible
  Protected Delta.f
  
  Delta = Cible - actuelle
  If P > 1000.0
    P = 1000.0
  EndIf
  
  ProcedureReturn  (actuelle + ( Delta * P / 1000.0))
EndProcedure

;************************************************************************************
; Name: WrapValueF
; Purpose: provide a modulo(360) operation for floats => useful for angles
; Parameters: angle
; Return-Value: result (0 >= result < 360)
;************************************************************************************
Procedure.f wrapValueF(angle.f)
    If angle < 0
      ProcedureReturn angle+360
    ElseIf angle >= 360
        ProcedureReturn angle-360
    EndIf
  ProcedureReturn angle
EndProcedure


;- ---- Main program ----

;-Texture 
; Create a "rainbowy" 64x64 texture
CreateTexture(0,64,64) 
StartDrawing(TextureOutput(0)) 
  numstep.w=171
  value.f=0
  x.w=0:y.w=0
  couleur.l
  For mode=1 To 6
     For i=1 To numstep
        value=i*(255.00/numstep)
        If value>255
          value=255
        EndIf
  
        Select mode
           Case 1
              couleur = RGB(255,value,0)

           Case 2
              couleur = RGB(255-value,255,0)
 
           Case 3
              couleur = RGB(0,255,value)

           Case 4
              couleur = RGB(0,255-value,255)

           Case 5
              couleur = RGB(value,0,255)

           Case 6
              couleur = RGB(255,value,255)
        EndSelect
        Box(x,y,2,2,couleur)
        x=x+2
        If x=64
          x=0
          y=y+2
        EndIf
     Next i
  Next mode
StopDrawing()  

;-Material
; convert it into a semi-transparent material 
CreateMaterial(0,TextureID(0))
MaterialBlendingMode(0,#PB_Material_Add) 


;-Entity 
; Create a bunch of platonic solids
colorConv.f =1024.00/numcube
Define numcolor.l,xt.l,yt.l,u.f,v.f
dotsize.f = 1.0/32.0
For i=0 To numcube-1

  numcolor = i*colorConv
  If numcolor < 32
    numcolor=32
  ElseIf numcolor > 1023
    numcolor=1023
  EndIf
  yt=numcolor/32
  xt=numcolor-(yt*32)
  u=(xt/32.00)
  v=(yt/32.00)
  
  myCubeMesh = CreatePlatonicMesh(#cube,1,1,1,u,v,dotsize,dotsize,$FFFFFF) 
  CreateEntity(i+1,MeshID(myCubeMesh),MaterialID(0))
  FreeMesh(myCubeMesh)

Next i

;-Skybox
; Add a nice space skybox
Add3DArchive("absdancesky.zip", #PB_3DArchive_Zip)
SkyBox("space.jpg")

;-Camera 
CreateCamera(0, 0, 0 , 100 , 100) 
MoveCamera(0,0,0,-40) 
CameraLookAt(0,0,0,0) 
xtarget=1:ytarget=-30:ztarget=-8
xcam.f=CameraX(0):ycam.f=CameraY(0):zcam.f=CameraZ(0)
xcamd.f=0:ycamd.f=0:zcamd.f=0
xcamdt.f=(xtarget-xcam)/500.00:ycamdt.f=(ytarget-ycam)/500.00:zcamdt.f=(ztarget-zcam)/500.00

;-Light 
; strong ambient light, for a flashy look
AmbientColor(RGB(200,200,200)) 

;- Variables
Define mode.l=0  ; forward or reverse motion
Define t.l=1,tmax.l=2000   ; used to store pos and rotations
Define vmax.l=100,vcur.l=100,v.f=1 ; motion speed modificator
Define speed.f=0.3,var1.f=1,var2.f=2.5,var3.f=2.5  ; speed and rotation values
Define xmean.f,ymean.f,zmean.f  ; Used to compute the center of the entity "swarm"

Define t.l=1,tmax.l=2000   ; used to store pos and rotations
Dim path.f(numcube,tmax+100,6) ; used to store pos and rotations 

Define oldtimer.l = ElapsedMilliseconds() ; Used to cap frame rate

;- Main loop
Repeat 
   If fullscreen = 0 
      While WindowEvent() : Wend 
   EndIf
   
   ; "Forward motion" mode
   If mode=0
      v=vcur/100.00
      For i=1 To numcube
         path(i,t,4)=wrapvalueF( path(i,t-1,4)+(var1*v) )
         path(i,t,5)=wrapvalueF( path(i,t-1,5)+(((i/100)-var2)*v) )
         path(i,t,6)=wrapvalueF( path(i,t-1,6)+(((i/100)-var3)*v) )
                  
         EulerAnglesToQuat(path(i,t,4) * 0.0174533,path(i,t,5) * 0.0174533,path(i,t,6) * 0.0174533 )
         QuaternionTransform(0,0,-speed*v)                 
                  
         MoveEntity( i,pResultVector\x,pResultVector\y,pResultVector\z )
         RotateEntity(i,path(i,t,5),path(i,t,4),path(i,t,6))
         
         path(i,t,1)=EntityX(i)
         path(i,t,2)=EntityY(i)
         path(i,t,3)=EntityZ(i)

         xmean+path(i,t,1)
         ymean+path(i,t,2)
         zmean+path(i,t,3)
      Next i

      ; After tmax loops, the motion slows down until it stops
      t+1
      If t = tmax
        vmax=-vmax
      EndIf
      If vmax>0 And vcur<vmax
        vcur+1
      EndIf
      If vmax<0 And vcur>vmax
        vcur-1
      EndIf
      ; when the motion is stopped, switch to "reverse motion" mode
      If vcur=0
        mode=1
        vcur=vmax
      EndIf
   Else
      ; "Reverse motion" mode => re-use stored positions and rotations
      t-1
      For i=1 To numcube
         EntityLocate( i,path(i,t,1),path(i,t,2),path(i,t,3) )
         RotateEntity( i,path(i,t,5),path(i,t,4),path(i,t,6) )
         xmean+path(i,t,1)
         ymean+path(i,t,2)
         zmean+path(i,t,3)
      Next i
      If t=1
         mode=0
         var1=-2 + (Random(40)/10.00)
         var2=-4 + (Random(80)/10.00)
         var3=-4 + (Random(80)/10.00)
      EndIf
   EndIf

    ; The camera constantly flies toward random destinations
   xcamd=curvevalue(xcamdt,xcamd,500.0)
   ycamd=curvevalue(ycamdt,ycamd,500.0)
   zcamd=curvevalue(zcamdt,zcamd,500.0)
   xcam+xcamd
   ycam+ycamd
   zcam+zcamd
   CameraLocate(0,xcam,ycam,zcam)
  
   ; Every 500 loops, the destination change
   campos+1
   If campos=500
      xtarget=EntityX(1)+25-Random(50)
      ytarget=EntityY(1)+25-Random(50)
      ztarget=EntityZ(1)+25-Random(50)
      xcamdt=(xtarget-xcam)/500.00
      ycamdt=(ytarget-ycam)/500.00
      zcamdt=(ztarget-zcam)/500.00
      campos=0
   EndIf
   
   ; But it always looks at the center of the entity "swarm"
   xmean/numcube
   ymean/numcube
   zmean/numcube
   CameraLookAt(0,xmean,ymean,zmean)
   
  ; show it all
  RenderWorld() 
  
  ; uncomment this to show FPS
  StartDrawing(ScreenOutput())
  DrawText(0,0,Str(Engine3DFrameRate(#PB_Engine3D_Average)) + " FPS / " + Str(CountRenderedTriangles()) + " triangles", $00FFFF, $BB0000)
  StopDrawing() 
  
  ; Flip buffers to avoid tearing  
  FlipBuffers()
  
  ; Cap Frame Rate at 30FPS max
;   timer = ElapsedMilliseconds()
;   If timer - oldtimer < 33
;     Delay(33 - (timer - oldtimer))
;   EndIf
;   oldtimer = timer
  
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) 

DataSection:
tetrahedron:
; Nb sommets / Nb faces
Data.l 10,4

; Vertices: pos / normals / uv
Data.f 0.817497,0.578350,0
Data.f 0,1,0
Data.f 0.5,0.5
Data.f -0.815497,0.578350,0
Data.f 0,1,0
Data.f 0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0,0.577351,0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0,0.577351,-0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0.816496,-0.577351,0
Data.f 0.5,1.5
Data.f 0.817497,0.578350,0
Data.f 0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,-0.815497
Data.f -0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f -0.815497,0.578350,0
Data.f -0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,0.817497
Data.f -0.816496,-0.577351,0
Data.f 0.5,1.5

; Faces
Data.l 0,1,2
Data.l 1,0,3
Data.l 4,6,5
Data.l 7,9,8

cube:
; Nb sommets / Nb faces
Data.l 24,12

; Vertices: pos / normals / uv
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,1
Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,1
Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,0
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,0
Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,0
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,0
Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,1
Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,1
Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,0
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,0
Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,1
Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,1
Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,0
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.f 0,0
Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.f 0,1
Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.f 1,0
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.f 1,1
Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.f 1,0

; Faces
Data.l 2,1,0
Data.l 0,3,2
Data.l 6,5,4
Data.l 4,7,6
Data.l 10,9,8
Data.l 8,11,10
Data.l 14,13,12
Data.l 12,15,14
Data.l 18,17,16
Data.l 16,19,18
Data.l 22,21,20
Data.l 20,23,22


octahedron:
; Nb sommets / Nb faces
Data.l 18,8

; Vertices: pos / normals / uv
Data.f 0,0.708107,0.708107
Data.f 0,1,0
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0,1,0
Data.f 0,1.5
Data.f 1.001000,0,0
Data.f 1,0,0
Data.f 0.5,1
Data.f 0,-0.706107,0.708107
Data.f 0,0,1
Data.f -0.5,1
Data.f -0.999000,0,0
Data.f -1,0,0
Data.f 0,1.5
Data.f 0,-0.706107,-0.706107
Data.f 0,0,-1
Data.f -0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,0.816496
Data.f 0,0.5
Data.f 0,0.708107,0.708107
Data.f 0.577350,0,0.816496
Data.f 0.5,1
Data.f 0,0.708107,0.708107
Data.f -0.577350,0,0.816496
Data.f 0.5,1
Data.f -0.999000,0,0
Data.f -0.577350,0.816496,0
Data.f -0.5,1
Data.f 0,0.708107,-0.706107
Data.f -0.577350,0,-0.816496
Data.f 0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,-0.816496
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0.577350,0,-0.816496
Data.f 0.5,1
Data.f 0,-0.706107,-0.706107
Data.f 0.577350,-0.816496,0
Data.f 0,1.5
Data.f 0,-0.706107,0.708107
Data.f 0.577350,-0.816496,0
Data.f 0,0.5
Data.f -0.999000,0,0
Data.f -0.577350,-0.816496,0
Data.f -0.5,1
Data.f 0,-0.706107,0.708107
Data.f -0.577350,-0.816496,0
Data.f 0,0.5
Data.f 0,-0.706107,-0.706107
Data.f -0.577350,-0.816496,0
Data.f 0,1.5

; Faces
Data.l 1,0,2
Data.l 6,7,3
Data.l 3,8,4
Data.l 9,0,1
Data.l 4,10,5
Data.l 5,12,11
Data.l 2,14,13
Data.l 15,17,16

dodecahedron:
; Nb sommets / Nb faces
Data.l 72,36

; Vertices: pos / normals / uv
Data.f 0.357822,0.935172,0
Data.f 0,0.955423,0.295242
Data.f 0.190983,1
Data.f -0.355822,0.935172,0
Data.f 0,0.955423,-0.295242
Data.f -0.190983,1
Data.f 0.578350,0.578350,0.578350
Data.f 0.688191,0.587785,0.425325
Data.f 0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0,0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f 0,0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f -0.309017,1.309020
Data.f 0,0.357822,-0.933172
Data.f 0,0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.935172,0,0.357822
Data.f 1,0,0
Data.f 0.190983,1
Data.f 0.935172,0,-0.355822
Data.f 1,0,0
Data.f -0.190983,1
Data.f 0,-0.355822,-0.933172
Data.f 0,0,-1
Data.f -0.190983,1
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f -0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,-0.576350
Data.f -0.425325,-0.688191,-0.587785
Data.f -0.309017,1.309020
Data.f -0.355822,-0.933172,0
Data.f 0,-0.992447,0.122673
Data.f -0.190983,1
Data.f 0,-0.355822,0.935172
Data.f 0,-0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.979432,-0.201774,0
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.992447,0.122673,0
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.357822,0.935172,0
Data.f 0.850651,0.525731,0
Data.f 0,0.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0,0.357822,-0.933172
Data.f 0.525731,0,-0.850651
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.935172,0,-0.355822
Data.f 0.525731,0,-0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0,-0.355822,-0.933172
Data.f 0,-0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,-0.525731
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,0.525731
Data.f 0.190983,1
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,0.578350
Data.f -0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.525731,0,0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.576350,-0.576350,0.578350
Data.f -0.525731,0,0.850651
Data.f -0.309017,1.309020
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.850651,0.525731,0
Data.f 0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.576350,0.578350,-0.576350
Data.f -0.525731,0,-0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,-0.355822,0.935172
Data.f 0.525731,0,0.850651
Data.f -0.190983,1

; Faces
Data.l 0,3,2
Data.l 0,4,3
Data.l 0,1,4
Data.l 1,6,5
Data.l 1,7,6
Data.l 1,0,7
Data.l 20,8,9
Data.l 21,2,8
Data.l 22,23,2
Data.l 24,10,25
Data.l 26,11,10
Data.l 27,28,11
Data.l 29,12,13
Data.l 30,8,12
Data.l 31,9,8
Data.l 32,14,33
Data.l 34,15,14
Data.l 35,36,15
Data.l 15,16,17
Data.l 15,37,16
Data.l 15,39,38
Data.l 40,18,14
Data.l 41,19,18
Data.l 42,43,19
Data.l 44,46,45
Data.l 47,49,48
Data.l 50,52,51
Data.l 19,53,18
Data.l 19,55,54
Data.l 19,57,56
Data.l 58,10,14
Data.l 59,60,10
Data.l 61,63,62
Data.l 64,65,2
Data.l 66,68,67
Data.l 69,71,70

icosahedron:
; Nb sommets / Nb faces
Data.l 42,20

; Vertices: pos / normals / uv
Data.f 0,0.851651,0.526731
Data.f 0,1,0
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0,1,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.356822,0.934172,0
Data.f 0.5,1
Data.f 0.526731,0,0.851651
Data.f 0.810146,0,0.586227
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f 0,0,1
Data.f 0,1.309020
Data.f -0.849651,0.526731,0
Data.f -0.934172,0.356822,0
Data.f 0,0.690983
Data.f -0.524731,0,-0.849651
Data.f -0.810146,0,-0.586227
Data.f -0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0,0,-1
Data.f 0,0.690983
Data.f 0.851651,-0.524731,0
Data.f 0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0,-0.356822,-0.934172
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f 0,-0.707107,0.707107
Data.f 0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,0.577350
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f 0.526731,0,0.851651
Data.f 0,0.356822,0.934172
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0,0.356822,0.934172
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.577350,0.577350,0.577350
Data.f 0.5,1
Data.f 0,0.851651,0.526731
Data.f -0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f -0.849651,0.526731,0
Data.f -0.356822,0.934172,0
Data.f -0.5,1
Data.f 0,0.851651,-0.524731
Data.f -0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f -0.524731,0,-0.849651
Data.f 0,0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,0.851651,-0.524731
Data.f 0,0.356822,-0.934172
Data.f 0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0.577350,0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,-0.577350
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,0.356822
Data.f 0,0.690983
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,-0.356822
Data.f 0,0.690983
Data.f 0.526731,0,-0.849651
Data.f 0.934172,0,-0.356822
Data.f -0.5,1
Data.f -0.524731,0,-0.849651
Data.f 0,-0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f 0.526731,0,-0.849651
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,-0.524731,0
Data.f 0.356822,-0.934172,0
Data.f 0.5,1
Data.f 0,-0.849651,-0.524731
Data.f 0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.356822,-0.934172,0
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f -0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0,-0.356822,0.934172
Data.f -0.5,1
Data.f 0.526731,0,0.851651
Data.f 0,-0.356822,0.934172
Data.f 0,0.690983
Data.f -0.524731,0,0.851651
Data.f -0.577350,-0.577350,0.577350
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.934172,0,0.356822
Data.f 0.5,1

; Faces
Data.l 1,0,2
Data.l 12,13,3
Data.l 14,15,4
Data.l 16,17,5
Data.l 18,0,1
Data.l 5,19,6
Data.l 20,21,7
Data.l 22,24,23
Data.l 25,3,8
Data.l 26,8,27
Data.l 28,7,9
Data.l 29,30,8
Data.l 8,3,10
Data.l 31,33,32
Data.l 6,34,11
Data.l 35,37,36
Data.l 38,39,4
Data.l 10,40,11
Data.l 6,11,5
Data.l 5,11,41

EndDataSection
NB: ce programme utilise la skybox ci-dessous; téléchargez-la et placez la dans le même répertoire que le code.
http://keleb.free.fr/absdancesky.zip

P.S.: j'ai aussi une version du même truc qui utilise DreamMotion 3D. Et là, c'est le cauchemar: même avec 512 cubes, je plafonne à 12 FPS! 3 fois moins qu'avec PB "pur"! 8O
Je n'y comprends plus rien...

Publié : mer. 19/mars/2008 17:16
par Chris
Ça tourne à 60 FPS chez moi en plein écran comme en fenêtré.

On sait pas ce que ça représente, ... mais c'est joli.

Publié : mer. 19/mars/2008 17:57
par Anonyme
Debugger actif ?

Publié : mer. 19/mars/2008 18:10
par Anonyme
tu peut largement optimisé le code.
Déjà , en virant tous les tableaux

Voici un p'tit snippet te montrant grossièrement la différence.
Faut pas croire, la moindre optimisation peut rendre un code extrement rapide :D

Code : Tout sélectionner

MAX = 1000000

Dim T3.l(99,99,99) ; Tableau de 100x100x100 éléments soit 1000000 élements

*Buffer = AllocateMemory(MAX*4)





TimerA = ElapsedMilliseconds()
For IT = 1 To 100
  For x = 0 To 99
    For y = 0 To 99
      For z = 0 To 99
        T3(x,y,z) = Random(2147483647)
        A = T3(x,y,z)
      Next
    Next
  Next 
Next 

TimerB = ElapsedMilliseconds()
TimerAB = TimerB-TimerA




TimerC = ElapsedMilliseconds()
  For IT = 1 To 100
    For i = 0 To MAX
      PokeL(*Buffer+(i*4),Random(2147483647))
      A = PeekL(*Buffer+(i*4))
    Next 
  Next 
  TimerD = ElapsedMilliseconds()
TimerCD = TimerD-TimerC



MessageRequester("...","Tableaux = "+Str(TimerAB)+"ms , Pointeurs = "+Str(TimerCD)+"ms")

Publié : mer. 19/mars/2008 18:21
par Chris
Cpl.Bator a écrit :Debugger actif ?
Non, sans debugger!

Tester le framerate avec le debugger n'a pas une grande utilité, à mon avis.

Publié : mer. 19/mars/2008 19:59
par Anonyme
c'était pas pour toi la question :mrgreen:
j'me doute bien que ta pas mis le debugger :D

Publié : mer. 19/mars/2008 20:04
par Chris
Cpl.Bator a écrit :c'était pas pour toi la question :mrgreen:
j'me doute bien que ta pas mis le debugger :D
Ah!!
Ooops :oops: :mrgreen:

Publié : mer. 19/mars/2008 22:15
par Huitbit
Très joli fond d'écran (Abstract dance) !
Je suis pas trop 3D mais là...
Chapeau!

Pour le code donné :
30 fps avec mon HP en carton (euh pavilion) et sa carte ATI radeon Xpress 200 !

Hasta la vista !

Publié : jeu. 20/mars/2008 10:54
par kelebrindae
@HuiTbit et Chris:
Merci des compliments!

@Cpl_Bator:
Oui, debugger actif. Mais j'avais déjà essayé sans debugger sans constater de différence énorme (3-4 FPS maxi)...
Et oui, je suis d'accord, tout cela peut être grandement optimisé; c'est du portage brut de fonderie. A ce propos, merci pour le snippet: c'est très parlant! :)

Et j'ai enfin pris le temps de tester la version Dreammotion sur mon portable (doté d'une carte 3D à peu près potable), et là ça tourne à fond (60 FPS, soit la fréquence de rafraîchissement de l'écran) jusqu'à plus de 5000 cubes. Cool! :P

Je fais un petit résumé de la situation pour clarifier:
___________________________________________________________
____________|_Bonne carte 3D + Vista__|___Carte 3D pourrie + XP____|
PB pur ______ |__________ :( ________|_________ :) _____________|
DreamMotion _ |__________ :) ________|_________ :( _____________|

=> Comment PB gère-t-il la 3D en natif (= Ogre?): Il utilise Direct3D? OpenGL? Software?
Parce que s'il utilise OpenGL, je pourrais imputer les mauvais résultats sous Vista à la gestion pourrie d'OpenGL par ce dernier (OpenGL étant le grand concurrent de DirectX, Microsoft l'a volontairement défavorisé dans Vista en en faisant une simple surcouche de DirectX -> lent).

Qu'en pensez-vous ?

Publié : jeu. 20/mars/2008 11:15
par Anonyme
Bizare que tu n'ai pas de différence significative.

Dreamotion3D devrait être plus rapide si tu met en place un octree en place, je te laisse regarder les exemples.

Purebasic utilise Ogre , du moins en petite partie...
j'ai voulu m'atteler à un wrapping du moteur , mais c'est une usine à gaz...
Pour OpenGL sous vista , c'est possible , j'en ai entendu parler aussi , mais a priori cela à changer , il paraîtrai même qu'opengl soit plus rapide que direct 3D , un comble sous vista...

http://www.presence-pc.com/actualite/vi ... ngl-18718/

Publié : ven. 21/mars/2008 14:19
par kelebrindae
Bizare que tu n'ai pas de différence significative.
Peut-être que c'est la partie 3D qui rame (juste l'affichage), et que cette partie n'est pas gérée/tracée par PB ?
Purebasic utilise Ogre
Oui, mais comme Ogre peut utiliser soit Direct3D, soit OpenGL, on n'en sait pas plus...
J'aurais tendance à dire que l'Ogre wrappé par PB utilise OpenGL, car avec mon PC Vista, j'ai noté des ralentissements comparables dans les tutoriaux OpenGL de Nehe traduits par Flype (ici: http://www.purebasic.fr/french/viewtopi ... light=nehe).
Et puis comme PB tourne aussi sous Linux, il est probable que ses auteurs n'aient pas développé deux wrappings différents (pour peu que ce ne soit pas Ogre qui choisisse lui-même quelle API utiliser).
Mais bon, là, c'est de la pure spéculation (Tiens, ça ferait un bon nom pour une appli boursière développée en PB, ça... :wink: )
Pour OpenGL sous vista , c'est possible , j'en ai entendu parler aussi , mais a priori cela a changé
Oui et non: le groupe qui gère OpenGL a un peu forcé la main des constructeurs de GPU (Nvidia et ATI) pour qu'ils sortent des drivers Vista complémentaires spécifiques OpenGL, au format ICD (Installable Client Driver). Mais je ne sais pas s'ils sont maintenant inclus dans les drivers des cartes graphiques, et je n'ai pas réussi à en trouver trace sur le site de Nvidia... :?

[EDIT]
Trouvé sur le site OpenGL.org:
OpenGL hardware acceleration is handled in exactly the same way in Windows XP and Windows Vista - through an Installable Client Driver (ICD) provided by graphics card manufacturers. Without an OpenGL ICD installed, Windows XP and Windows Vista both revert to rendering OpenGL in software on the CPU rather than using GPU acceleration.
ça pourrait expliquer pourquoi ça se traîne tant avec mon Vista => il fait tout en "software render" !

Si quelqu'un sait où en est cette histoire, ou bien où trouver ces drivers ICD, je suis preneur ![/b]

Publié : ven. 21/mars/2008 16:11
par Anonyme
J'aurais tendance à dire que l'Ogre wrappé par PB utilise OpenGL, car avec mon PC Vista
C'est tout simplement pas possible, tu ne pourrais pas utilisé les sprites en même temps. c'est du directx tout court.
Pour linux c'est du opengl , juste une constante à changer lors de l'init de l'ogre ( au niveau du wrapping je parle ) c'est opaque pour l'utilisateur.
il fait tout en "software render" !
Non , et heureusement , en fait sous vista , Opengl est interpréter de facon a avoir un équivalent à directx , mais cette interprétation est mal faite volontairement.
les drivers icd quand à eux permettent justement de passé outre cette interprétation.