Subversion Repositories Kolibri OS

Rev

Rev 8047 | Rev 9237 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8047 Rev 8666
Line 1... Line 1...
1
; Real Phong's shading implemented if flat assembler
1
; Glass like rendering triangle by Maciej Guba.
2
; by Maciej Guba.
-
 
3
; http://macgub.vxm.pl
2
; http://macgub.hekko.pl, macgub3@wp.pl
Line 4... Line 3...
4
 
3
 
5
ROUND2 equ 10
4
ROUND2 equ 10
6
real_phong_tri_z:
5
glass_tri:
7
;----procedure render Phongs shaded triangle with z coord
6
;----procedure render glass like triangle with z coord --
8
;----interpolation ( Catmull alghoritm )-----------------
7
;----interpolation ( Catmull alghoritm )-----------------
9
;----I normalize normal vector in every pixel -----------
8
;----I normalize normal vector in every pixel -----------
10
;------------------in - eax - x1 shl 16 + y1 ------------
9
;------------------in - eax - x1 shl 16 + y1 ------------
11
;---------------------- ebx - x2 shl 16 + y2 ------------
10
;---------------------- ebx - x2 shl 16 + y2 ------------
-
 
11
;---------------------- ecx - x3 shl 16 + y3 ------------
12
;---------------------- ecx - x3 shl 16 + y3 ------------
12
;---------------------- edx - ptr to stencil_buff -------
13
;---------------------- esi - pointer to Z-buffer filled-
13
;---------------------- esi - pointer to Z-buffer filled-
14
;----------------------   with dd float variables--------
14
;----------------------   with dd float variables--------
15
;---------------------- edi - pointer to screen buffer---
15
;---------------------- edi - pointer to screen buffer---
16
;---------------------- xmm0 - 1st normal vector --------
16
;---------------------- xmm0 - 1st normal vector --------
Line 65... Line 65...
65
 
65
 
66
  .cnv1   equ [ebp-208]  ; cur normal vectors
66
  .cnv1   equ [ebp-208]  ; cur normal vectors
67
  .cnv2   equ [ebp-224]
67
  .cnv2   equ [ebp-224]
68
  .cz2    equ [ebp-228]
68
  .cz2    equ [ebp-228]
69
  .cz1    equ [ebp-232]
-
 
-
 
69
  .cz1    equ [ebp-232]
Line 70... Line 70...
70
 
70
  .stencil_buff equ [ebp-236]
Line 97... Line 97...
97
 
97
 
98
   movaps .z1,xmm4
98
   movaps .z1,xmm4
99
   mov    .y1,eax
99
   mov    .y1,eax
100
   mov    .y2,ebx
100
   mov    .y2,ebx
-
 
101
   mov    .y3,ecx
Line 101... Line 102...
101
   mov    .y3,ecx
102
   mov    .stencil_buff, edx
102
 
103
 
103
   movdqa   .y_min,xmm5
104
   movdqa   .y_min,xmm5
104
if 1                            ; check if at last only fragment
105
if 1                            ; check if at last only fragment
Line 119... Line 120...
119
end if
120
end if
120
   movaps   .1_nv,xmm0
121
   movaps   .1_nv,xmm0
121
   movaps   .2_nv,xmm1
122
   movaps   .2_nv,xmm1
122
   movaps   .3_nv,xmm2
123
   movaps   .3_nv,xmm2
123
   movaps   .l_v,xmm3
124
   movaps   .l_v,xmm3
124
   mov      .Zbuf,esi
125
 ;  mov      .Zbuf,esi
125
   mov      .screen,edi
126
   mov      .screen,edi
Line 126... Line 127...
126
 
127
 
Line 254... Line 255...
254
       movaps   xmm1,.cnv2
255
       movaps   xmm1,.cnv2
255
       movlps   xmm3,.cz1
256
       movlps   xmm3,.cz1
256
       movaps   xmm4,.l_v
257
       movaps   xmm4,.l_v
257
       sar      ebx,ROUND2
258
       sar      ebx,ROUND2
258
       sar      eax,ROUND2
259
       sar      eax,ROUND2
-
 
260
       mov      edx,.stencil_buff
259
       mov      edi,.screen
261
       mov      edi,.screen
260
       mov      esi,.Zbuf
