Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9236 → Rev 9237

/programs/demos/view3ds/3dmath.inc
4,13 → 4,108
vec_x equ 0
vec_y equ 4
vec_z equ 8
; 3d point - triple integer word coordinate
; vector - triple float dword coordinate
;----------------------in: --------------------------------
;------------------------ esi - pointer to 1st 3d point ---
;------------------------ edi - pointer to 2nd 3d point ---
;------------------------ ebx - pointer to result vector --
;---------------------- out : none ------------------------
 
if 0 ; Ext >= SSE3
calc_bounding_box:
; in:
; xmm0 - normal vector of ray
; xmm1 - light origin
; out:
; eax - axis aligned bounding boxes bit mask
 
.rmx equ [ebp-36]
.nray equ [ebp-64]
.origin equ [ebp-80]
.dirfrac equ [ebp-96]
.nrayr equ [ebp-112]
.originr equ [ebp-128]
.tmin equ [ebp-132]
.tmax equ [ebp-136]
 
 
push ebp
mov ebp,esp
and ebp,-16
sub esp,160
 
movss xmm5,[rsscale]
shufps xmm5,xmm1,0
movd xmm2,[vect_x]
punpcklwd xmm2,[the_zero]
cvtdq2ps xmm2,xmm2
subps xmm1,xmm2
movaps .origin,xmm1
mulps xmm0,xmm5
movaps .nray,xmm0
 
mov esi,matrix
lea edi,.rmx
call reverse_mx_3x3
 
; in: esi - ptr to points(normals], each point(normal) coeficient as dword
; edi - ptr to rotated points(normals)
; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix
; ecx - number of points(normals)
 
; reverse transform
lea esi,.nray
lea edi,.nrayr
lea ebx,.rmx
mov ecx,1
call rotary
 
lea esi,.origin
lea edi,.originr
lea ebx,.rmx
mov ecx,1
call rotary
 
xor ecx,ecx
mov ebx,aabb1
xor eax,eax
rcpps xmm7,.nrayr
movaps .dirfrac,xmm7
 
.nx_aabb:
movaps xmm5,[ebx]
movaps xmm6,[ebx]
minps xmm5,[the_zero]
maxps xmm6,[the_zero]
; xmm5 - lb corner of AABB with minimal coordinates
; xmm6 - rt cor. of AABB wit maximum coords
subps xmm5,.originr
subps xmm6,.originr
mulps xmm5,.dirfrac ; xmm5 - tx1, ty1
mulps xmm6,.dirfrac ; xmm6 - tx2, ty2
movaps xmm1,xmm6
movaps xmm2,xmm6
 
 
minps xmm1,xmm5
maxps xmm2,xmm5
 
movaps xmm5,xmm1
movaps xmm6,xmm2
shufps xmm5,xmm5,11100001b
shufps xmm6,xmm6,11100001b
maxss xmm1,xmm5 ;t min
minss xmm2,xmm6 ;t max
comiss xmm2,xmm1
jb .no_inter
.yes:
bts eax,ecx
.no_inter:
add ebx,16
inc ecx
cmp ecx,8
jne .nx_aabb
 
; out: eax - bit mask
add esp,160
pop ebp
ret
end if
 
reverse_mx_3x3:
; esi - source matrix
; edi - desired reversed matrix
141,6 → 236,13
mov esp,ebp
pop ebp
ret
; 3d point - triple integer word coordinate
; vector - triple float dword coordinate
;----------------------in: --------------------------------
;------------------------ esi - pointer to 1st 3d point ---
;------------------------ edi - pointer to 2nd 3d point ---
;------------------------ ebx - pointer to result vector --
;---------------------- out : none ------------------------
 
make_vector_r:
if Ext < SSE2
194,17 → 296,37
fsubp ;st1 ,st
fstp dword [ebx+vec_z]
ret
cross_aligned:
movaps xmm0,[esi]
movaps xmm1,[esi]
movaps xmm2,[edi]
movaps xmm3,[edi]
shufps xmm0,xmm0,00001001b
shufps xmm1,xmm1,00010010b
shufps xmm2,xmm2,00010010b
shufps xmm3,xmm3,00001001b
mulps xmm0,xmm2
mulps xmm1,xmm3
subps xmm0,xmm1
movaps [ebx],xmm0
ret
;----------------------- in: ------------------------------
;---------------------------- edi - pointer to vector -----
;----------------------- out : none
normalize_vector:
if Ext >= SSE3
if Ext >= SSE2
movups xmm0,[edi]
andps xmm0,[zero_hgst_dd]
movups xmm1,xmm0
mulps xmm0,xmm0
haddps xmm0,xmm0
haddps xmm0,xmm0
movhlps xmm2,xmm0
addps xmm0,xmm2
movaps xmm2,xmm0
shufps xmm2,xmm2,11100101b
addps xmm0,xmm2
shufps xmm0,xmm0,0
; haddps xmm0,xmm0
; haddps xmm0,xmm0
rsqrtps xmm0,xmm0
mulps xmm0,xmm1
movlps [edi],xmm0
559,7 → 681,7
; packsdw xmm0,xmm0
; movq [edi]
fld dword[esi]
fiadd [vect_x]
fiadd word[vect_x]
fistp word[edi]
fld dword[esi+4]
fiadd [vect_y]
/programs/demos/view3ds/3glass.inc
1,5 → 1,5
; Glass like rendering triangle by Maciej Guba.
; http://macgub.hekko.pl, macgub3@wp.pl
; http://macgub.co.pl, macgub3@wp.pl
 
ROUND2 equ 10
glass_tri:
/programs/demos/view3ds/3glass_tex.inc
1,7 → 1,7
; Bilinear filtering, real Phongs shading and glass like parallel.
; Thanks to authors of 3dica tutorial.
; Implemented in FASM by Maciej Guba.
; http://macgub.j.pl
; http://macgub.co.pl
 
ROUND2 equ 10
 
/programs/demos/view3ds/3r_phg.inc
1,6 → 1,6
; Real Phong's shading implemented if flat assembler
; by Maciej Guba.
; http://macgub.vxm.pl
; http://macgub.co.pl
 
ROUND2 equ 10
real_phong_tri_z:
/programs/demos/view3ds/3ray_shd.inc
0,0 → 1,688
; Ray casted shadows
; by Maciej Guba.
; http://macgub.co.pl
 
 
ROUND2 equ 10
ray_shad:
;--- Procedure render triangle with ray casted shadow ---
;--- effect. Calc intersection with all triangles in ----
;--- everypixel. Its not real time process, especially --
;--- when many triangles are computed. ------------------
;------in - eax - x1 shl 16 + y1 ------------------------
;---------- ebx - x2 shl 16 + y2 ------------------------
;---------- ecx - x3 shl 16 + y3 ------------------------
;---------- edx - ptr to fur coords struct --------------
;---------- esi - pointer to stencil / Z-buffer, filled -
;-------------- with dword float variables, it masks --
;-------------- 'Z' position (coord) of every front ---
;-------------- pixel. --------------------------------
;---------- edi - pointer to screen buffer --------------
;---------- xmm0 - 1st normal vector --------------------
;---------- xmm1 - 2cond normal vector ------------------
;---------- xmm2 - 3rd normal vector --------------------
;---------- xmm3 - --------------------------------------
;---------- xmm4 - lo -> hi z1, z2, z3 coords -----------
;--------------- as dwords floats ---------------------
;---------- xmm5 - lo -> hi y_min, y_max, x_min, x_max --
;--------------- as dword integers --------------------
;-----------mm7 - current triangle index ---------------
;---------------------- stack - no parameters -----------
;--------------------------------------------------------
;----------------- procedure don't save registers !! ----
 
push ebp
mov ebp,esp
sub esp,1024
sub ebp,16
and ebp,0xfffffff0
 
.1_nv equ [ebp-16]
.2_nv equ [ebp-32]
.3_nv equ [ebp-48]
.l_v equ [ebp-64]
.z3 equ [ebp-72]
.z2 equ [ebp-76]
.z1 equ [ebp-80]
.x1 equ [ebp-82]
.y1 equ [ebp-84]
.x2 equ [ebp-86]
.y2 equ [ebp-88]
.x3 equ [ebp-90]
.y3 equ [ebp-92]
.Zbuf equ [ebp-96]
.x_max equ [ebp-100]
.x_min equ [ebp-104]
.y_max equ [ebp-108]
.y_min equ [ebp-112]
.screen equ [ebp-116]
.dx12 equ [ebp-120]
.dx13 equ [ebp-124]
.dx23 equ [ebp-128]
.dn12 equ [ebp-144]
.dn13 equ [ebp-160]
.dn23 equ [ebp-176]
.dz12 equ [ebp-180]
.dz13 equ [ebp-184]
.dz23 equ [ebp-188]
.cnv1 equ [ebp-208] ; current normal vectors
.cnv2 equ [ebp-240]
.cz2 equ [ebp-244]
.cz1 equ [ebp-248]
.tri_no equ [ebp-252]
 
 
.sort3: ; sort triangle coordinates...
cmp ax,bx
jle .sort1
xchg eax,ebx
shufps xmm4,xmm4,11100001b
movaps xmm6,xmm0
movaps xmm0,xmm1
movaps xmm1,xmm6
 
.sort1:
cmp bx,cx
jle .sort2
xchg ebx,ecx
shufps xmm4,xmm4,11011000b
movaps xmm6,xmm1
movaps xmm1,xmm2
movaps xmm2,xmm6
 
jmp .sort3
 
.sort2:
 
