Page 1 sur 2

Problème Zbuffer Software

Publié : lun. 11/déc./2006 15:52
par Anonyme
Voila, j'ai un p'tit soucis qui me prend la tête
Je recode un peu mon moteur 3D software , et j'utilise un Zbuffer pour éliminer les faces cachées, je rempli mes faces avec une fonction de remplissage de triangles ( code plus bas )
cette fonction n'est pas de moi, je l'ai adapté d'un code en C ou pris a quelqu'un ici, je sais plus , bref, c'est pas important, mais j'ai du mal à calculer la profondeur Z du pixel en X,Y, je passe en paramètres les coordonnées 2D des vertices du triangle à afficher, j'ai essayer de rajouté 3 paramètres pour chaque Z des vertices qui compose le triangle , mais je m'en sors pas, j'arrive pas à calculer correctement le pas incrémental pour le Z. Si quelqu'un de moins fatigué que moi peu m'aider c'est sympa :D

Image

Logiquement le beret arrive presque jusqu'au yeux, on ne devrait pas voir mon crâne...


Code : Tout sélectionner

Procedure Triangle(ax1.f,ay1.f,ax2.f,ay2.f,ax3.f,ay3.f,Color) 
  
  If ax1 =< ax2 And ax1 =< ax3 
    x1 = ax1 
    y1 = ay1 
    If ax2 =< ax3 
      x2 = ax2 : y2 = ay2 
      x3 = ax3 : y3 = ay3 
    Else 
      x2 = ax3 : y2 = ay3 
      x3 = ax2 : y3 = ay2 
    EndIf 
  EndIf  
  
  If ax2 =< ax1 And ax2 =< ax3 
    x1 = ax2 
    y1 = ay2 
    If ax1 =< ax3 
      x2 = ax1 : y2 = ay1 
      x3 = ax3 : y3 = ay3 
    Else      
      x2 = ax3 : y2 = ay3 
      x3 = ax1 : y3 = ay1 
    EndIf    
  EndIf 
  
  If ax3 =< ax1 And ax3 =< ax2 
    x1 = ax3 
    y1 = ay3 
    If ax2 =< ax1 
      x2 = ax2 : y2 = ay2 
      x3 = ax1 : y3 = ay1 
    Else      
      x2 = ax1 : y2 = ay1 
      x3 = ax2 : y3 = ay2 
    EndIf    
  EndIf 
  
  
  xdepart.f = x1 
  ydepart.f = y1 
  yfin.f    = y1 
  
  Coeff_A.f = ( y2-y1 ) / (x2-x1 ) 
  Coeff_B.f = ( y3-y1 ) / (x3-x1 ) 
  
  
  
  If x2 < x3    
    Pt_Ct = x2 : fin = x3 : fin2 = y3 
    Coeff_C.f = -1*( y3-y2 ) / (x3-x2 )  
    Coeff_D.f = -1*Coeff_B.f 
  Else  
    Pt_Ct = x3 : fin = x2 : fin2 = y2 
    Coeff_C.f = -1*( y2-y3 ) / (x2-x3 ) 
    Coeff_D.f = -1*Coeff_A.f 
  EndIf 
  
  
  
  If Coeff_A.f < Coeff_B.f 
    Coeff_Down.f = Coeff_A.f 
    Coeff_Up.f   = Coeff_B.f 
  Else 
    Coeff_Down.f = Coeff_B.f 
    Coeff_Up.f   = Coeff_A.f 
  EndIf 
  
  For x = xdepart.f To Pt_Ct Step 1 
    y = ydepart.f 
    Repeat 
      y = y+1 
      
      
      If x>0 And x<1024-1 And y>0 And y<768-1
        Plot( x,y,Color ) 
        
          EndIf
    Until y >= yfin.f 
    
    ydepart.f = ydepart.f+Coeff_Down.f 
    yfin.f    = yfin.f+Coeff_Up.f 
    
    
  Next x 
  
  
  ;********************************************************************* 
  
  If Coeff_C.f < Coeff_D.f 
    Coeff_Down.f = Coeff_C.f 
    Coeff_Up.f   = Coeff_D.f 
  Else 
    Coeff_Down.f = Coeff_D.f 
    Coeff_Up.f   = Coeff_C.f 
  EndIf  
  
  ydepart.f = fin2 
  yfin.f    = fin2 
  
  
  For x = fin To Pt_Ct Step -1 
    y = ydepart.f 
    Repeat 
      y = y+1  
       
      If x>0 And x<1024-1 And y>0 And y<768-1
        Plot( x,y,Color) 
      
         EndIf
    Until y >= yfin.f 
    ydepart.f = ydepart.f+Coeff_Down.f 
    yfin.f    = yfin.f+Coeff_Up.f 
  Next x 
  
  
  
  