262
   ;    mov      esi,.Zbuf
Line 261... Line 263...
261
 
263
 
Line 262... Line 264...
262
       call     real_phong_line_z
264
       call     glass_line
263
 
265
 
264
       popad
266
       popad
265
       movaps   xmm0,.cnv1
267
       movaps   xmm0,.cnv1
Line 307... Line 309...
307
       movaps   xmm1,.cnv2
309
       movaps   xmm1,.cnv2
308
       movlps   xmm3,.cz1
310
       movlps   xmm3,.cz1
309
       movaps   xmm4,.l_v
311
       movaps   xmm4,.l_v
310
       sar      ebx,ROUND2
312
       sar      ebx,ROUND2
311
       sar      eax,ROUND2
313
       sar      eax,ROUND2
-
 
314
       mov      edx,.stencil_buff
312
       mov      edi,.screen
315
       mov      edi,.screen
313
       mov      esi,.Zbuf
316
  ;     mov      esi,.Zbuf
Line 314... Line 317...
314
 
317
 
Line 315... Line 318...
315
       call     real_phong_line_z
318
       call     glass_line
316
 
319
 
317
       popad
320
       popad
318
       movaps   xmm0,.cnv1
321
       movaps   xmm0,.cnv1
Line 340... Line 343...
340
      add   esp,512
343
      add   esp,512
341
      pop   ebp
344
      pop   ebp
Line 342... Line 345...
342
 
345
 
343
ret
346
ret
344
align 16
347
align 16
345
real_phong_line_z:
348
glass_line:
346
; in:
349
; in:
347
;    xmm0 - normal vector 1
350
;    xmm0 - normal vector 1
348
;    xmm1 - normal vect 2
351
;    xmm1 - normal vect 2
349
;    xmm3 - lo -> hi z1, z2 coords as dwords floats
352
;    xmm3 - lo -> hi z1, z2 coords as dwords floats
350
;    xmm2 - lo -> hi y_min, y_max, x_min, x_max
353
;    xmm2 - lo -> hi y_min, y_max, x_min, x_max
351
;           as dword integers
354
;           as dword integers
352
;    xmm4 - normalized light vector
355
;    xmm4 - normalized light vector
353
;    eax - x1
356
;    eax - x1
354
;    ebx - x2
357
;    ebx - x2
-
 
358
;    ecx - y
355
;    ecx - y
359
;    edx - stencil buff ptr
356
;    edi - screen buffer
360
;    edi - screen buffer
Line 357... Line 361...
357
;    esi - z buffer filled with dd floats
361
;    esi - z buffer ===> not needed in glass rendering
358
 
362
 
359
   push  ebp
363
   push  ebp
360
   mov   ebp,esp
364
   mov   ebp,esp
361
   sub   esp,160
365
   sub   esp,256
Line 362... Line 366...
362
   sub   ebp,16
366
   sub   ebp,16
363
   and   ebp,0xfffffff0
367
   and   ebp,0xfffffff0
Line 377... Line 381...
377
 .y_min  equ [ebp-80]
381
 .y_min  equ [ebp-80]
378
 .dn     equ [ebp-96]
382
 .dn     equ [ebp-96]
379
 .dz     equ [ebp-100]
383
 .dz     equ [ebp-100]
380
 .y      equ [ebp-104]
384
 .y      equ [ebp-104]
381
 .cnv    equ [ebp-128]
385
 .cnv    equ [ebp-128]
-
 
386
 .col_sum_b  equ [ebp-136]
-
 
387
 .col_sum_g  equ [ebp-140]
-
 
388
 .col_sum_r  equ [ebp-144]
-
 
389
 .cur_col equ [ebp-160]
-
 
390
 .stencil_buf equ [ebp-164]
Line 382... Line 391...
382
 
391
 
383
        mov    .y,ecx
392
        mov    .y,ecx
384
        packssdw xmm2,xmm2
393
        packssdw xmm2,xmm2
385
        movq   .y_min,xmm2
394
        movq   .y_min,xmm2
Line 405... Line 414...
405
        movaps  .lv,xmm4
414
        movaps  .lv,xmm4
406
        movaps  .n1,xmm0
415
        movaps  .n1,xmm0
407
        movaps  .n2,xmm1
416
        movaps  .n2,xmm1
408
        mov     .lx1,eax