movaps .z1,xmm4
mov .y1,eax
mov .y2,ebx
mov .y3,ecx
 
movdqa .y_min,xmm5
if 1 ; check if at last only fragment
packssdw xmm5,xmm5 ; of triangle is in visable area
pshuflw xmm5,xmm5,11011000b
movdqu xmm7,.y3
movdqa xmm6,xmm5
pshufd xmm5,xmm5,0 ; xmm5 lo-hi -> broadcasted y_min, x_min
pshufd xmm6,xmm6,01010101b ;xmm6 -> brd y_max x_max
movdqa xmm4,xmm7
pcmpgtw xmm7,xmm5
pcmpgtw xmm4,xmm6
pxor xmm7,xmm4
pmovmskb eax,xmm7
and eax,0x00aaaaaa
or eax,eax
jz .rpt_loop2_end
end if
movd .tri_no,mm7
movaps .1_nv,xmm0
movaps .2_nv,xmm1
movaps .3_nv,xmm2
; movaps .l_v,xmm3
mov .Zbuf,esi
mov .screen,edi
 
 
 
mov bx,.y2 ; calc deltas
sub bx,.y1
jnz .rpt_dx12_make
 
xorps xmm7,xmm7
mov dword .dx12,0
mov dword .dz12,0
movaps .dn12,xmm7
jmp .rpt_dx12_done
 
.rpt_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx12,eax
 
cvtsi2ss xmm6,ebx
movss xmm5,.z2
rcpss xmm6,xmm6
subss xmm5,.z1
mulss xmm5,xmm6
movss .dz12,xmm5
 
shufps xmm6,xmm6,0
movaps xmm0,.2_nv
subps xmm0,.1_nv
mulps xmm0,xmm6
movaps .dn12,xmm0
; subps xmm3,xmm0
; mulps xmm3,xmm6
 
.rpt_dx12_done:
mov bx,.y3 ; calc deltas
sub bx,.y1
jnz .rpt_dx13_make
 
xorps xmm7,xmm7
mov dword .dx13,0
mov dword .dz13,0
movaps .dn13,xmm7
jmp .rpt_dx13_done
 
.rpt_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx13,eax
 
cvtsi2ss xmm6,ebx
movss xmm5,.z3
rcpss xmm6,xmm6
subss xmm5,.z1
mulss xmm5,xmm6
movss .dz13,xmm5
 
movaps xmm0,.3_nv
subps xmm0,.1_nv
shufps xmm6,xmm6,0
mulps xmm0,xmm6
movaps .dn13,xmm0
 
; mulps xmm0,xmm6
 
.rpt_dx13_done:
 
mov bx,.y3 ; calc deltas
sub bx,.y2
jnz .rpt_dx23_make
 
xorps xmm7,xmm7
mov dword .dx23,0
mov dword .dz23,0
movaps .dn23,xmm7
 
jmp .rpt_dx23_done
 
.rpt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx23,eax
 
cvtsi2ss xmm6,ebx
movss xmm5,.z3
rcpss xmm6,xmm6
subss xmm5,.z2
mulss xmm5,xmm6
movss .dz23,xmm5
 
movaps xmm0,.3_nv
subps xmm0,.2_nv
shufps xmm6,xmm6,0
mulps xmm0,xmm6
movaps .dn23,xmm0
; mulps xmm0,xmm6
 
.rpt_dx23_done:
 
movsx eax,word .x1
shl eax,ROUND2
mov ebx,eax
mov ecx,.z1
mov .cz1,ecx
mov .cz2,ecx
movaps xmm0,.1_nv
movaps .cnv1,xmm0
movaps .cnv2,xmm0
mov edi,.screen
mov esi,.Zbuf
movsx ecx,word .y1
cmp cx,.y2
 
jge .rpt_loop1_end
 
.rpt_loop1:
pushad
 
movaps xmm2,.y_min
movaps xmm0,.cnv1
movaps xmm1,.cnv2
movlps xmm3,.cz1
; movaps xmm4,.l_v
sar ebx,ROUND2
sar eax,ROUND2
movd mm7,.tri_no
 
call ray_shd_l
 
popad
movaps xmm0,.cnv1
movaps xmm1,.cnv2
; fur x,y
movss xmm2,.cz1
movss xmm3,.cz2
shufps xmm4,xmm4,01001110b
addps xmm0,.dn13
addps xmm1,.dn12
addss xmm2,.dz13
addss xmm3,.dz12
 
 
add eax,.dx13
add ebx,.dx12
 
shufps xmm4,xmm4,01001110b
movaps .cnv1,xmm0
movaps .cnv2,xmm1
movss .cz1,xmm2
movss .cz2,xmm3
 
add ecx,1
cmp cx,.y2
jl .rpt_loop1
 
 
.rpt_loop1_end:
movsx ecx,word .y2
cmp cx,.y3
jge .rpt_loop2_end
 
movsx ebx,word .x2 ; eax - cur x1
shl ebx,ROUND2 ; ebx - cur x2
push dword .z2
pop dword .cz2
movaps xmm0,.2_nv
movaps .cnv2,xmm0
 
mov edi,.screen
mov esi,.Zbuf
 
 
.rpt_loop2:
pushad
movaps xmm2,.y_min
movaps xmm0,.cnv1
movaps xmm1,.cnv2
movlps xmm3,.cz1
; movaps xmm4,.l_v
sar ebx,ROUND2
sar eax,ROUND2
movd mm7,.tri_no
 
call ray_shd_l
 
popad
movaps xmm0,.cnv1
movaps xmm1,.cnv2
movss xmm2,.cz1
movss xmm3,.cz2
 
addps xmm0,.dn13
addps xmm1,.dn23
addss xmm2,.dz13
addss xmm3,.dz23
add eax,.dx13
add ebx,.dx23
addps xmm4,xmm6
 
movaps .cnv1,xmm0
movaps .cnv2,xmm1
movss .cz1,xmm2
movss .cz2,xmm3
 
add ecx,1
cmp cx,.y3
jl .rpt_loop2
 
.rpt_loop2_end:
 
add esp,1024
pop ebp
 
 
 
ret
align 16
ray_shd_l:
; in:
; xmm0 - normal vector 1
; xmm1 - normal vect 2
; xmm3 - lo -> hi z1, z2 coords as dwords floats
; xmm2 - lo -> hi y_min, y_max, x_min, x_max
; as dword integers
; xmm4 - ----
; mm7 - current triangle index
; eax - x1
; ebx - x2
; ecx - y
; edx - -----
; edi - screen buffer
; esi - z buffer / stencil buffer filled with dd floats
 
push ebp
mov ebp,esp
sub esp,320
sub ebp,16
and ebp,0xfffffff0
 
.n1 equ [ebp-16]
.n2 equ [ebp-32]
.lv equ [ebp-48]
.lx1 equ [ebp-52]
.lx2 equ [ebp-56]
.z2 equ [ebp-60]
.z1 equ [ebp-64]
.screen equ [ebp-68]
.zbuff equ [ebp-72]
.x_max equ [ebp-74]
.x_min equ [ebp-76]
.y_max equ [ebp-78]
.y_min equ [ebp-80]
.dn equ [ebp-96]
.dz equ [ebp-100]
.y equ [ebp-104]
; .cur_tri equ [ebp-108]
.cnv equ [ebp-128]
.Rlen equ [ebp-128-16]
.r1 equ [ebp-128-32]
.vect_t equ [ebp-128-48]
.cur_tri equ [ebp-128-64]
; .p3t equ [ebp-128-80]
.nray equ [ebp-128-96]
.final_col equ [ebp-128-112]
.aabb_mask equ dword[ebp-128-112-4]
 
mov .y,ecx
movdqa xmm4,xmm2
packssdw xmm2,xmm2
movq .y_min,xmm2
cmp cx,.y_min
jl .end_rp_line
cmp cx,.y_max
jge .end_rp_line ;
cmp eax,ebx
je .end_rp_line
jl @f
xchg eax,ebx
movaps xmm7,xmm0
movaps xmm0,xmm1
movaps xmm1,xmm7
shufps xmm3,xmm3,11100001b
@@:
movd .cur_tri,mm7
cmp ax,.x_max
jge .end_rp_line
cmp bx,.x_min
jle .end_rp_line
; movaps .lv,xmm4
andps xmm0,[zero_hgst_dd]
andps xmm1,[zero_hgst_dd]
movaps .n1,xmm0
movaps .n2,xmm1
mov .lx1,eax
mov .lx2,ebx
movlps .z1,xmm3
 
sub ebx,eax
cvtsi2ss xmm7,ebx
rcpss xmm7,xmm7
shufps xmm7,xmm7,0
subps xmm1,xmm0
mulps xmm1,xmm7
movaps .dn,xmm1
shufps xmm3,xmm3,11111001b
subss xmm3,.z1
mulss xmm3,xmm7
movss .dz,xmm3
 
subps xmm6,xmm5
mulps xmm6,xmm7
 
mov ebx,.lx1
cmp bx,.x_min ; clipping on function4
jge @f
movzx eax,word .x_min
sub eax,ebx
cvtsi2ss xmm7,eax
shufps xmm7,xmm7,0
mulss xmm3,xmm7
mulps xmm1,xmm7
mulps xmm6,xmm7
addss xmm3,.z1
addps xmm1,.n1
addps xmm6,xmm5
movsx eax,word .x_min
movss .z1,xmm3
movaps .n1,xmm1
mov dword .lx1,eax
@@:
 
movzx eax,word .x_max
cmp .lx2,eax
jl @f
mov .lx2,eax
@@:
movzx eax,word[xres_var]
mul dword .y
add eax,.lx1
mov .zbuff,esi
mov .screen,edi
shl eax,2
add edi,eax
add esi,eax
mov ecx,.lx2
sub ecx,.lx1
 
movd xmm0,[vect_x]
punpcklwd xmm0,[the_zero]
cvtdq2ps xmm0,xmm0
movaps .vect_t,xmm0
 
 
.ddraw:
 
xorps xmm0,xmm0
movss xmm2,.z1
movss xmm5,.z1
movaps .final_col,xmm0
addss xmm2,[f1]
subss xmm5,[f1]
cmpnltss xmm2,dword[esi]
cmpnltss xmm5,dword[esi]
pxor xmm2,xmm5
movd eax,xmm2
or eax,eax
jz .skips
 
movaps xmm7,.n1
andps xmm7,[zero_hgst_dd]
mulps xmm7,xmm7 ; normalize
haddps xmm7,xmm7
haddps xmm7,xmm7
rsqrtps xmm7,xmm7
mulps xmm7,.n1
movaps .cnv,xmm7
mov ebx,point_light_coords
mov edx,lights_aligned
xor eax,eax
.nx_light:
pushad
cvtsi2ss xmm0,.lx1
cvtsi2ss xmm1,.y
movss xmm2,.z1
movlhps xmm0,xmm1
shufps xmm0,xmm2,11001000b
subps xmm0,[ebx] ; xmm0 - ray end, -> current vertex
movaps xmm3,[ebx]
andps xmm0,[zero_hgst_dd]
movaps xmm1,xmm0
mulps xmm0,xmm0
haddps xmm0,xmm0
haddps xmm0,xmm0
sqrtps xmm0,xmm0
movss .Rlen,xmm0
rcpps xmm0,xmm0
mulps xmm0,xmm1 ; xmm0 - normalized ray vector
andps xmm0,[zero_hgst_dd]
movaps .nray,xmm0
movaps .r1,xmm3 ; ray orgin
if 0
movaps xmm1,xmm3
call calc_bounding_box
 
mov .aabb_mask,eax
end if
mov edi,[triangles_ptr]
xor ecx,ecx
.nx_tri: ; next triangle
 
cmp ecx,.cur_tri ; prevent self shadowing
je .skipp
if 0
mov edi,ecx
imul edi,[i12]
add edi,[triangles_ptr]
mov eax,[edi]
mov ebx,[edi+4]
mov edx,[edi+8]
imul eax,[i12]
imul ebx,[i12]
imul edx,[i12]
add eax,[points_ptr]
add ebx,[points_ptr]
add edx,[points_ptr]
movups xmm2,[eax]
movups xmm3,[ebx]
movups xmm4,[edx]
andps xmm2,[sign_mask]
andps xmm3,[sign_mask]
andps xmm4,[sign_mask]
movmskps ebx,xmm4
cmpeqps xmm2,xmm3
cmpeqps xmm3,xmm4
andps xmm2,xmm3
movmskps eax,xmm2
and eax,111b
and ebx,111b
cmp eax,111b
jne @f
bt .aabb_mask,ebx
jnc .skipp
@@:
end if
mov edi,ecx
imul edi,[i12]
add edi,[triangles_ptr]
mov eax,[edi]
mov ebx,[edi+4]
mov edx,[edi+8]
imul eax,[i12]
imul ebx,[i12]
imul edx,[i12]
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add edx,[points_rotated_ptr]
movups xmm2,[eax]
movups xmm3,[ebx]
movups xmm4,[edx]
addps xmm2,.vect_t
addps xmm3,.vect_t
addps xmm4,.vect_t
 
 
;intersect_tri: procs header
; in:
; xmm0 - ray direction ; should be normalized
; xmm1 - ray orgin
; xmm2 - tri vert1
; xmm3 - tri vert2
; xmm4 - tri vert3
; if eax = 1 - intersction with edge
; xmm6 - edge lenght
; if eax = 0 - intersect with ray (classic)
; out:
; eax = 1 - intersection occured
; xmm0 - float lo -> hi = t, v, u, ...
 
movss xmm6,.Rlen
movaps xmm0,.nray
movaps xmm1,.r1
subss xmm6,[the_one]
mov eax,1
push ecx
call intersect_tri
pop ecx
cmp eax,1
je .inter
.skipp:
.skp:
inc ecx
cmp ecx,[triangles_count_var]
jnz .nx_tri
; jz .do_process
; comiss xmm0,.Rlen
; jl .inter
 
popad
.do_process:
movaps xmm5,.nray ;[edx]
andps xmm5,[zero_hgst_dd] ; global
mulps xmm5,.cnv ;.lv ; last dword should be zeroed
; andps xmm5,[sign_z] ; global
haddps xmm5,xmm5
haddps xmm5,xmm5
andps xmm5,[abs_mask] ; global
movaps xmm7,xmm5
mulps xmm7,xmm7
mulps xmm7,xmm7
mulps xmm5,[edx+16]
mulps xmm7,xmm7
mulps xmm7,xmm7
mulps xmm7,[edx+48]
addps xmm5,xmm7
minps xmm5,[mask_255f] ; global
maxps xmm5,.final_col ; addps maxps
movaps .final_col,xmm5
jmp .nx_loop
.inter:
 
popad
.nx_loop:
; add edx,64 ; unncomment to achive 3 lights
; add ebx,16
; cmp edx,lights_aligned_end ; global
; jnz .nx_light
 
movaps xmm1,.final_col
cvtps2dq xmm1,xmm1
packssdw xmm1,xmm1
packuswb xmm1,xmm1
movd [edi],xmm1
.skips:
movaps xmm0,.n1
movss xmm2,.z1
add edi,4
add esi,4
add dword .lx1,1
addps xmm0,.dn
addss xmm2,.dz
movaps .n1,xmm0
movss .z1,xmm2
dec ecx
jnz .ddraw
.end_rp_line:
add esp,320
pop ebp
 
ret
/programs/demos/view3ds/a_procs.inc
1,3 → 1,200
 
 
if Ext > SSE2
;--------------------------------------------------------------------
init_point_lights:
; mov eax,1000
; cvtsi2ss xmm1,eax
; shufps xmm1,xmm1,11000000b
; mov esi,lights_aligned
; mov edi,point_light_coords
; mov ecx,3
; @@:
; movaps xmm0,[esi]
; addps xmm0,[f05xz]
; mulps xmm0,xmm1
; movaps [edi],xmm0
; add esi,64
; add edi,16
; loop @b
mov ecx,3
mov edi,point_light_coords
@@:
push ecx
xor ecx,ecx
movzx edx,word[size_x_var]
call random
cvtsi2ss xmm0,eax
movss [edi],xmm0
xor ecx,ecx
movzx edx,word[size_x_var]
call random
cvtsi2ss xmm0,eax
movss [edi+4],xmm0
; movzx ebx,word[size_x_var]
; shl ebx,2
; neg ebx
mov ecx,-1900
; sub ecx,100
mov edx,-600
call random
cvtsi2ss xmm0,eax
movss [edi+8],xmm0
; mov dword[edi+8],-1700.0
mov [edi+12],dword 0
add edi,16
pop ecx
loop @b
 
ret
 
;------------------------------------------------------------------
intersect_tri: ; Moeller-Trumbore method
; in:
; xmm0 - ray direction ; should be normalized
; xmm1 - ray orgin
; xmm2 - tri vert1
; xmm3 - tri vert2
; xmm4 - tri vert3
; if eax = 1 - intersction with edge
; xmm6 - edge lenght
; if eax = 0 - intersect with ray (classic)
; out:
; eax = 1 - intersection occured
; xmm0 - float lo -> hi = t, v, u, ...
push ebp
mov ebp,esp
and ebp,-16
sub esp,220
 
.dir equ [ebp-16]
.origin equ [ebp-32]
.ta equ [ebp-48]
.tb equ [ebp-64]
.tc equ [ebp-80]
.tvec equ [ebp-96]
.pvec equ [ebp-112]
.qvec equ [ebp-128]
.e1 equ [ebp-128-16]
.ift equ dword[ebp-152]
.invdet equ [ebp-156]
.det equ [ebp-160]
.ed_l equ [ebp-164]
.u equ [ebp-168]
.v equ [ebp-172]
.t equ [ebp-176]
.e2 equ [ebp-192]
 
movaps .dir,xmm0
movaps .origin,xmm1
movaps .ta,xmm2
movaps .tb,xmm3
movaps .tc,xmm4
mov .ift,eax
movss .ed_l,xmm6
subps xmm3,xmm2
subps xmm4,xmm2
andps xmm3,[zero_hgst_dd]
andps xmm4,[zero_hgst_dd]
movaps .e1,xmm3
movaps .e2,xmm4
 
lea esi,.dir
lea edi,.e2
lea ebx,.pvec
call cross_aligned
 
movaps xmm0,.e1
mulps xmm0,.pvec
; andps xmm0,[zero_hgst_dd]
haddps xmm0,xmm0
haddps xmm0,xmm0
movss .det,xmm0
; cmpnless xmm0,[eps]
; movd eax,xmm0
; or eax,eax
; jz @f
comiss xmm0,[eps]
jl @f
 
rcpss xmm0,.det
movss .invdet,xmm0
 
movaps xmm0,.origin
subps xmm0,.ta
andps xmm0,[zero_hgst_dd]
movaps .tvec,xmm0
 
mulps xmm0,.pvec
haddps xmm0,xmm0
haddps xmm0,xmm0
mulss xmm0,.invdet
movss xmm1,xmm0
movss .u,xmm0
cmpnless xmm1,[epsone]
cmpnless xmm0,[epsminus]
pxor xmm1,xmm0
movd eax,xmm1
or eax,eax
jz @f
 
lea esi,.tvec
lea edi,.e1
lea ebx,.qvec
call cross_aligned
 
movaps xmm0,.dir
mulps xmm0,.qvec
haddps xmm0,xmm0
haddps xmm0,xmm0
mulss xmm0,.invdet
movss .v,xmm0
movss xmm1,xmm0
addss xmm1,.u
cmpnless xmm1,[epsone]
cmpnless xmm0,[epsminus]
pxor xmm1,xmm0
movd eax,xmm1
or eax,eax
jz @f
 
movaps xmm1,.e2
mulps xmm1,.qvec
haddps xmm1,xmm1
haddps xmm1,xmm1
mulss xmm1,.invdet
movss .t,xmm1
; cmpnless xmm1,[eps]
; movmskps eax,xmm1
; test eax,1
; jz @f
comiss xmm1,[eps]
jl @f
 
mov eax,1
cmp .ift,0
je .end ; ok intersect occured, no edge cause
 
movss xmm0,.t ; else check with edge lenght
; movss xmm1,.t
cmpnless xmm0,[eps]
cmpnless xmm1,.ed_l
xorps xmm0,xmm1
movd ebx,xmm0
or ebx,ebx
jz @f
 
; mov eax,1
; movaps xmm0,.t
jmp .end
@@:
xor eax,eax
.end:
movaps xmm0,.t
add esp,220
pop ebp
ret
end if
;===============================================================
do_edges_list:
push ebp
223,13 → 420,18
 
 
do_sinus:
;in - ax - render mode
.x equ [ebp-8]
.y equ [ebp-12]
.new_y equ [ebp-16]
.temp equ [ebp-20]
.dr_f equ word[ebp-22]
 
push ebp
mov ebp,esp
sub esp,64
sub esp,30
mov .dr_f,ax
 
mov dword .x,0
mov dword .y,0
mov esi,[screen_ptr]
243,53 → 445,20
cld
rep stosd
pop edi
; movzx eax,[sinus_flag]
; mov edx,10
; mul edx
; mov [sin_amplitude],eax
; mov [sin_frq],eax
fninit
;if Ext = SSE2
; movups xmm1,[const0123] ; xmm1 - init values
; mov eax,0x000000ff
; movd xmm2,eax
; shufps xmm2,xmm2,0 ; xmm2 - mask value
; mov eax,4
; movd xmm3,eax
; shufps xmm3,xmm3,0
.again:
if 0
fild dword .x
fidiv [sin_frq]
fsin
fimul [sin_amplitude]
fiadd dword .y
fistp dword .new_y
else
fild dword .x
fmul [sin_frq]
fistp dword .temp
mov eax, .temp
; mov bx, [angle_x]
; add bx, [angle_y]
; movzx ebx,bx
; shr ebx,1 ; change phase
; add eax,ebx
 
 
and eax, 0x000000ff
 
; cdq
; mul [sin_frq]
; and eax,0x000000ff
; and ax,0x00ff
; cwde
 
fld dword [sin_tab+eax*4]
fimul dword [sin_amplitude]
fiadd dword .y
fistp dword .new_y
end if
 
mov eax,.new_y
or eax,eax
jl .skip
298,12 → 467,11
jg .skip
movzx edx,word[size_x_var]
mul edx
; shl eax,9
add eax,dword .x
 
lea ebx,[eax*3]
cmp [dr_flag],12 ; 32 bit col cause
jl @f
cmp .dr_f,12 ; 32 bit col cause
jb @f
add ebx,eax
@@:
mov eax,[esi]
310,8 → 478,8
mov [edi+ebx],eax
.skip:
add esi,3
cmp [dr_flag],12
jl @f
cmp .dr_f,12
jb @f
inc esi
@@:
inc dword .x
330,8 → 498,8
movzx ecx,word[size_x_var]
movzx eax,word[size_y_var]
imul ecx,eax
cmp [dr_flag],12
jge @f
cmp .dr_f,12
jae @f
lea ecx,[ecx*3]
shr ecx,2
; mov ecx,SIZE_X*SIZE_Y*3/4
377,7 → 545,19
ret
 
do_emboss: ; sse2 version only
; in ax - render model
push ebp
mov ebp,esp
sub esp,4
 
.dr_mod equ word[ebp-2]
 
mov .dr_mod,ax
 
if Ext >= SSE2
 
 
 
movzx ecx,[bumps_deep_flag]
inc ecx
call blur_screen ;blur n times
392,13 → 572,13
sub ecx,ebx
mov esi,[screen_ptr]
mov edi,[Zbuffer_ptr]
cmp [dr_flag],12
cmp .dr_mod,11
jge @f
lea ebx,[ebx*3]
jmp .f
jmp .gf
@@:
shl ebx,2
.f:
.gf:
mov edx,esi
add esi,ebx
lea ebx,[ebx+esi]
405,7 → 585,7
pxor xmm0,xmm0
push eax
.emb:
cmp [dr_flag],12
cmp .dr_mod ,11
jge @f
movlps xmm1,[esi+3]
movhps xmm1,[esi+6]
442,14 → 622,7
pmaxsw xmm1,xmm7
pmaxsw xmm1,xmm6
 
if 0
movaps xmm7,xmm3
movaps xmm6,xmm3
psrlq xmm7,2*8
psrlq xmm6,4*8
pmaxsw xmm3,xmm7
pmaxsw xmm3,xmm6
end if
 
pmaxsw xmm1,xmm3
 
movd eax,xmm1
469,7 → 642,7
mov eax,[eax]
mov [edi+4],eax
 
cmp [dr_flag],12
cmp .dr_mod,11
jl @f
add esi,2
add ebx,2
487,7 → 660,7
pop ecx ;,eax
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
cmp [dr_flag],12
cmp .dr_mod,11
jge .e
@@:
movsd
498,6 → 671,11
 
end if
 
 
 
mov esp,ebp
pop ebp
 
ret
 
;align 16
/programs/demos/view3ds/b_procs.inc
737,22 → 737,33
 
blur_screen: ;blur n times ; blur or fire
;in - ecx times count
;.counter equ dword[esp-4]
.counter1 equ dword[esp-8]
; ax - render mode
 
.val equ dword[ebp-4]
.dr_model equ word[ebp-6]
.fire equ dword[ebp-10]
 
if Ext>=SSE2
push ebp
mov ebp,esp
push dword 0x01010101
movss xmm5,[esp]
sub esp,10
; xorps xmm5,xmm5
; or edx,edx
; jz @f
mov .val,0x01010101
movss xmm5,.val
shufps xmm5,xmm5,0
@@:
mov .dr_model,ax
 
 
.again_blur:
push ecx
mov edi,[screen_ptr]
movzx ecx,word[size_x_var] ;SIZE_X*3/4
 
cmp [dr_flag],12
cmp .dr_model,11
jge @f
lea ecx,[ecx*3+1]
lea ecx,[ecx*3+3]
shr ecx,2
@@:
 
763,7 → 774,7
movzx ecx,word[size_y_var]
sub ecx,3
imul ecx,ebx
cmp [dr_flag],12 ; 32 bit per pix cause
cmp .dr_model,11 ; 32 bit per pix cause
jge @f
lea ecx,[ecx*3]
shr ecx,4
781,7 → 792,7
mov ecx,edi
sub ecx,ebx
movups xmm1,[ecx]
cmp [dr_flag],12
cmp .dr_model,12
jge @f
movups xmm2,[edi-3]
movups xmm3,[edi+3]
802,9 → 813,9
end if
xor eax,eax
movzx ecx,word[size_x_var]
cmp [dr_flag],12
cmp .dr_model,11
jge @f
lea ecx,[ecx*3]
lea ecx,[ecx*3+3]
shr ecx,2
@@:
; mov ecx,SIZE_X*3/4
/programs/demos/view3ds/data.inc
1,5 → 1,7
; DATA AREA ************************************
 
if Ext > SSE2
isSSE3 db 1
end if
i3 dw 3
i6 dd 6
i12 dd 12
6,6 → 8,7
i36 dd 36
i256 dw 256
i255d dd 255
f1:
dot_max dd 1.0 ; dot product max and min
dot_min dd 0.0
env_const dd 1.05
25,7 → 28,7
y_offset dw SIZE_Y / 2
z_offset dw 0
rsscale dd 175.0 ; next real scale
vect_x dw SIZE_X / 2
vect_x: dw SIZE_X / 2
vect_y dw SIZE_Y / 2
vect_z dw 0
size_y_var:
110,9 → 113,9
dd ?
 
db 7
db 'catmull '
db 'ray shadow'
db 2
catmull_flag db 1
ray_shd_flag db 0
dd onoff_f
 
db 8
165,7 → 168,7
 
db 16
db 'fire '
db 3
db 2
fire_flag db 0
dd blur_f
 
350,7 → 353,7
if Ext=SSE3
db ' (SSE3)'
end if
db ' 0.073',0
db ' 0.074',0
labellen:
STRdata db '-1 '
lab_vert:
425,8 → 428,43
 
 
 
;if Ext >= SSE3
align 16
point_light_coords:
dd 50.0
dd 50.0
dd -215.0
dd 0.0
 
align 16
 
dd 815.0
dd 815.0
dd -215.0
dd 0.0
 
dd 1500.0
dd 1500.0
dd -215.0
dd 0.0
if 0
aabb1:
.0 dd 1.0,1.0,1.0,0
.1 dd -1.0,1.0,1.0,0
.2 dd 1.0,-1.0,1.0,0
.3 dd -1.0,-1.0,1.0,0
.4 dd 1.0,1.0,-1.0,0
.5 dd -1.0,1.0,-1.0,0
.6 dd 1.0,-1.0,-1.0,0
.7 dd -1.0,-1.0,-1.0,0
 
end if
 
sign_mask:
times 4 dd 0x80000000
f05xz: dd 0, 0, - 1.0 ,0
 
sign_z:
dd -1,-1,0x7fffffff,0
abs_mask:
dd 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff
emboss_bias:
442,7 → 480,11
times 4 dd 510.0
the_one:
times 4 dd 1.0
 
eps: times 4 dd 0.00000
epsone dd 1.0001
aprox dd 0.0001
epsminus dd -0.0001
 
 
file_info:
463,22 → 505,13
workarea rb 180
EndFile dd ?
align 8
sinbeta dd ?;+32
sinbeta dd ?;
cosbeta dd ?
 
xsub dw ?
zsub dw ?;+40
zsub dw ?
ysub dw ?
 
xx1 dw ?
yy1 dw ?
zz1 dw ?;+48 xx1 + 4
xx2 dw ?
yy2 dw ?
zz2 dw ? ; xx1 + 10
xx3 dw ?;+56
yy3 dw ?
zz3 dw ? ; xx1 + 16
col1 dd ?
col2 dd ?
col3 dd ?
487,13 → 520,9
points_count_var dd ? ;
triangles_count_var dd ? ; dont change order
edges_count dd ? ;
tex_points_ptr dd ?
 
point_index1 dd ? ;-\
point_index2 dd ? ; } don't change order
point_index3 dd ? ;-/
temp_col dw ?
temp1 dd ? ; > dont change
temp2 dd ? ; > order
high dd ?
rand_seed dw ?
align 8
510,18 → 539,14
matrix rb 36
cos_tab rd 360
sin_tab rd 360
 
align 16
lights_aligned:
lights_aligned_end = $ + 16 * 12
rb 16 * 12
 
 
points_count = 180000/6*3
triangles_count = 180000 / 6 ;($-triangles)/6
align 16
label trizdd dword
label trizdq qword
triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position
align 16
vectors rb 24
 
align 16
bumpmap rb TEXTURE_SIZE + 1
align 16
535,25 → 560,19
align 16
color_map rb (TEXTURE_SIZE +100) * 3
align 16
tex_points rb points_count * 4 ; bump_map and texture coords
; each point word x, word y
align 16
lights_aligned:
lights_aligned_end = $ + 16 * 12
rb 16 * 12
; tex_points rb points_count * 4 ; bump_map and texture coords
; ; each point word x, word y
;align 16
; lights_aligned:
; lights_aligned_end = $ + 16 * 12
; rb 16 * 12
 
 
if Ext >= SSE2
sse_repository rb 1024
end if
; SourceFile: ; source file temporally in screen area
; workarea dd ?
 
; screen rb SIZE_X * SIZE_Y * 3 ; screen buffer
;align 16
; Z_buffer rb SIZE_X * SIZE_Y * 4
procinfo:
rb 1024 ; process info
rb 2048 ; process info
I_Param rb 256
memStack:
rb 2000
/programs/demos/view3ds/history.txt
1,3 → 1,8
View3ds 0.073 - may 2021
1. I introduced procedure for searching nonredundand edges.
2. Writing some info about object: vertices, triangles unique edges
count.
-----------------------------------------------------------------------------------
 
View3ds 0.072 - march 2021
1. New displaying model - texturing with bilinear filtering and transparency
/programs/demos/view3ds/readme.txt
1,20 → 1,16
View3ds 0.073 - tiny viewer to .3ds and .asc files with several graphics
View3ds 0.074 - tiny viewer to .3ds and .asc files with several graphics
effects implementation.
 
What's new?
1. I introduced procedure for searching nonredundand edges.
2. Writing some info about object: vertices, triangles unique edges
count.
1. Fixed emboss bug in grd lines displaying model.
2. Grd line exceedes screen problem fix.
3. New rendering model - ray casted shadows and appropiate button to
set 'on' this option. Note that is non real time model, especially when
complex object is computed. I took effort to introduce accelerating
structure - AABB (Axis Aligned Bounding Boxes).. but it is disabled
for now - seems to work incorrect(slow).
 
 
1. New displaying model - texturing with bilinear filtering and transparency
simultanusly. Note that filtering is done only inside polygon. To better
quality of image there is a need to use floats coordinates of texture to pass
as arguments to single triangle rendering proc.
2. Optimizations.
3. SSE3 version runs correct on SSE2 cpus, but real phong, glass and
transparented texturing with filtering rendering models are disabled.
 
Buttons description:
1. rotary: choosing rotary axle: x, y, x+y.
2. shd. model: choosing shading model: flat, grd (smooth), env (spherical
26,7 → 22,7
ptex (real Phong + texturing + transparency).
3. speed: idle, full.
4,5. zoom in, out: no comment.
6. catmull: disabled
6. ray shadow: calc ray casted shadows.
7. culling: backface culling on/ off.
8. rand. light: Randomize 3 unlinear lights( so called Phong's illumination).
9. Blur: blur N times; N=0,1,2,3,4,5
50,4 → 46,4
decrease whole handlers count by enable culling (using appropriate button) - some
back handlers become hidden.
 
Maciej Guba V 2021
Maciej Guba IX 2021
/programs/demos/view3ds/view3ds.asm
1,5 → 1,5
 
; application : View3ds ver. 0.071 - tiny .3ds and .asc files viewer
; application : View3ds ver. 0.074 - tiny .3ds and .asc files viewer
; with a few graphics effects demonstration.
; compiler : FASM
; system : KolibriOS
38,6 → 38,9
SSE2 = 3
SSE3 = 4
Ext = SSE3 ;Ext={ NON | MMX | SSE | SSE2 | SSE3 }
; For now correct only SSE2 and SSE3 versions. if you have older CPU
; use older versions of app. Probably ver 005 will be OK but it need
; re-edit to support new Kolibri features.
 
; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features)
USE_LFN = 1 ; App is Kolibri only now.
54,6 → 57,8
dd 0x0 ; I_Icon
 
START: ; start of execution
rdtsc
mov [rand_seed],ax
cld
push dword (SIZE_Y shr 3) * 3
fninit
90,9 → 95,7
; set point(0,0,0) in center and calc all coords
; to be in <-1.0,1.0>
call normalize_all_light_vectors
if Ext >= SSE3
call copy_lights ; to aligned float
end if
call init_triangles_normals2
call init_point_normals
call init_envmap2
100,17 → 103,25
call generate_texture2
call init_sincos_tab
call do_color_buffer ; intit color_map
if Ext >= SSE3
call init_point_lights
mov [fire_flag],0 ; proteza
end if
mov edi,bumpmap
call calc_bumpmap
call calc_bumpmap_coords ; bump and texture mapping
call do_edges_list
call draw_window
;mov [draw_win_at_first],0
;mov eax,40 ; set events mask
;mov ebx,1100000000000000000000000100111b
;int 0x40
if Ext > SSE2
mov eax,1
cpuid
bt ecx,0 ; is sse3 on board?
jc @f
mov [max_dr_flg],12
mov [isSSE3],0
@@:
end if
 
 
still:
cmp [edit_flag],1
jne @f
122,7 → 133,16
mov ebx,111b
.int:
int 0x40
if Ext > SSE2
cmp [ray_shd_flag],1
jne @f
cmp [isSSE3],1
jne @f
mov eax,10
jmp .intt
end if
 
@@:
mov eax,23
mov ebx,TIMEOUT
cmp [speed_flag],0
134,6 → 154,7
mov eax,10
 
@@:
.intt:
int 0x40
 
cmp eax,1 ; redraw event ?
263,8 → 284,9
jne .next_m5 ; 'grd ' 1
call make_random_lights ; 'env ' 2
call normalize_all_light_vectors ; 'bump' 3
call copy_lights
if Ext >= SSE3
call copy_lights
call init_point_lights ; for ex. ray casting
end if
call do_color_buffer ; intit color_map ; 'tex ' 4
 
396,7 → 418,7
cmp [move_flag],0
jne @f
.x_minus:
sub [vect_x],10
sub word[vect_x],10
jmp .next2
@@:
cmp [move_flag],1
414,7 → 436,7
cmp [move_flag],0
jne @f
.x_plus:
add [vect_x],10
add word[vect_x],10
jmp .next3
@@:
cmp [move_flag],1
522,8 → 544,6
.no_sort:
cmp [dr_flag],7 ; fill if 2tex and texgrd
jge @f
cmp [catmull_flag],0 ;non fill if Catmull = off
je .non_f
cmp [dr_flag],6 ; non fill if dots
je .non_f
@@:
534,43 → 554,71
call draw_dots
jmp .blurrr
@@:
if Ext > SSE2
cmp [ray_shd_flag],1 ;non fill if Catmull = off
jne @f
cmp [isSSE3],1
jne @f
mov ax,100
jmp .dr
@@:
end if
 
movzx ax,[dr_flag]
.dr:
call draw_triangles ; draw all triangles from the list
cmp [edit_flag],0
jz .no_edit
call clear_vertices_index
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
call draw_handlers
; call edit
 
 
 
 
 
 
.no_edit:
 
.blurrr:
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
cmp [sinus_flag],0
je @f
je .no_sin
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
call do_sinus
; jmp .finito
.no_sin:
@@:
cmp [fire_flag],0
jne @f
movzx ecx,[fire_flag]
cmp [fire_flag],1
je @f
cmp [blur_flag],0
je .no_blur ; no blur, no fire
movzx ecx,[blur_flag]
call blur_screen ; blur and fire
jmp .no_blur
@@:
cmp [emboss_flag],0
jne .emb ; if emboss=true -> no fire
movzx ecx,[fire_flag]
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
call blur_screen ; blur and fire
; jmp .finito
 
.no_blur: ; no blur, no fire
cmp [emboss_flag],0
je @f
.emb:
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
call do_emboss
 
.finito:
@@:
 
 
707,6 → 755,8
mov ebx,[screen_ptr]
mov ecx,[size_y_var]
mov edx,[offset_y]
cmp [ray_shd_flag],1
jge .ff
cmp [dr_flag],11
jge .ff
int 0x40
764,6 → 814,7
include '3stencil.inc'
include '3glass.inc'
include '3glass_tex.inc'
include '3ray_shd.inc'
end if
clear_vertices_index:
mov edi,[vertices_index_ptr]
1075,7 → 1126,7
fldpi
fadd st,st
mov esi,[points_ptr]
mov edi,tex_points
mov edi,[tex_points_ptr]
mov ecx,[points_count_var]
inc ecx
; cmp [map_tex_flag],1
1389,7 → 1440,8
mov esp,ebp
pop ebp
ret
if Ext >= SSE3
 
if Ext >= SSE2
init_point_normals:
.z equ dword [ebp-8]
.y equ dword [ebp-12]
1397,7 → 1449,6
.point_number equ dword [ebp-28]
.hit_faces equ dword [ebp-32]
 
fninit
push ebp
mov ebp,esp
sub esp,64
1438,19 → 1489,25
jne .ipn_check_face
cvtsi2ss xmm6,.hit_faces
movaps xmm7,.x
 
rcpss xmm6,xmm6
shufps xmm6,xmm6,11000000b
mulps xmm7,xmm6
movaps xmm6,xmm7
mulps xmm6,xmm6
andps xmm6,[zero_hgst_dd]
haddps xmm6,xmm6
haddps xmm6,xmm6
rsqrtps xmm6,xmm6
mulps xmm7,xmm6
movlps [edi],xmm7
movhlps xmm7,xmm7
movss [edi+8],xmm7
call normalize_vector
; movaps xmm6,xmm7
; mulps xmm6,xmm6
; andps xmm6,[zero_hgst_dd]
; haddps xmm6,xmm6
; haddps xmm6,xmm6
; rsqrtps xmm6,xmm6
; mulps xmm7,xmm6
; movlps [edi],xmm7
; movhlps xmm7,xmm7
; movss [edi+8],xmm7
 
add edi,12
inc .point_number
mov edx,.point_number
1576,11 → 1633,9
pop ecx
sub ecx,1
jnz @b
; cmp dword[ebp],-1
; jne @b
ret
 
if Ext >= SSE3
 
copy_lights: ; after normalising !
mov esi,lights
mov edi,lights_aligned
1610,8 → 1665,8
pop ecx
loop .again
ret
end if
 
 
clrscr:
mov edi,[screen_ptr]
movzx ecx,word[size_x_var]
1654,7 → 1709,37
 
 
draw_triangles:
; in: eax - render draw model
.tri_no equ dword[ebp-60]
.point_index3 equ [ebp-8]
.point_index2 equ [ebp-12]
.point_index1 equ [ebp-16]
.yy3 equ [ebp-18]
.xx3 equ [ebp-20]
.yy2 equ [ebp-22]
.xx2 equ [ebp-24]
.yy1 equ [ebp-26]
.xx1 equ [ebp-28]
 
.zz3 equ [ebp-30]
.zz2 equ [ebp-32]
.zz1 equ [ebp-34]
.index3x12 equ [ebp-38]
.index2x12 equ [ebp-42]
.index1x12 equ [ebp-46]
.temp1 equ dword[ebp-50]
.temp2 equ dword[ebp-54]
.dr_flag equ word[ebp-56]
 
 
push ebp
mov ebp,esp
sub esp,60
 
; movzx ax,[dr_flag]
mov .dr_flag,ax
 
 
emms
; update translated list MMX required
cmp [vertex_edit_no],0
1671,7 → 1756,8
movd dword[eax],mm1
@@:
if Ext >= SSE3
cmp [dr_flag],13
 
cmp .dr_flag,13
jnge .no_stencil
mov esi,[triangles_ptr]
mov ecx,[triangles_count_var]
1734,124 → 1820,57
je .draw_smooth_line
 
mov esi,[triangles_ptr]
mov ecx,[triangles_count_var]
xor ecx,ecx ;mov ecx,[triangles_count_var]
.again_dts:
; push ebp
push esi
push ecx
mov ebp,[points_translated_ptr]
if Ext >= SSE2
mov eax,dword[esi]
mov [point_index1],eax
lea eax,[eax*3]
add eax,eax
push ebp
add ebp,eax
mov eax,[ebp]
; cmp [vertex_edit_no],0
; jne @f
;
; @@:
mov dword[xx1],eax
mov eax,[ebp+4]
mov [zz1],ax
mov .tri_no,ecx
 
pop ebp
mov eax,[esi]
mov ebx,[esi+4]
mov ecx,[esi+8]
 
mov .point_index1,eax
mov .point_index2,ebx
mov .point_index3,ecx
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov .index1x12,eax
mov .index2x12,ebx
mov .index3x12,ecx
 
mov eax,dword[esi+4]
mov [point_index2],eax
lea eax,[eax*3]
add eax,eax
push ebp
add ebp,eax
mov eax,[ebp]
mov dword[xx2],eax
mov eax,[ebp+4]
mov [zz2],ax
pop ebp
shr eax,1
shr ebx,1
shr ecx,1
add eax,[points_translated_ptr]
add ebx,[points_translated_ptr]
add ecx,[points_translated_ptr]
push word[eax+4]
push word[ebx+4]
push word[ecx+4]
pop word .zz3
pop word .zz2
pop word .zz1
 
mov eax,[eax]
mov ebx,[ebx]
mov ecx,[ecx]
ror eax,16
ror ebx,16
ror ecx,16
mov .xx1,eax
mov .xx2,ebx
mov .xx3,ecx
 
mov eax,dword[esi+8] ; xyz3 = [ebp+[esi+4]*6]
mov [point_index3],eax
lea eax,[eax*3]
add eax,eax
; push ebp
add ebp,eax
mov eax,[ebp]
mov dword[xx3],eax
mov eax,[ebp+4]
mov [zz3],ax
else
movq mm0,[esi] ; don't know MMX
mov qword[point_index1],mm0
; shr eax,16
; mov [point_index2],ax
mov eax,dword[esi+8]
mov [point_index3],eax
movdqu xmm0,[esi]
paddd xmm0,xmm0
movdqa xmm1,xmm0
paddd xmm0,xmm0
paddd xmm0,xmm1
movd eax,xmm0
psrldq xmm0,4
movd ebx,xmm0
psrldq xmm0,4
movd ecx,xmm0
and eax,0FFFFh
and ebx,0FFFFh
and ecx,0FFFFh
movq mm0,[ebp+eax]
movq mm1,[ebp+ebx]
movq mm2,[ebp+ecx]
movq qword[xx1],mm0
movq qword[xx2],mm1
movq qword[xx3],mm2
; emms
end if ; *********************************
if 0
cmp [vertex_edit_no],0
jne .no_edit
mov ax,[vertex_edit_no]
dec ax
cmp ax,[point_index1]
jne @f
movd mm0,[edit_start_x]
psubw mm0,[edit_end_x]
movd mm1,dword[xx1]
paddw mm1,mm0
movd dword[xx1],mm1
jmp .no_edit
@@:
 
cmp ax,[point_index2]
jne @f
movd mm0,[edit_start_x]
psubw mm0,[edit_end_x]
movd mm1,dword[xx2]
paddw mm1,mm0
movd dword[xx2],mm1
jmp .no_edit
@@:
 
cmp ax,[point_index3]
jne @f
movd mm0,[edit_start_x]
psubw mm0,[edit_end_x]
movd mm1,dword[xx3]
paddw mm1,mm0
movd dword[xx3],mm1
jmp .no_edit
@@:
 
 
.no_edit:
end if
 
push esi ;
; push esi
fninit ; DO culling AT FIRST
cmp [culling_flag],1 ; (if culling_flag = 1)
jne .no_culling
mov esi,point_index1 ; *********************************
lea esi,.point_index1 ; *********************************
mov ecx,3 ;
@@:
mov eax,dword[esi]
1858,76 → 1877,77
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr]
; lea eax,[eax+point_normals_rotated]
fld dword[eax+8] ; *****************************
ftst ; CHECKING OF Z COOFICIENT OF
fstsw ax ; NORMAL VECTOR
sahf
jb @f
ffree st
mov eax,[eax+8]
bt eax,31
jc @f
; *****************************
; CHECKING OF Z COOFICIENT OF
; NORMAL VECTOR
add esi,4
loop @b
jmp .end_draw ; non visable
@@:
ffree st ;is visable
 
.no_culling:
cmp [dr_flag],0 ; draw type flag
cmp .dr_flag,0 ; draw type flag
je .flat_draw
cmp [dr_flag],2
cmp .dr_flag,2
je .env_mapping
cmp [dr_flag],3
cmp .dr_flag,3
je .bump_mapping
cmp [dr_flag],4
cmp .dr_flag,4
je .tex_mapping
cmp [dr_flag],5
cmp .dr_flag,5
je .rainbow
cmp [dr_flag],7
cmp .dr_flag,7
je .grd_tex
cmp [dr_flag],8
cmp .dr_flag,8
je .two_tex
cmp [dr_flag],9
cmp .dr_flag,9
je .bump_tex
cmp [dr_flag],10
cmp .dr_flag,10
je .cubic_env_mapping
cmp [dr_flag],11
cmp .dr_flag,11
je .draw_smooth_line
if Ext >= SSE3
cmp [dr_flag],12
cmp .dr_flag,12
je .r_phg
cmp [dr_flag],13
cmp .dr_flag,13
je .glass
cmp [dr_flag],14
cmp .dr_flag,14
je .glass_tex
end if ; ****************
mov esi,point_index3 ; do Gouraud shading
cmp .dr_flag,100
je .ray_shd
 
end if
 
push ebp ; ****************
lea esi,.index3x12 ; do Gouraud shading
lea edi,.zz3
mov ecx,3
.again_grd_draw:
mov eax,dword[esi]
shl eax,2
lea eax,[eax*3]
add eax,[points_normals_rot_ptr]
; texture x=(rotated point normal -> x * 255)+255
fld dword[eax] ; x cooficient of normal vector
fimul [correct_tex]
fiadd [correct_tex]
fistp [temp1]
fistp .temp1
; texture y=(rotated point normal -> y * 255)+255
fld dword[eax+4] ; y cooficient
fimul [correct_tex]
fiadd [correct_tex]
fistp [temp2]
fistp .temp2
 
mov eax,[temp2]
mov ebx,[temp1]
mov eax,.temp2
mov ebx,.temp1
and ebx,0xfffffff
shl eax,TEX_SHIFT
add eax,ebx
lea eax,[eax*3+color_map]
mov eax,dword[eax]
; cmp [catmull_flag],1 ; put on stack z coordinate if necessary
; jne @f
lea edx,[ecx*3]
push word[edx*2+xx1-2] ; zz1 ,2 ,3
; @@:
push word[edi] ; zz1 ,2 ,3
 
ror eax,16 ; eax -0xxxrrggbb -> 0xggbbxxrr
xor ah,ah
push ax ;r
1938,98 → 1958,55
push ax ;b
 
sub esi,4
sub edi,2
dec cx
jnz .again_grd_draw
jmp .both_draw
 
; movzx edi,[point_index3] ;gouraud shading according to light vector
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
.rainbow:
push ebp
push word .zz3
 
; movzx edi,[point_index2]
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
 
; movzx edi,[point_index1]
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
.rainbow:
; cmp [catmull_flag],1 ; put on stack z coordinate if necessary
; jne @f
push [zz3]
@@:
mov eax,dword[yy3]
mov eax, .xx3
ror eax,16
mov ebx,0x00ff00ff
and eax,ebx
push eax
neg al
push ax
push [zz2]
push word .zz2
 
mov eax,dword[yy2]
mov eax, .xx2
ror eax,16
and eax,ebx
push eax
neg al
push ax
push [zz1]
push word .zz1
 
mov eax,dword[yy1]
mov eax, .xx1
ror eax,16
and eax,ebx
push eax
neg al
push ax
.both_draw:
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
call gouraud_triangle_z
pop ebp
jmp .end_draw
 
.flat_draw: ;**************************
fninit ; FLAT DRAWING
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
shl eax,2
shl ebx,2
shl ecx,2
lea eax,[eax*3] ;+point_normals_rotated]
mov eax,.index1x12
mov ebx,.index2x12
mov ecx,.index3x12
add eax,[points_normals_rot_ptr]
lea ebx,[ebx*3] ;+point_normals_rotated]
add ebx,[points_normals_rot_ptr]
lea ecx,[ecx*3] ;+point_normals_rotated]
add ecx,[points_normals_rot_ptr]
fld dword[eax] ; x cooficient of normal vector
fadd dword[ebx]
2037,7 → 2014,7
fidiv [i3]
fimul [correct_tex]
fiadd [correct_tex]
fistp [temp1] ;dword[esp-4] ; x temp variables
fistp .temp1 ;dword[esp-4] ; x temp variables
fld dword[eax+4] ; y cooficient of normal vector
fadd dword[ebx+4]
fadd dword[ecx+4]
2044,12 → 2021,12
fidiv [i3]
fimul [correct_tex]
fiadd [correct_tex]
fistp [temp2] ;dword[esp-8] ; y
mov edx,[temp2] ;dword[esp-8]
fistp .temp2 ;dword[esp-8] ; y
mov edx,.temp2 ;dword[esp-8]
and edx,0xfffffff
and [temp1],0xfffffff
and .temp1,0xfffffff
shl edx,TEX_SHIFT
add edx,[temp1] ;dword[esp-4]
add edx,.temp1 ;dword[esp-4]
 
lea eax,[3*edx]
add eax,color_map
2071,34 → 2048,32
; shl eax,8
; mov edx,eax
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edi,[screen_ptr]
 
mov esi,[Zbuffer_ptr]
push word[zz3]
push word[zz2]
push word[zz1]
push ebp
push word .zz3
push word .zz2
push word .zz1
call flat_triangle_z
pop ebp
jmp .end_draw
 
.env_mapping:
push [zz3]
push [zz2]
push [zz1]
push ebp
push word .zz3
push word .zz2
push word .zz1
 
mov esi,point_index1
lea esi, .index1x12
sub esp,12
mov edi,esp
mov ecx,3
@@:
mov eax,dword[esi]
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr] ;point_normals_rotated
; texture x=(rotated point normal -> x * 255)+255
fld dword[eax]
2115,33 → 2090,29
add esi,4
loop @b
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax, .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edi,[screen_ptr]
mov esi,envmap
 
mov edx,[Zbuffer_ptr]
call tex_triangle_z
 
pop ebp
jmp .end_draw
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.cubic_env_mapping:
push [zz3]
push [zz2]
push [zz1]
push ebp
push word .zz3
push word .zz2
push word .zz1
 
mov esi,point_index1
lea esi,.index1x12
sub esp,12
mov edi,esp
mov ecx,3
@@:
mov eax,dword[esi]
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr]
 
fld dword[eax]
2171,37 → 2142,32
add esi,4
loop @b
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov edi,[screen_ptr]
mov esi,envmap_cub
mov edx,[Zbuffer_ptr]
 
call tex_triangle_z
 
pop ebp
jmp .end_draw
 
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
.bump_mapping:
 
push ebp
push [Zbuffer_ptr]
push [zz3]
push [zz2]
push [zz1]
push word .zz3
push word .zz2
push word .zz1
 
mov esi,point_index1
lea esi,.index1x12
sub esp,12
mov edi,esp
mov ecx,3
@@:
mov eax,dword[esi]
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr] ;point_normals_rotated
; texture x=(rotated point normal -> x * 255)+255
fld dword[eax]
2218,70 → 2184,58
add esi,4
loop @b
 
mov esi,[point_index3] ; bump map coords
mov esi, .point_index3 ; bump map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index2]
mov esi, .point_index2
shl esi,2
add esi,tex_points
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
add esi,[tex_points_ptr]
push dword[esi]
; push dword[xx2]
mov esi,[point_index1]
mov esi, .point_index1
shl esi,2
add esi,tex_points
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
add esi,[tex_points_ptr]
push dword[esi]
; push dword[xx1]
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edi,[screen_ptr]
mov esi,envmap
mov edx,bumpmap ;BUMP_MAPPING
 
call bump_triangle_z
 
pop ebp
jmp .end_draw
 
.tex_mapping:
 
push [zz3]
push [zz2]
push [zz1]
push ebp
push word .zz3
push word .zz2
push word .zz1
; @@:
mov esi,[point_index3] ; tex map coords
mov esi, .point_index3 ; tex map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index2]
mov esi, .point_index2
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index1]
mov esi, .point_index1
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edi,[screen_ptr]
mov esi,texmap
mov edx,[Zbuffer_ptr]
 
call tex_triangle_z
 
pop ebp
jmp .end_draw
; .ray:
; grd_triangle according to points index
2319,49 → 2273,43
 
.grd_tex: ; smooth shading + texture
push ebp
mov ebp,esp
sub esp,4
push ebp
 
mov esi,[point_index3] ; tex map coords
mov esi, .point_index3 ; tex map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi] ; texture coords as first
mov esi,[point_index2] ; group of parameters
mov esi, .point_index2 ; group of parameters
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index1]
mov esi, .point_index1
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
 
mov esi,point_index3
lea esi, .index3x12
lea edi, .zz3
mov ecx,3
 
.aagain_grd_draw:
 
lea edx,[ecx*3]
push word[edx*2+xx1-2] ; zz1 ,2 ,3
push word[edi] ; zz1 ,2 ,3
fninit
mov eax,dword[esi]
shl eax,2
lea eax,[eax*3] ;+point_normals_rotated]
add eax,[points_normals_rot_ptr]
; texture x=(rotated point normal -> x * 255)+255
fld dword[eax] ; x cooficient of normal vector
fimul [correct_tex]
fiadd [correct_tex]
fistp [temp1] ;word[ebp-2]
fistp .temp1 ;word[ebp-2]
; texture y=(rotated point normal -> y * 255)+255
fld dword[eax+4] ; y cooficient
fimul [correct_tex]
fiadd [correct_tex]
fistp [temp2] ;word[ebp-4]
fistp .temp2 ;word[ebp-4]
 