EndProcedure 

Publié : lun. 11/déc./2006 19:42
par tonton
manque la partie interpolation

le pas pour la deuxieme partie du programme est : (z(arrivé)-z(depart))/(y(arrivé)-y(depart))

le pas pour la partie "scanline" est (z(arrivé)-z(depart))/(x(arrivé)-x(depart))

Publié : lun. 11/déc./2006 19:58
par Anonyme
Merci tonton, je vais voir pour modifié mon code.

Publié : mer. 13/déc./2006 11:05
par Anonyme
j'y arrive Vraiment pas, y a des jours ou il ne vaudrais mieux pas programmé :cry:
Tu n'a pas une fonctions déjà faites ? :D

Publié : mer. 13/déc./2006 17:02
par tonton
yo, bator

j ai ajouté le zbufer sur ton listing polygone plus haut
y a encore un petit bug que je te laisse trouver lol.

voila un exemple avec 2 triangle

Code : Tout sélectionner

  InitSprite() 
   InitKeyboard() 
   InitMouse() 
   OpenScreen(1024,768, 32, "") 
 deb: 
 
   Gosub clear_zbuffer 

     
   StartDrawing(ScreenOutput()) 
   
   ax1.f=200
   ay1.f=100
   az1.f=50
   
   ax2.f=700
   ay2.f=350
   az2.f=50
   
   ax3.f=230
   ay3.f=410
   az3.f=50
   
   color= $0000ff
   Gosub poly
   
   ExamineMouse()
   xx=MouseX()
   yy=MouseY()
   
   ax1.f=xx+5
   ay1.f=yy+5
   az1.f=10
   
   ax2.f=xx+550
   ay2.f=yy+270
   az2.f=110
   
   ax3.f=xx+230
   ay3.f=yy+410
   az3.f=110
   
   color=$00ff00
   
   Gosub poly
   
   StopDrawing()
 
    FlipBuffers()  
      ClearScreen(RGB(0,0,0)) 
     
   ExamineKeyboard() 
   If KeyboardPushed(#PB_Key_Escape) 
   End 
   EndIf 

   
  Goto  deb
   
poly: 

 
  If ax1 =< ax2 And ax1 =< ax3 
    x1 = ax1 
    y1 = ay1 
    z1 = az1 
    If ax2 =< ax3 
      x2 = ax2 : y2 = ay2 : z2 = az2
      x3 = ax3 : y3 = ay3 : z3 = az3
    Else 
      x2 = ax3 : y2 = ay3 : z2 = az3
      x3 = ax2 : y3 = ay2 : z3 = az2
    EndIf 
  EndIf  
  
  If ax2 =< ax1 And ax2 =< ax3 
    x1 = ax2 
    y1 = ay2 
    z1 = az2 
    If ax1 =< ax3 
      x2 = ax1 : y2 = ay1 : z2 = az1
      x3 = ax3 : y3 = ay3 : z3 = az3
    Else      
      x2 = ax3 : y2 = ay3 : z2 = az3
      x3 = ax1 : y3 = ay1 : z3 = az1
    EndIf    
  EndIf 
  
  If ax3 =< ax1 And ax3 =< ax2 
    x1 = ax3 
    y1 = ay3 
    z1 = az3 
    If ax2 =< ax1 
      x2 = ax2 : y2 = ay2 : z2 = az2
      x3 = ax1 : y3 = ay1 : z3 = az1
    Else      
      x2 = ax1 : y2 = ay1 : z2 = az1
      x3 = ax2 : y3 = ay2 : z3 = az2
    EndIf    
  EndIf 
  
  
  xdepart.f = x1 
  ydepart.f = y1 
  
  zdepart.f = z1;ajout
  
  yfin.f    = y1 
  
  Coeff_A.f = ( y2-y1 ) / (x2-x1 ) 
  Coeff_B.f = ( y3-y1 ) / (x3-x1 ) 
  
  Coeff_Z.f = ( z2-z1 ) / (y2-y1 );ajout
  Coeff_Z1.f = ( z3-z1 ) / (x3-x1 );ajout
  
  
  If x2 < x3    
    Pt_Ct = x2 : fin = x3 : fin2 = y3 
    
    
    Coeff_C.f = -1*( y3-y2 ) / (x3-x2 )  
    Coeff_D.f = -1*Coeff_B.f 
    
  Else  
  
    Pt_Ct = x3 : fin = x2 : fin2 = y2 
    Coeff_C.f = -1*( y2-y3 ) / (x2-x3 ) 
    Coeff_D.f = -1*Coeff_A.f 
    
  EndIf 
  
  
  
  If Coeff_A.f < Coeff_B.f 
    Coeff_Down.f = Coeff_A.f 
    Coeff_Up.f   = Coeff_B.f 
    
     Coeffz_Down.f = Coeff_Z.f
    Coeffz_Up.f   = Coeff_Z1.f
    
  Else 
    Coeff_Down.f = Coeff_B.f 
    Coeff_Up.f   = Coeff_A.f 
    
     Coeffz_Down.f = Coeff_Z.f
    Coeffz_Up.f   = Coeff_Z1.f
  EndIf 
  
  
  
        
  
  For x = xdepart.f To Pt_Ct Step 1 
    y = ydepart.f 
    zdepart1.f=zdepart.f
 Repeat 
      y = y+1 
      zdepart1.f= zdepart1.f+ Coeffz_Down.f 
      
      If x>0 And x<1024-1 And y>0 And y<768-1 
      
       af = 0
      
     z = zdepart1.f
    Gosub  zbuff 
      
      
        If af=1 
        Plot( x,y,Color) 
        EndIf
        
          EndIf 
  Until y >= yfin.f 

    
    ydepart.f = ydepart.f+Coeff_Down.f 
    yfin.f    = yfin.f+Coeff_Up.f 
    
     zdepart.f = zdepart.f+Coeffz_Up.f 
    
  Next x 
 ; Return
  
  ;********************************************************************* 
  
  If Coeff_C.f < Coeff_D.f 
    Coeff_Down.f = Coeff_C.f 
    Coeff_Up.f   = Coeff_D.f 
  Else 
    Coeff_Down.f = Coeff_D.f 
    Coeff_Up.f   = Coeff_C.f 
  EndIf  
  
  ydepart.f = fin2 
  yfin.f    = fin2 
    z = zdepart.f
  
  For x = fin To Pt_Ct Step -1 
    y = ydepart.f 
      zdepart.f= zdepart.f+ Coeff_z1.f
    Repeat 
      y = y+1  
        
      If x>0 And x<1024-1 And y>0 And y<768-1 

       af = 0
       z = zdepart.f
       Gosub  zbuff  
      
      
        If af=1 
        Plot( x,y,Color) 
        EndIf
      
         EndIf 
    Until y >= yfin.f 
    ydepart.f = ydepart.f+Coeff_Down.f 
    yfin.f    = yfin.f+Coeff_Up.f 
     zdepart.f = zdepart.f+Coeff_z
  Next x 
  
  Return
  
  
  clear_zbuffer:    
   !eraz_zbuffer:
   !push  esi
   !push  ecx
   !lea   esi,[zbuffer]
   !mov   ecx,786432
   !eraz:
   !mov   dword[esi],-100000
   !add   esi,4
   !loop  eraz
   !pop   ecx
   !pop   esi
   Return
  
 zbuff: 
  ; ***** asm *****
   !pushad
   !mov    eax,[v_x]
   !sal    eax,2
   !mov    ebx,[v_y]
   !imul   ebx,4096
   !add    eax,ebx
   !lea    esi,[zbuffer]
   !mov    ebx,dword[v_z]
   !mov    ecx,[esi+eax]
   !cmp    ecx,ebx
   !jnle     affi1
   !mov    dword[v_af],1
   !mov    [esi+eax],ebx
   !affi1:  
   !popad
      ;***************
Return

   !section '.data' align 16
   !zbuffer:
   !rd 786432

Publié : mer. 13/déc./2006 17:17
par tonton
bon j ai trouvé, le bug mais je te laisse le trouver quant meme, je vais pas tout faire non plus :lol:

pour rappel sur un autre post, un objet a geometrie variable est un objet qui change de forme.tout les hommes digne de ce nom, en possede un.
c est lna qui va etre jalouse 8)