417
        mov     .lx1,eax
409
        mov     .lx2,ebx
418
        mov     .lx2,ebx
-
 
419
        mov     .stencil_buf,edx
410
        movlps  .z1,xmm3
420
        movlps  .z1,xmm3
Line 411... Line 421...
411
 
421
 
412
        sub     ebx,eax
422
        sub     ebx,eax
413
        cvtsi2ss xmm7,ebx
423
        cvtsi2ss xmm7,ebx
Line 418... Line 428...
418
        psrldq  xmm3,4
428
        psrldq  xmm3,4
419
        subss   xmm3,.z1
429
        subss   xmm3,.z1
420
        divss   xmm3,xmm7
430
        divss   xmm3,xmm7
421
        movss   .dz,xmm3
431
        movss   .dz,xmm3
Line 422... Line -...
422
 
-
 
423
 
-
 
424
 
432
 
425
        mov      ebx,.lx1
433
        mov      ebx,.lx1
426
        cmp      bx,.x_min     ; clipping on function4
434
        cmp      bx,.x_min     ; clipping on function4
427
        jge      @f
435
        jge      @f
428
        movzx    eax,word .x_min
436
        movzx    eax,word .x_min
Line 442... Line 450...
442
        movzx   eax,word .x_max
450
        movzx   eax,word .x_max
443
        cmp     .lx2,eax
451
        cmp     .lx2,eax
444
        jl      @f
452
        jl      @f
445
        mov     .lx2,eax
453
        mov     .lx2,eax
446
      @@:
454
      @@:
447
        movzx   eax,word[size_x_var]
455
        movzx   eax,word[xres_var]
448
        mul     dword .y
456
        mul     dword .y
449
      ;  mov     edx,.x1
-
 
-
 
457
 
450
        add     eax,.lx1
458
        add     eax,.lx1
451
        shl     eax,2
459
        shl     eax,2
452
        add     edi,eax
460
        add     edi,eax
453
        add     esi,eax
461
        mov     ebx,eax
-
 
462
        add     ebx,.stencil_buf
-
 
463
 
Line 454... Line 464...
454
 
464
 
455
        mov     ecx,.lx2
465
        mov     ecx,.lx2
-
 
466
        sub     ecx,.lx1
456
        sub     ecx,.lx1
467
 
457
        movaps  xmm0,.n1
468
        movaps  xmm0,.n1
458
        movss   xmm2,.z1
469
        movss   xmm2,.z1
459
align 16
470
align 16
460
   .ddraw:
-
 
461
        movss    xmm7,xmm2
-
 
462
        cmpnltss xmm7,dword[esi]
-
 
463
        movd     eax,xmm7
-
 
464
        or       eax,eax
-
 
465
        jnz      .skip
-
 
466
        movss    [esi],xmm2
471
   .ddraw:
467
        movaps   xmm7,xmm0
472
        movaps   xmm7,xmm0
-
 
473
        mulps    xmm7,xmm7 ; normalize
468
        mulps    xmm7,xmm7 ; normalize
474
        andps    xmm7,[zero_hgst_dd]
469
        haddps   xmm7,xmm7
475
        haddps   xmm7,xmm7
470
        haddps   xmm7,xmm7
476
        haddps   xmm7,xmm7
471
        rsqrtps  xmm7,xmm7
477
        rsqrtps  xmm7,xmm7
-
 
478
        mulps    xmm7,xmm0
472
        mulps    xmm7,xmm0
479
       ; maxps    xmm7,[the_zero]
Line 473... Line 480...
473
        movaps   .cnv,xmm7
480
        movaps   .cnv,xmm7
474
 
481
 
-
 
482
        mov      edx,lights_aligned  ; lights_aligned - global variable
-
 
483
        xorps    xmm1,xmm1           ; instead global can be used .lv - light vect.
-
 
484
      .again_col:
-
 
485
        movaps    xmm3,.cnv
-
 
486
        mulps     xmm3,[edx]
-
 
487
        haddps    xmm3,xmm3
-
 
488
        haddps    xmm3,xmm3   ; xmm3 - dot pr
-
 
489
 
-
 
490
      ; cmp       [bump_flag],1     ; on/off temporaly
-
 
491
                                    ; depend on bump button
-
 
492
      ; je        @f