mov eax,[temp2] ;word[ebp-4]
mov ebx,[temp1] ;word[ebp-2]
and ebx,0xfffffff ; some onjects need thid 'and'
mov eax,.temp2
mov ebx,.temp1
and ebx,0xfffffff ; some onjects need this 'and'
shl eax,TEX_SHIFT
add eax,ebx
lea eax,[eax*3]
2376,17 → 2324,14
push ax ;g
shr eax,24
push ax ;b
 
sub edi,2
sub esi,4
dec cx
jnz .aagain_grd_draw
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov edi,[screen_ptr]
mov edx,texmap
mov esi,[Zbuffer_ptr]
2394,31 → 2339,30
call tex_plus_grd_triangle
 
pop ebp
mov esp,ebp
pop ebp
jmp .end_draw
 
.two_tex:
push ebp
push [Zbuffer_ptr]
 
push word[zz3]
push word[zz2]
push word[zz1]
push word .zz3
push word .zz2
push word .zz1
 
mov esi,[point_index3] ; tex map coords
mov esi, .point_index3 ; tex map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index2]
mov esi, .point_index2
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index1]
mov esi, .point_index1
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
 
mov esi,point_index1 ; env coords
lea esi, .point_index1 ; env coords
sub esp,12
mov edi,esp
mov ecx,3
2443,50 → 2387,46
add esi,4
loop @b
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov edi,[screen_ptr]
mov esi,texmap
mov edx,envmap
 
call two_tex_triangle_z
pop ebp
jmp .end_draw
 
.bump_tex:
mov esi,[point_index3] ; tex map coords
push ebp
mov esi, .point_index3 ; tex map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index2]
mov esi, .point_index2
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index1]
mov esi, .point_index1
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
 
push dword texmap
 
push [Zbuffer_ptr]
xor edi,edi
 
push word[zz3]
push word[zz2]
push word[zz1]
push word .zz3
push word .zz2
push word .zz1
 
mov esi,point_index1 ; env coords
lea esi, .index1x12 ; env coords
sub esp,12
mov edi,esp
mov ecx,3
@@:
mov eax,dword[esi]
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr]
; texture x=(rotated point normal -> x * 255)+255
fld dword[eax]
2503,40 → 2443,28
add esi,4
loop @b
 
; push dword 1 shl 16 + 1 ; emap coords
; push dword 127 shl 16 + 1
; push dword 127 shl 16 + 127
 
mov esi,[point_index3] ; bump map coords
mov esi, .point_index3 ; bump map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index2]
mov esi, .point_index2
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
 
mov esi,[point_index1]
mov esi, .point_index1
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
 
; push dword 1 shl 16 + 127
; push dword 127 shl 16 + 127
; push dword 1 shl 16 + 1 ; bump coords
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edi,[screen_ptr]
mov esi,envmap
mov edx,bumpmap
 
call bump_tex_triangle_z
 
pop ebp
jmp .end_draw
 
 
2549,12 → 2477,9
pshufd xmm5,xmm5,01110011b
 
 
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
2566,12 → 2491,9
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
2584,12 → 2506,9
 
 
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
 
2603,12 → 2522,9
pshufd xmm5,xmm5,01110011b
 
 
mov eax,[point_index1]
mov ebx ,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
2620,12 → 2536,9
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
2638,12 → 2551,9
 
 
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov edi,[screen_ptr]
mov edx,[Zbuffer_ptr]
mov esi,[Zbuffer_ptr]
2657,12 → 2567,9
punpcklwd xmm5,[the_zero]
pshufd xmm5,xmm5,01110011b
 
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
2674,12 → 2581,9
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
2690,17 → 2594,17
add esp,12
andps xmm4,[zero_hgst_dd]
 
mov esi,[point_index3] ; tex map coords
mov esi,.point_index3 ; tex map coords
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index2]
mov esi,.point_index2
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
mov esi,[point_index1]
mov esi,.point_index1
shl esi,2
add esi,tex_points
add esi,[tex_points_ptr]
push dword[esi]
movups xmm6,[esp]
add esp,12
2714,31 → 2618,84
por xmm6,xmm7
 
 
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edx,texmap
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
 
call glass_tex_tri
jmp .end_draw
 
.ray_shd:
emms
movd xmm5,[size_y_var]
punpcklwd xmm5,[the_zero]
pshufd xmm5,xmm5,01110011b
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
movups xmm0,[eax]
movups xmm1,[ebx]
movups xmm2,[ecx]
andps xmm0,[zero_hgst_dd]
andps xmm1,[zero_hgst_dd]
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
; mov ebx,.tri_no
; cmp ebx,0
; je @f
; int3
; @@:
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
push dword[ecx+8]
push dword[ebx+8]
push dword[eax+8]
movups xmm4,[esp]
add esp,12
andps xmm4,[zero_hgst_dd]
 
movd mm7,.tri_no
 
; mm7 - intialised
 
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov edx,texmap
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
 
call ray_shad
 
 
 
end if
 
.end_draw:
; pop ebp
pop ecx
pop esi
 
add esi,12
inc ecx
cmp ecx,[triangles_count_var]
jnz .again_dts
 
pop ecx
dec ecx
jmp .eend
 
jnz .again_dts
ret
 
 
.draw_smooth_line:
2789,7 → 2746,8
sub esp,16
movups [esp],xmm1
add esi,4
loop .aga_n
dec ecx
jnz .aga_n
 
movups xmm0,[esp]
movups xmm1,[esp+16]
2807,11 → 2765,17
movhps xmm7,[edx]
pshufd xmm7,xmm7,11101000b
movdqa xmm6,xmm7
movdqa xmm3,xmm7
movdqa xmm4,xmm7
movd xmm5,[size_y_var]
pshuflw xmm5,xmm5,00010001b
pcmpeqw xmm3,xmm5
pcmpeqw xmm4,[the_zero]
pcmpgtw xmm7,xmm5
pcmpgtw xmm6,[the_zero]
pxor xmm7,xmm6
pxor xmm3,xmm4
pxor xmm7,xmm3
pmovmskb eax,xmm7
cmp al,-1
jnz .skp
2851,6 → 2815,15
cmp ecx,[edges_count]
jnz .again_s_line
 
 
 
 
 
 
.eend:
add esp,60
pop ebp
 
ret
 
 
2858,8 → 2831,9
 
 
 
 
draw_handlers:
 
; in eax - render model
push ebp
mov ebp,esp
 
2866,14 → 2840,15
.counter equ ebp-16
.xres3m18 equ ebp-8
.xres2m12 equ ebp-12
.dr_model equ dword[ebp-4]
 
 
; init counter
sub esp,12
push dword 0
 
mov .dr_model,eax
movzx eax,word[size_x_var]
cmp [dr_flag],12
cmp .dr_model,12
jge @f
lea ebx,[eax*3]
sub ebx,18
2931,7 → 2906,7
add eax,ebx
push eax
lea edi,[eax*3]
cmp [dr_flag],12
cmp .dr_model,12
jl @f
add edi,[esp]
@@:
2956,7 → 2931,7
mov byte[edi+2],0xff ;al
mov word[eax],dx
add eax,2
cmp [dr_flag],12
cmp .dr_model,12
jl @f
add edi,4
loop .do
3226,7 → 3201,6
.exit:
mov dword[edi],-1
ret
 
alloc_mem_for_tp:
mov eax, 68
cmp [re_alloc_flag],1
3293,7 → 3267,15
mov [points_rotated_ptr], eax
 
mov eax, 68
mov ebx, 12
mov ecx, [points_count_var]
shl ecx,2
mov edx,[tex_points_ptr]
int 0x40
mov [tex_points_ptr], eax
 
mov eax, 68
mov ecx, [points_count_var]
inc ecx
shl ecx, 3
mov edx,[points_translated_ptr]
3302,7 → 3284,6
ret
 
 
 
read_from_disk:
mov eax, 68
mov ebx, 11
3348,11 → 3329,11
mov edi,menu
.again:
mov eax,8 ; function 8 : define and draw button
mov bx,[size_x_var]
movzx ebx,word[size_x_var]
shl ebx,16
add ebx,(10)*65536+62 ; [x start] *65536 + [x size]
movzx ecx,byte[edi] ; button id = position+2
sub cl,2
sub ecx,2
lea ecx,[ecx*5]
lea ecx,[ecx*3]
add ecx,25
3364,10 → 3345,10
; BUTTON LABEL
mov eax,4 ; function 4 : write text to window
movzx ebx,byte[edi]
sub bl,2 ; button id, according to position
sub ebx,2 ; button id, according to position
lea ebx,[ebx*3]
lea ebx,[ebx*5]
mov cx,[size_x_var]
movzx ecx,word[size_x_var]
shl ecx,16
add ebx,ecx
add ebx,(12)*65536+28 ; [x start] *65536 + [y start]
3459,6 → 3440,9
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
movzx eax,[fire_flag]
push eax
; int3
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
3492,6 → 3476,7
; add edx,130*65536+60 ; [x start] *65536 + [y start]
; mov esi,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
; int 0x40
 
call write_info
 
; ADD VECTOR LABEL ; add vector buttons - 30 ++
3644,6 → 3629,8
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
pop eax
mov [fire_flag],al
ret