papaillouuu!.. papaillouuuu!.. papaillou papailloup lé lé.....

Publié : mer. 13/déc./2006 17:18
par Anonyme
tu es un killer :D
sinon je suis assez deçu de ne pas comprendre l'asm :cry:
car pour mené un p'tit moteur à bien y a pas le choix.
j'ai lu quelque part ici que l'asm génerer par Purebasic n'était pas optimisé, est ce Vrai ? si c'est le cas , je vais me collé à l'asm :D

Publié : mer. 13/déc./2006 17:29
par Anonyme
le bug c'est lorsque l'on modifie le Z du plan rouge (az1 par exemple) le clipping est incorrect, pour le corrigé c'est autre chose :?

@++ :D

Publié : mer. 13/déc./2006 19:00
par tonton
vi, j ai oublier de corriger la derniere partie du programme.
je suis sur un autre projet en ce moment, je te corrigerais ca tantot.

a++++

Publié : mer. 13/déc./2006 21:56
par djes
Cpl.Bator a écrit :tu es un killer :D
sinon je suis assez deçu de ne pas comprendre l'asm :cry:
car pour mené un p'tit moteur à bien y a pas le choix.
j'ai lu quelque part ici que l'asm génerer par Purebasic n'était pas optimisé, est ce Vrai ? si c'est le cas , je vais me collé à l'asm :D
Si tu veux un (petit) coup de main en assembleur, je suis là aussi, n'hésite pas :)
Je trouve qu'il manque un petit tuto simple pour les nuls, avant sph en avait fait un, mais il l'a effacé. En pure, l'initiation à l'assembleur est vraiment idéale je trouve!
Un truc qui dirait vite fait comment on fait une opération sur une variable, pourquoi on utilise les registres, ptet une boucle, et qui embraye sur une petite optim qui montre les capacités de l'assembleur...

Publié : mer. 13/déc./2006 23:37
par Backup
djes a écrit :Je trouve qu'il manque un petit tuto simple pour les nuls,

Un truc qui dirait vite fait comment on fait une opération sur une variable, pourquoi on utilise les registres, ptet une boucle, et qui embraye sur une petite optim qui montre les capacités de l'assembleur...
les tutos de Denis sont quand meme bien fait :D

Publié : jeu. 14/déc./2006 0:31
par Anonyme
Il sont bien fait certes, mais pas facile à comprendre, tu sais, je suis un idiot, je comprends rien "normalement" il faut me faire un dessin, j'ai un parcours scolaire lamentable, et aujourd'hui j'écris un moteur3D... , mon prof de math doit se retourné dans sa tombe... :D

@Djes, merci de ton aide ^^ je mettrais les sources sur un autre SVN, tu pourras tout refaire en asm :D :D
j'rigole :D , mais un coup de paluche n'est pas refus pour l'asm. :wink:

Publié : jeu. 14/déc./2006 13:45
par tonton
voici, une routine asm compatible avec ton moteur avec zbuffer.
tu peux facilement l integrer
j ai garder le" plot ":D


Code : Tout sélectionner

   InitSprite() 
   InitKeyboard() 
   InitMouse() 
   OpenScreen(1024,768, 32, "") 
 deb: 
 
   Gosub clear_zbuffer 

     
   StartDrawing(ScreenOutput()) 
   
   ax1.f=600
   ay1.f=200
   az1.f=20
   
   ax2.f=800
   ay2.f=420
   az2.f=20
   
   ax3.f=410
   ay3.f=330
   az3.f=20
   
   color= $0000ff
   Gosub poly_asm
   
   ExamineMouse()
   xx=MouseX()
   yy=MouseY()
   
   ax1.f=xx
   ay1.f=yy
   az1.f=10
   
   ax2.f=xx+300
   ay2.f=yy+150
   az2.f=30
   
   ax3.f=xx-340
   ay3.f=yy+253
   az3.f=30
   
   color=$00ff00
   
   Gosub poly_asm
   
  StopDrawing()
 
    FlipBuffers()  
      ClearScreen(RGB(0,0,0)) 
     
   ExamineKeyboard() 
   If KeyboardPushed(#PB_Key_Escape) 
   End 
   EndIf 

   
  Goto  deb
   
     
 poly_asm:     
  !zone_lam:  ;--  trie "y" par ordre croissant --------------------
     x=0
     y=0
     z=0
    !pushad 
    !lea      esi,[zbuffer]
    !mov      [madzbuffer],esi
    !cVTSS2SI eax,[v_ax1]
    !cVTSS2SI ebx,[v_ay1]  
    !cVTSS2SI ecx,[v_ax2]     
    !cVTSS2SI edx,[v_ay2]  
    !cVTSS2SI edi,[v_ax3]
    !cVTSS2SI esi,[v_ay3]  
    !MOVss    xmm0,[v_az1]
    !movss    xmm1,[v_az2]
    !movss    xmm2,[v_az3]
    
    
    !CMP      ebx,esi
    !Jnge     rien01_lam
    !XCHG     ebx,esi
    !XCHG     eax,edi 
    !movss    xmm3,xmm0
    !movss    xmm0,xmm2
    !movss    xmm2,xmm3
!rien01_lam:
    !CMP      ebx,edx
    !Jnge     rien02_lam
    !XCHG     ebx,edx
    !XCHG     eax,ecx
    !movss    xmm3,xmm0
    !movss    xmm0,xmm1
    !movss    xmm1,xmm3
!rien02_lam:     
    !CMP      edx,esi
    !Jnge     rien03_lam
    !XCHG     edx,esi
    !XCHG     ecx,edi
    !movss    xmm3,xmm1
    !movss    xmm1,xmm2
    !movss    xmm2,xmm3
!rien03_lam:  
    !MOV      [fillx1],eax
    !MOV      [filly1],ebx 
    !MOV      [fillx2],ecx    
    !MOV      [filly2],edx  
    !MOV      [fillx3],edi
    !MOV      [filly3],esi 
    !MOVss    [fillz1],xmm0
    !MOVss    [fillz2],xmm1
    !MOVss    [fillz3],xmm2
 
!affizone_lam:    ;-- determine different cas de polygones ----------- 
    !SUB      esi,ebx
    !INC      esi
    !MOV      [linn],esi 
    !LEA      ebx,[memzone] 
    !CMP      ecx,edi
    !JGE      form1_lam  
    !CMP      eax,ecx
    !JNGE     depass01ac_lam  
    !CMP      eax,edi
    !JG       depass01c_lam
    !MOV      edx,[fillx1] 
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !JMP      rempli_lam
!depass01c_lam:  
    !MOV      edx,[fillx1] 
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3]
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !JMP      rempli_lam
!depass01ac_lam: 
    !MOV      edx,0
    !MOV      eax,[fillx3]
    !SUB      eax,[fillx1]
    !MOV      edi,[filly3]
    !SUB      edi,[filly1]
    !JE       sanscond01ac_lam
    !SAL      eax,16
    !DIV      edi
    !MOV      esi,eax
    !MOV      edx,0
    !MOV      eax,[fillx3]
    !SUB      eax,[fillx2]
    !MOV      edi,[filly3]
    !SUB      edi,[filly2]
    !JE       sanscond01ac_lam
    !SAL      eax,16
    !DIV      edi
    !MOV      edi,eax
    !CMP      esi,edi
    !JGE      depass01bc_lam