-
 
493
      ; stencil
-
 
494
        movss     xmm5,xmm2
-
 
495
        movss     xmm6,xmm2
-
 
496
        addss     xmm5,[aprox]
-
 
497
        subss     xmm6,[aprox]
-
 
498
        cmpnltss  xmm5,dword[ebx]
-
 
499
        cmpnltss  xmm6,dword[ebx]
-
 
500
        xorps     xmm5,xmm6
-
 
501
        movd      eax,xmm5
475
        mov      edx,lights_aligned    ; lights - global variable
502
        or        eax,eax
476
        xorps    xmm1,xmm1     ; instead global can be used .lv - light vect.
503
        jz       .no_reflective
477
      @@:
504
     @@:
478
        movaps    xmm6,[edx+16]
505
        movaps    xmm6,xmm3   ;xmm7
479
        movaps    xmm5,[edx]
-
 
480
        movaps    xmm3,[edx+48]
-
 
481
        andps     xmm5,[zero_hgst_dd]  ; global
-
 
482
 
506
        mulps     xmm6,xmm6
483
        mulps    xmm5,.cnv  ;.lv  ; last dword should be zeroed
507
        mulps     xmm6,xmm6
484
        haddps   xmm5,xmm5
-
 
485
        haddps   xmm5,xmm5
-
 
486
   ;     mulps    xmm5,[env_const2]
-
 
487
   ;     maxps    xmm5,[dot_min]
508
        mulps     xmm6,xmm6
488
   ;     minps    xmm5,[dot_max]
-
 
489
        movaps   xmm7,xmm5
509
        mulps     xmm6,xmm6
490
      ;  mulps    xmm7,[env_const2]
-
 
491
     ;   mulps    xmm7,[env_const2]
510
        mulps     xmm6,xmm6
492
     ;   maxps    xmm7,[dot_min]
-
 
493
     ;   minps    xmm7,[dot_max]
511
        mulps     xmm6,[edx+48]
494
 
512
      .no_reflective:
495
        mulps    xmm7,xmm7
513
        movaps    xmm7,xmm3
496
        mulps    xmm7,xmm7
514
        mulps     xmm7,[edx+16]
497
        mulps    xmm5,xmm6
515
        addps     xmm7,xmm6
498
        mulps    xmm7,xmm7
516
        addps     xmm7,[edx+32]
499
        mulps    xmm7,xmm3
-
 
500
 
-
 
501
        addps    xmm5,xmm7
517
        minps     xmm7,[mask_255f]   ; global
502
        minps    xmm5,[mask_255f]   ; global
518
 
503
        maxps    xmm1,xmm5
-
 
504
     ;   movq     xmm3,[edx+20]    ; minimal color
-
 
505
     ;   punpcklwd xmm3,[minimum0]
-
 
506
     ;   cvtdq2ps xmm3,xmm3
-
 
507
     ;   maxps    xmm1,xmm3
519
        maxps     xmm1,xmm7
508
        add      edx,64
520
        add       edx,64     ; size of one light in aligned list
509
        cmp      edx,lights_aligned_end    ; global
-
 
510
        jnz      @b
521
        cmp       edx,lights_aligned_end
-
 
522
        jl        .again_col
511
 
523
        cvtps2dq  xmm1,xmm1
512
        cvtps2dq xmm1,xmm1
524
        movd      xmm6,[edi]
-
 
525
        packssdw  xmm1,xmm1
513
        packssdw xmm1,xmm1
526
        packuswb  xmm1,xmm1
-
 
527
        paddusb   xmm1,xmm6
-
 
528
        movd      [edi],xmm1
514
        packuswb xmm1,xmm1
529
 
515
        movd     [edi],xmm1
530
 
516
     .skip:
531
     .skip:
517
        add      edi,4
532
        add      edi,4
518
        add      esi,4
533
        add      ebx,4  ; stencil_buff
519
        addps    xmm0,.dn
534
        addps    xmm0,.dn
520
        addss    xmm2,.dz
535
        addss    xmm2,.dz
Line 521... Line 536...
521
        sub      ecx,1
536
        sub      ecx,1
522
        jnz      .ddraw
537
        jnz      .ddraw
523
 
538
 
Line 524... Line 539...
524
  .end_rp_line:
539
  .end_rp_line: