1 ; Real Phong's shading implemented if flat assembler
7 ;----procedure render Phongs shaded triangle with z coord
8 ;----interpolation ( Catmull alghoritm )-----------------
9 ;----I normalize normal vector in every pixel -----------
10 ;------------------in - eax - x1 shl 16 + y1 ------------
11 ;---------------------- ebx - x2 shl 16 + y2 ------------
12 ;---------------------- ecx - x3 shl 16 + y3 ------------
13 ;---------------------- esi - pointer to Z-buffer filled-
14 ;---------------------- with dd float variables--------
15 ;---------------------- edi - pointer to screen buffer---
16 ;---------------------- xmm0 - 1st normal vector --------
17 ;---------------------- xmm1 - 2cond normal vector ------
18 ;---------------------- xmm2 - 3rd normal vector --------
19 ;---------------------- xmm3 - normalized light vector --
20 ;---------------------- xmm4 - lo -> hi z1, z2, z3 coords
21 ;---------------------- as dwords floats ---------------
22 ;---------------------- xmm5 - lo -> hi y_min, y_max, ---
23 ;---------------------- x_min, x_max as dword integers -
24 ;---------------------- stack - no parameters -----------
25 ;--------------------------------------------------------
26 ;----------------- procedure don't save registers !! ----
66 .cnv1 equ [ebp-208] ; cur normal vectors
75 .sort3: ; sort triangle coordinates...
79 shufps xmm4,xmm4,11100001b
89 shufps xmm4,xmm4,11011000b
104 if 1 ; check if at last only fragment
105 packssdw xmm5,xmm5 ; of triangle is in visable area
106 pshuflw xmm5,xmm5,11011000b
109 pshufd xmm5,xmm5,0 ; xmm5 lo-hi -> broadcasted y_min, x_min
110 pshufd xmm6,xmm6,01010101b ;xmm6 -> brd y_max x_max
129 mov bx,.y2 ; calc deltas
164 mov bx,.y3 ; calc deltas
198 mov bx,.y3 ; calc deltas
262 call real_phong_line_z
294 movsx ebx,word .x2 ; eax - cur x1
295 shl ebx,ROUND2 ; ebx - cur x2
315 call real_phong_line_z
346 ; xmm0 - normal vector 1
347 ; xmm1 - normal vect 2
348 ; xmm3 - lo -> hi z1, z2 coords as dwords floats
349 ; xmm2 - lo -> hi y_min, y_max, x_min, x_max
351 ; xmm4 - normalized light vector
355 ; edi - screen buffer
356 ; esi - z buffer filled with dd floats
397 shufps xmm3,xmm3,11100001b
425 cmp bx,.x_min ; clipping on function4
427 movzx eax,word .x_min
435 movsx eax,word .x_min
441 movzx eax,word .x_max
446 movzx eax,word[size_x_var]
461 cmpnltss xmm7,dword[esi]
467 mulps xmm7,xmm7 ; normalize
474 mov edx,lights_aligned ; lights - global variable
475 xorps xmm1,xmm1 ; instead global can be used .lv - light vect.
480 andps xmm5,[zero_hgst_dd] ; global
482 mulps xmm5,.cnv ;.lv ; last dword should be zeroed
485 ; mulps xmm5,[env_const2]
486 ; maxps xmm5,[dot_min]
487 ; minps xmm5,[dot_max]
489 ; mulps xmm7,[env_const2]
490 ; mulps xmm7,[env_const2]
491 ; maxps xmm7,[dot_min]
492 ; minps xmm7,[dot_max]
501 minps xmm5,[mask_255f] ; global
503 ; movq xmm3,[edx+20] ; minimal color
504 ; punpcklwd xmm3,[minimum0]
508 cmp edx,lights_aligned_end ; global