!sanscond01ac_lam:
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !MOV      eax,[ebx]
    !MOV      [sauvad],ebx
    !MOV      [sauvpt],eax
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3]   
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam ;
    !MOV      edx,[sauvad]
    !MOV      eax,[sauvpt]
    !MOV      [edx],eax
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !JMP      rempli_lam
!depass01bc_lam:
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !JMP      rempli_lam
!form1_lam:  
    !CMP      eax,ecx
    !JG       depass01_lam  
    !CMP      eax,edi
    !JNG      depass01a_lam  
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !JMP      rempli_lam
!depass01_lam: 
    !MOV      edx,0
    !MOV      eax,[fillx1]
    !SUB      eax,[fillx3]
    !MOV      edi,[filly3]
    !SUB      edi,[filly1]
    !JE       sanscond01a_lam
    !SAL      eax,16
    !DIV      edi
    !MOV      esi,eax
    !MOV      edx,0
    !MOV      eax,[fillx2]
    !SUB      eax,[fillx3]
    !MOV      edi,[filly3]
    !SUB      edi,[filly2]
    !JE       sanscond01a_lam
    !SAL      eax,16
    !DIV      edi
    !MOV      edi,eax
    !CMP      esi,edi
    !JGE      depass01b_lam
!sanscond01a_lam: 
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,0           
    !CALL     tracage_lam 
    !MOV      eax,[ebx]
    !MOV      [sauvad],ebx
    !MOV      [sauvpt],eax
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !MOV      edx,[sauvad]
    !MOV      eax,[sauvpt]
    !MOV      [edx],eax
    !JMP      rempli_lam
!depass01a_lam: 
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !JMP      rempli_lam
!depass01b_lam:
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx2] 
    !MOV      esi,[filly2] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz2]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !MOV      edx,[fillx2]
    !MOV      edi,[filly2] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !movss    xmm0,[fillz2]
    !movss    xmm1,[fillz3]
    !MOV      ecx,1
    !CALL     tracage_lam 
    !ADD      ebx,16
    !MOV      edx,[fillx1]
    !MOV      edi,[filly1] 
    !MOV      ebp,[fillx3] 
    !MOV      esi,[filly3] 
    !MOVss    xmm0,[fillz1]
    !movss    xmm1,[fillz3]
    !MOV      ecx,0
    !CALL     tracage_lam 
    !JMP      rempli_lam 
!tracage_lam: ;-- mise en memoire des coordonees "x" , "x1" et "z","z1"----------------
    !SUBss     xmm1,xmm0 
    !mov       dword[pointx],1
    !mov       eax,edx
    !SUB       ebp,edx
    !JNS       positifx_lam
    !NEG       ebp
    !NEG       dword[pointx]
    
!positifx_lam: 
    !SUB       esi,edi
    !CMP       ebp,esi 
    !JNL       zone1_a_lam
    !XCHG      ebp,esi 
!zone2_lam: 
    !MOV       ecx,ebp 
    !MOV       edx,ebp
    !SAR       edx,1
    !INC       ecx
    !cVTSI2SS  xmm2,ecx
    !divss     xmm1,xmm2
!dezo2_lam: 
    !MOV       [ebx],eax
    !MOV       [ebx+4],edi
    !MOVss     [ebx+8],xmm0
    !ADDss     xmm0,xmm1
    !ADD       ebx,16 
    !ADD       edi,1;[largecr]
    !SUB       edx,esi 
    !JGE       depzo2_lam
    !ADD       eax,dword[pointx];eax 
    !ADD       edx,ebp 
!depzo2_lam: 
    !LOOP      dezo2_lam 
    !SUB       ebx,16
    !RET
!zone1_a_lam: 
    !CMP       ecx,[sens]
    !JE        zone1a_lam
!zone1_lam:    
    !MOV       ecx,ebp 
    !MOV       edx,ebp
    !SAR       edx,1
    !INC       ecx
    !cVTSI2SS  xmm2,ecx
    !divss     xmm1,xmm2
!dezo1_lam: 
    !ADDss     xmm0,xmm1
    !SUB       edx,esi 
    !JGE       depzo1_lam
    !MOV       [ebx],eax
    !MOV       [ebx+4],edi
    !MOVss     [ebx+8],xmm0
    !ADD       ebx,16   
    !ADD       edi,1;[largecr]
    !ADD       edx,ebp 
    !ADD       eax,dword[pointx];eax
    !LOOP      dezo1_lam 
    !SUB       eax,dword[pointx];eax
    !SUB       edi,1;[largecr]
    !SUB       ebx,16
    !RET
!depzo1_lam: 
    !ADD       eax,dword[pointx];eax
    !LOOP      dezo1_lam 
    !SUB       eax,dword[pointx];eax
    !MOV       [ebx],eax
    !MOV       [ebx+4],edi
    !MOVss     [ebx+8],xmm0
    !RET
!zone1a_lam: 
    !MOV       ecx,ebp 
    !MOV       edx,ebp
    !SAR       edx,1
    !INC       ecx
    !cVTSI2SS  xmm2,ecx
    !divss     xmm1,xmm2
    !MOV       [ebx],eax
    !MOV       [ebx+4],edi
    !MOVss     [ebx+8],xmm0
    !ADD       ebx,16 
!dezo1a_lam: 
    !ADDss     xmm0,xmm1
    !ADD       eax,dword[pointx];eax
    !SUB       edx,esi 
    !JGE       depzo1a_lam
    !ADD       edi,1;[largecr] 
    !MOV       [ebx],eax
    !MOV       [ebx+4],edi
    !MOVss     [ebx+8],xmm0
    !ADD       ebx,16 
    !ADD       edx,ebp 
    !LOOP      dezo1a_lam
    !SUB       ebx,32
    !RET
!depzo1a_lam: 
    !LOOP      dezo1a_lam 
    !SUB       ebx,16
    !RET
!rempli_lam: ;-- remplissage de la zone --------------------

    !LEA       ebx,[memzone] 
    !MOV       ebp,[linn] 
    !MOV       [deczon],ebp
    !SAL       ebp,4
!rempli2_lam: 
    !MOV       ecx,[ebx+ebp] 
    !MOV       edi,[ebx] 
    !cmp       ecx,[largecr]
    !jnge      depecr
    !mov       ecx,[largecr]
!depecr:
    !cmp       edi,0
    !jnle      depecr1
    !mov       edi,0
!depecr1:
    !MOV       eax,[ebx+4]     
    !SUB       ecx,edi 
    !Jnge      rempli2a_lam
    !MOVss     xmm0,[ebx+8] 
    !MOVss     xmm1,[ebx+ebp+8]
    !subss     xmm1,xmm0 
    !INC       ecx 
    !cVTSI2SS  xmm2,ecx
    !DIVss     xmm1,xmm2
    
!rempzo_lam: 
    !cmp       eax,[hautecr]
    !jnge      depecr2
    !mov       eax,[hautecr]
    !jmp       paspoint_lam
!depecr2:
    !cmp       eax,0
    !jnle      depecr3
    !mov       eax,0
     !jmp       paspoint_lam
!depecr3:
    !cmp       edi,[largecr]
    !jnge      depecr4
    !mov       edi,[largecr]
     !jmp       paspoint_lam
!depecr4:
    !cmp       edi,0
    !jnle      depecr5
    !mov       edi,0
     !jmp       paspoint_lam
!depecr5:
    !mov       dword[v_y],eax
    !mov       dword[v_x],edi  
    !push      edi
    !push      eax
    !sal       edi,2
    !imul      eax,4096
    !add       eax,edi
    !lea       esi,[zbuffer]
    !add       esi,eax
    !comiss    xmm0,[esi]
    !ja        affi1
    !movss     [esi],xmm0
    !pushad 
    Plot      (x,y,color)   ;*************  une ligne en basic, pour que ce soit plus claire *****************
    !popad
    !affi1: 
    !pop       eax
    !pop       edi

!paspoint_lam:
    !addss     xmm0,xmm1  
    !ADD       edi,1
    !dec       ecx
    !jne       rempzo_lam 
    !ADD       ebx,16 
    !DEC       dword[deczon]
    !Jnle      rempli2_lam 

!rempli2a_lam: 
    !popad
    Return    

  clear_zbuffer: ;-- cls zbuffer-----   
   !eraz_zbuffer:
   !push  esi
   !push  ecx
   !lea   esi,[zbuffer]
   !mov   ecx,786432
   !eraz:
   !mov   dword[esi],-100000
   !add   esi,4
   !loop  eraz
   !pop   ecx
   !pop   esi
   Return


   !section '.data' align 16
   !fillx1:
   !dd 0
   !filly1: 
   !dd 0
   !fillz1: 
   !dd 0
   !fillx2: 
   !dd 0
   !filly2:
   !dd 0
   !fillz2:
   !dd 0
   !fillx3:
   !dd 0
   !filly3:
   !dd 0
   !fillz3:
   !dd 0

   !largecr:
   !dd  1023
   !hautecr:
   !dd  767
   !linn:
   !dd  0
   !pointx:
   !dd  0
   !af:
   !dd   0
   !sauvad:
   !dd 0
   !sauvpt:
   !dd 0 
   !sens:
   !dd 0
   !madzbuffer:
   !dd 0
   !deczon:
   !dd 0
   !moins1:
   ! dd -1.0
   !memzone:
   !rd  40000
   
   !section '.data' align 16
   !zbuffer:
   !rd 786432

 

Publié : jeu. 14/déc./2006 14:49
par Anonyme
8O Tu me force à comprendre l'asm.
C'est ma femme qui va te tapé sur la gueulle :D
En tout cas merci de ton aide, ta réponse à tout en 3D :D
D'ailleurs , il est passé ou ton forum??
Djes , si tu peut m'aider à comprendre c'est le moment :D

@++

Publié : jeu. 14/déc./2006 17:25
par tonton
y a de quoi faire pour djes la!!! :lol:
j ai rééditer le code du dessus pour augmenter la precision du zbuffer.

mon forum est fermé car je ne fait plus de 3d, je programme maintenant un logiciel pour le turf..