view3ds 0073 by macgub

git-svn-id: svn://kolibrios.org@8719 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2021-05-12 00:26:00 +00:00
parent 1c24cac315
commit 73122f1cb1
9 changed files with 7546 additions and 7756 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,327 +1,329 @@
ROUND2 equ 10
stencil_tri:
; procedure calculate triangle in stencil buffer
; ----------------in - eax - x1 shl 16 + y1 ----------------------
; -------------------- ebx - x2 shl 16 + y2 ----------------------
; -------------------- ecx - x3 shl 16 + y3 ----------------------
; -------------------- esi - pointer to s-buffer -----------------
; -------------------- xmm0 - lo -> hi z1, z2, z3 as dword float
.x1 equ [ebp-2]
.y1 equ [ebp-4]
.x2 equ [ebp-6]
.y2 equ [ebp-8]
.x3 equ [ebp-10]
.y3 equ [ebp-12]
.dx12 equ dword[ebp-20]
.dx13 equ dword[ebp-24]
.dx23 equ dword[ebp-28]
.dz12 equ dword[ebp-32]
.dz13 equ dword[ebp-36]
.dz23 equ dword[ebp-40]
.zz2 equ [ebp-44]
.zz1 equ [ebp-48]
.z3 equ [ebp-56]
.z2 equ [ebp-60]
.z1 equ [ebp-64]
.s_buff equ [ebp-68]
push ebp
mov ebp,esp
sub esp,128
and ebp,0xfffffff0
.sort2:
cmp ax,bx
jle .sort1
xchg eax,ebx
shufps xmm0,xmm0,11100001b
.sort1:
cmp bx,cx
jle .sort3
xchg ebx,ecx
shufps xmm0,xmm0,11011000b
jmp .sort2
.sort3:
mov .y1,eax ; store triangle coordinates in user friendly variables
mov .y2,ebx
mov .y3,ecx
; mov edx,100.11
; movd xmm0,edx
; shufps xmm0,xmm0,11100000b
movaps .z1,xmm0
; mov dword .z1,edx
; mov .z2,edx
; mov .z3,edx
mov .s_buff,esi
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .loop2_end
mov bx,.y2 ; calc delta 12
sub bx,.y1
jnz .dx12_make
mov .dx12,0
mov .dz12,0
jmp .dx12_done
.dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx12,eax
movss xmm1,.z2
cvtsi2ss xmm2,ebx
subss xmm1,.z1
divss xmm1,xmm2
movss .dz12,xmm1
; mov .dz12, dword 0.11
.dx12_done:
mov bx,.y3 ; calc delta 13
sub bx,.y1
jnz .dx13_make
mov .dx13,0
mov .dz13,0
jmp .dx13_done
.dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx13,eax
movss xmm1,.z3
cvtsi2ss xmm2,ebx
subss xmm1,.z1
divss xmm1,xmm2
movss .dz13,xmm1
; mov .dz13, dword 0.11
.dx13_done:
mov bx,.y3 ; calc delta 23
sub bx,.y2
jnz .dx23_make
mov .dx23,0
mov .dz23,0
jmp .dx23_done
.dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx23,eax
movss xmm1,.z3
cvtsi2ss xmm2,ebx
subss xmm1,.z2
divss xmm1,xmm2
movss .dz23,xmm1
.dx23_done:
mov edx,.z1
mov .zz1,edx
mov .zz2,edx
movsx eax,word .x1
shl eax,ROUND2 ; eax - cur x1
mov ebx,eax ; ebx - cur x2
mov cx,.y1
cmp cx,.y2
jge .loop1_end
.loop1:
pushad
sar ebx,ROUND2
sar eax,ROUND2
; movq xmm0,.zz1
movlps xmm0,.zz1
; mov edx,0.11
; movd xmm0,edx
; shufps xmm0,xmm0,11100000b
mov esi,.s_buff
call stencil_line
popad
add eax,.dx13
add ebx,.dx12
movss xmm1,.zz1
movss xmm2,.zz2
addss xmm1,.dz13
addss xmm2,.dz12
movss .zz1,xmm1
movss .zz2,xmm2
add cx,1
cmp cx,.y2
jl .loop1
.loop1_end:
mov edx,.z2
mov .zz2,edx
movsx ebx,word .x2
shl ebx,ROUND2
mov cx,.y2
cmp cx,.y3
jge .loop2_end
.loop2:
pushad
sar ebx,ROUND2
sar eax,ROUND2
movlps xmm0,.zz1
mov esi,.s_buff
call stencil_line
popad
add eax,.dx13
add ebx,.dx23
movss xmm1,.zz1
movss xmm2,.zz2
addss xmm1,.dz13
addss xmm2,.dz23
movss .zz1,xmm1
movss .zz2,xmm2
add cx,1
cmp cx,.y3
jl .loop2
.loop2_end:
add esp,128
pop ebp
ret
stencil_line:
;----------------------------------------------------
;-------------in xmm0 - lo -> hi z1, z2
;--------------- eax - x1 ---------------------------
;--------------- ebx - x2 ---------------------------
;--------------- ecx - y-----------------------------
;--------------- esi - pointer to s-buffer
.dz equ [ebp-4]
.z2 equ [ebp-8]
.z1 equ [ebp-12]
.x2 equ [ebp-16]
.x1 equ [ebp-20]
.s_buf equ [ebp-24]
; cmp eax,ebx
; je @f
; int3
; @@:
push ebp
mov ebp,esp
sub esp,64
; cmp eax,0
; jg @f
;
; @@:
or cx,cx
jle .l_quit
cmp cx,[size_y_var]
jge .l_quit
movzx ecx,cx
mov .s_buf,esi
cmp eax,ebx
je .l_quit
jl .l_ok
xchg eax,ebx
shufps xmm0,xmm0,11100001b
.l_ok:
cmp ax,[size_x_var]
jge .l_quit
cmp bx,0
jle .l_quit
movlps .z1,xmm0
mov .x1,eax
mov .x2,ebx
sub ebx,eax
movss xmm0,.z2
cvtsi2ss xmm1,ebx
subss xmm0,.z1
divss xmm0,xmm1
movss .dz,xmm0
movzx edx,word[size_x_var]
cmp eax,1
jge @f
mov eax,.x1
neg eax
cvtsi2ss xmm2,eax
mulss xmm2,.dz
addss xmm2,.z1
movss .z1,xmm2
mov dword .x1,0
movzx edx,word[size_x_var]
sub edx,1
@@:
cmp .x2,edx
jl @f
mov .x2,edx
@@:
; mov eax,.x1
; cmp .x2,eax
; je .l_quit
movzx edx,word[size_x_var]
mov esi,.s_buf
mov eax,ecx ; y
mul edx
add eax,.x1
shl eax,2
add esi,eax
mov ecx,.x2
sub ecx,.x1
movss xmm2,.z1 ; cz
.ccalc:
; movss xmm1,xmm2
comiss xmm2,dword[esi]
jg @f
movss dword[esi],xmm2
@@:
add esi,4
addss xmm2,.dz
sub ecx,1
jnz .ccalc
.l_quit:
mov esp,ebp
pop ebp
ret
ROUND2 equ 10
stencil_tri:
; procedure calculate triangle in stencil buffer
; ----------------in - eax - x1 shl 16 + y1 ----------------------
; -------------------- ebx - x2 shl 16 + y2 ----------------------
; -------------------- ecx - x3 shl 16 + y3 ----------------------
; -------------------- esi - pointer to s-buffer -----------------
; -------------------- xmm0 - lo -> hi z1, z2, z3 as dword float
.x1 equ [ebp-2]
.y1 equ [ebp-4]
.x2 equ [ebp-6]
.y2 equ [ebp-8]
.x3 equ [ebp-10]
.y3 equ [ebp-12]
.dx12 equ dword[ebp-20]
.dx13 equ dword[ebp-24]
.dx23 equ dword[ebp-28]
.dz12 equ dword[ebp-32]
.dz13 equ dword[ebp-36]
.dz23 equ dword[ebp-40]
.zz2 equ [ebp-44]
.zz1 equ [ebp-48]
.z3 equ [ebp-56]
.z2 equ [ebp-60]
.z1 equ [ebp-64]
.s_buff equ [ebp-68]
push ebp
mov ebp,esp
sub esp,128
and ebp,0xfffffff0
.sort2:
cmp ax,bx
jle .sort1
xchg eax,ebx
shufps xmm0,xmm0,11100001b
.sort1:
cmp bx,cx
jle .sort3
xchg ebx,ecx
shufps xmm0,xmm0,11011000b
jmp .sort2
.sort3:
mov .y1,eax ; store triangle coordinates in user friendly variables
mov .y2,ebx
mov .y3,ecx
; mov edx,100.11
; movd xmm0,edx
; shufps xmm0,xmm0,11100000b
movaps .z1,xmm0
; mov dword .z1,edx
; mov .z2,edx
; mov .z3,edx
mov .s_buff,esi
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .loop2_end
mov bx,.y2 ; calc delta 12
sub bx,.y1
jnz .dx12_make
mov .dx12,0
mov .dz12,0
jmp .dx12_done
.dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx12,eax
movss xmm1,.z2
cvtsi2ss xmm2,ebx
subss xmm1,.z1
divss xmm1,xmm2
movss .dz12,xmm1
; mov .dz12, dword 0.11
.dx12_done:
mov bx,.y3 ; calc delta 13
sub bx,.y1
jnz .dx13_make
mov .dx13,0
mov .dz13,0
jmp .dx13_done
.dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx13,eax
movss xmm1,.z3
cvtsi2ss xmm2,ebx
subss xmm1,.z1
divss xmm1,xmm2
movss .dz13,xmm1
; mov .dz13, dword 0.11
.dx13_done:
mov bx,.y3 ; calc delta 23
sub bx,.y2
jnz .dx23_make
mov .dx23,0
mov .dz23,0
jmp .dx23_done
.dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND2
cdq
idiv ebx
mov .dx23,eax
movss xmm1,.z3
cvtsi2ss xmm2,ebx
subss xmm1,.z2
divss xmm1,xmm2
movss .dz23,xmm1
.dx23_done:
mov edx,.z1
mov .zz1,edx
mov .zz2,edx
movsx eax,word .x1
shl eax,ROUND2 ; eax - cur x1
mov ebx,eax ; ebx - cur x2
mov cx,.y1
cmp cx,.y2
jge .loop1_end
.loop1:
pushad
sar ebx,ROUND2
sar eax,ROUND2
; movq xmm0,.zz1
movlps xmm0,.zz1
; mov edx,0.11
; movd xmm0,edx
; shufps xmm0,xmm0,11100000b
mov esi,.s_buff
call stencil_line
popad
add eax,.dx13
add ebx,.dx12
movss xmm1,.zz1
movss xmm2,.zz2
addss xmm1,.dz13
addss xmm2,.dz12
movss .zz1,xmm1
movss .zz2,xmm2
add cx,1
cmp cx,.y2
jl .loop1
.loop1_end:
mov edx,.z2
mov .zz2,edx
movsx ebx,word .x2
shl ebx,ROUND2
mov cx,.y2
cmp cx,.y3
jge .loop2_end
.loop2:
pushad
sar ebx,ROUND2
sar eax,ROUND2
movlps xmm0,.zz1
mov esi,.s_buff
call stencil_line
popad
add eax,.dx13
add ebx,.dx23
movss xmm1,.zz1
movss xmm2,.zz2
addss xmm1,.dz13
addss xmm2,.dz23
movss .zz1,xmm1
movss .zz2,xmm2
add cx,1
cmp cx,.y3
jl .loop2
.loop2_end:
add esp,128
pop ebp
ret
stencil_line:
;----------------------------------------------------
;-------------in xmm0 - lo -> hi z1, z2
;--------------- eax - x1 ---------------------------
;--------------- ebx - x2 ---------------------------
;--------------- ecx - y-----------------------------
;--------------- esi - pointer to s-buffer
.dz equ [ebp-4]
.z2 equ [ebp-8]
.z1 equ [ebp-12]
.x2 equ [ebp-16]
.x1 equ [ebp-20]
.s_buf equ [ebp-24]
; cmp eax,ebx
; je @f
; int3
; @@:
push ebp
mov ebp,esp
sub esp,64
; cmp eax,0
; jg @f
;
; @@:
or cx,cx
jle .l_quit
cmp cx,[size_y_var]
jge .l_quit
movzx ecx,cx
mov .s_buf,esi
cmp eax,ebx
je .l_quit
jl .l_ok
xchg eax,ebx
shufps xmm0,xmm0,11100001b
.l_ok:
cmp ax,[size_x_var]
jge .l_quit
cmp bx,0
jle .l_quit
movlps .z1,xmm0
mov .x1,eax
mov .x2,ebx
sub ebx,eax
movss xmm0,.z2
cvtsi2ss xmm1,ebx
subss xmm0,.z1
divss xmm0,xmm1
movss .dz,xmm0
movzx edx,word[size_x_var]
cmp eax,1
jge @f
mov eax,.x1
neg eax
cvtsi2ss xmm2,eax
mulss xmm2,.dz
addss xmm2,.z1
movss .z1,xmm2
mov dword .x1,0
movzx edx,word[size_x_var]
sub edx,1
@@:
cmp .x2,edx
jl @f
mov .x2,edx
@@:
; mov eax,.x1
; cmp .x2,eax
; je .l_quit
movzx edx,word[size_x_var]
mov esi,.s_buf
mov eax,ecx ; y
mul edx
add eax,.x1
shl eax,2
add esi,eax
mov ecx,.x2
sub ecx,.x1
movss xmm2,.z1 ; cz
.ccalc:
movss xmm1,xmm2
cmpltss xmm1,dword[esi]
movd eax,xmm1
cmp eax,-1
jnz @f
movss dword[esi],xmm2
@@:
add esi,4
addss xmm2,.dz
sub ecx,1
jnz .ccalc
.l_quit:
mov esp,ebp
pop ebp
ret

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,643 +1,115 @@
;-procedure draws smooth shaded lines (I mean interpolation 24 bit--
;-color), with z coord interpolation--------------------------------
;-author: Maciej Guba (www.macgub.hekko.pl)-------------------------
;-in : -------------------------------------------------------------
;----- edi - pointer to screen buffer ------------------------------
;----- esi - pointer to Z buffer -----------------------------------
;------ constans : SIZE_X, SIZE_Y - screen width and height---------
;----------------- ROUND - fixed point shift------------------------
;------ other parameters via stack----------------------------------
smooth_line:
.x1 equ ebp+4
.y1 equ ebp+6
.z1 equ ebp+8
.r1 equ ebp+10
.g1 equ ebp+12
.b1 equ ebp+14
.x2 equ ebp+16
.y2 equ ebp+18
.z2 equ ebp+20
.r2 equ ebp+22
.g2 equ ebp+24
.b2 equ ebp+26
.line_lenght equ ebp-2
.delta equ ebp-6
.delta_x equ ebp-10
.delta_y equ ebp-14
.dr equ ebp-18
.dg equ ebp-22
.db equ ebp-26
.dz equ ebp-30
.cr equ ebp-34
.cg equ ebp-38
.cb equ ebp-42
.cz equ ebp-46
;.line_lenght equ ebp-48
.screen equ ebp-52
.zbuffer equ ebp-56
.ccoord equ ebp-60 ;current coordinate
.czbuf equ ebp-64
.cscr equ ebp-68
.xres equ ebp-72
.yres equ ebp-76
.xresm1 equ ebp-80
.yresm1 equ ebp-84
.xresp1 equ ebp-88
.yresp1 equ ebp-92
.xres3 equ ebp-96
.xres4 equ ebp-100
macro .update_cur_var
{
if Ext=NON
mov ebx,[.dz]
add [.cz],ebx
mov ebx,[.dr]
add [.cr],ebx
mov ebx,[.dg]
add [.cg],ebx
mov ebx,[.db]
add [.cb],ebx
elseif Ext=MMX
movq mm0,[.cz]
movq mm1,[.cg]
paddd mm0,mm2 ;[.dz]
paddd mm1,mm3 ;[.dg]
movq [.cz],mm0
movq [.cg],mm1
elseif Ext >= SSE2
; movups xmm1,[.cz]
paddd xmm1,xmm0
; movups [.cz],xmm1
end if
}
macro .draw_pixel
{
mov [esi],ebx ; actualize Z buffer
if Ext>=SSE2
movaps xmm7,xmm1 ;[.cb] ;;xmm1
shufps xmm7,xmm7,00111001b
psrld xmm7,ROUND
packssdw xmm7,xmm7
packuswb xmm7,xmm7
pand xmm7,xmm6 ;[.mask]
movd [edi],xmm7
else
mov eax,[.cb]
sar eax,ROUND
mov [edi],al
; and eax,0x000000ff ; clean unused bits
mov ebx,[.cg]
sar ebx,ROUND
mov [edi+1],bl
; mov ah,bl
mov edx,[.cr]
sar edx,ROUND
mov [edi+2],dl
end if
; shl ebx,16
; or eax,ebx
; mov [edi],eax
}
macro .sort
{
if Ext >= MMX
movq mm0,[.x1]
movq mm1,[.x2]
movq [.x1],mm1
movq [.x2],mm0
else
mov edx,[.x1]
xchg edx,[.x2]
mov [.x1],edx
mov edx,[.z1]
xchg edx,[.z2]
mov [.z1],edx
end if
mov edx,[.g1]
xchg edx,[.g2]
mov [.g1],edx
}
emms
mov ebp,esp
sub esp,128
mov eax,[.x1] ; check if parameters exceedes screen area
mov ebx,[.x2]
or eax,ebx
test eax,80008000h
jne .end_line
movzx edx,word [size_x_var]
mov [.xres],edx
dec edx
movzx ecx,word [size_y_var]
mov [.yres],ecx
dec ecx
cmp word[.x1],dx ;SIZE_X
jg .end_line
cmp word[.x2],dx ;SIZE_X
jg .end_line
cmp word[.y1],cx ;SIZE_Y
jg .end_line
cmp word[.y2],cx ;SIZE_Y
jg .end_line
mov edx,[.xres]
shl edx,2
mov [.xres4],edx
shr edx,2
lea edx,[edx*3]
mov [.xres3],edx
mov edx,[.xres]
mov ecx,[.yres]
dec edx
dec ecx
mov [.xresm1],edx
mov [.yresm1],ecx
add edx,2
add ecx,2
mov [.xresp1],edx
mov [.yresp1],ecx
mov [.screen],edi
mov cx,[.x1]
cmp cx,[.x2]
je .vertical_l
mov cx,[.y1]
cmp cx,[.y2]
je .horizontal_l
mov ax,[.x1]
sub ax,[.x2]
cmp ax,0
jg @f
neg ax ; calc absolute value
@@:
mov [.delta_x],ax
mov bx,[.y1]
sub bx,[.y2]
cmp bx,0
jg @f
neg bx
@@:
mov [.delta_y],bx
cmp ax,bx
je .deg45_l
jl .more_vertical_l
jg .more_horizon_l
jmp .end_line
;
.horizontal_l:
mov ax,[.x1]
mov bx,[.x2]
cmp bx,ax
jge @f
.sort
@@:
mov bx,[.x2]
sub bx,[.x1]
movsx ebx,bx
cmp ebx,0 ;line lenght equql 0
je .end_line
mov [.delta_x],ebx
call .calc_delta
mov eax,[.xres] ;SIZE_X
movsx ebx,word[.y1]
mul ebx
add esi,eax
lea eax,[eax*3]
add esi,eax
add edi,eax
movsx eax,word[.x1]
add esi,eax
lea eax,[eax*3]
add edi,eax
add esi,eax
mov ecx,[.delta_x]
movsx ebx,word[.r1]
shl ebx,ROUND
mov [.cr],ebx
movsx ebx,word[.g1]
shl ebx,ROUND
mov [.cg],ebx
movsx ebx,word[.b1]
shl ebx,ROUND
mov [.cb],ebx
movsx ebx,word[.z1]
shl ebx,ROUND
mov [.cz],ebx
if Ext >= SSE2
movups xmm1,[.cz]
end if
.hdraw:
if Ext >= SSE2
movd ebx,xmm1
else
mov ebx,[.cz]
end if
cmp [esi],ebx
jle .skip
.draw_pixel
.skip:
add edi,3
add esi,4
.update_cur_var
loop .hdraw
jmp .end_line
.vertical_l:
mov ax,[.y1]
cmp [.y2],ax
jge @f
.sort
@@:
mov bx,[.y2]
sub bx,[.y1]
movsx ebx,bx
cmp ebx,0
je .end_line
mov [.delta_y],ebx
call .calc_delta
mov eax,[.xres] ;SIZE_X
movsx ebx,word[.y1]
mul ebx
add esi,eax
lea eax,[eax*3]
add edi,eax
add esi,eax
movsx eax,word[.x1]
add esi,eax
lea eax,[eax*3]
add esi,eax
add edi,eax
mov ecx,[.delta_y]
movsx ebx,word[.r1]
shl ebx,ROUND
mov [.cr],ebx
movsx ebx,word[.g1]
shl ebx,ROUND
mov [.cg],ebx
movsx ebx,word[.b1]
shl ebx,ROUND
mov [.cb],ebx
movsx ebx,word[.z1]
shl ebx,ROUND
mov [.cz],ebx
if Ext >= SSE2
movups xmm1,[.cz]
end if
.v_draw:
if Ext >= SSE2
movd ebx,xmm1
else
mov ebx,[.cz]
end if
cmp [esi],ebx
jle @f
.draw_pixel
@@:
add edi,[.xres3]
add esi,[.xres4]
.update_cur_var
loop .v_draw
jmp .end_line
.deg45_l:
mov word[.line_lenght],ax
mov ax,[.x1]
cmp [.x2],ax
jge @f
.sort
@@:
mov bx,[.y2]
sub bx,[.y1]
movsx ebx,bx
cmp ebx,0
je .end_line
mov [.delta_y],ebx
mov bx,[.x2]
sub bx,[.x1]
movsx ebx,bx
mov [.delta_x],ebx
call .calc_delta
mov eax,[.xres]
movsx ebx,word[.y1] ;calc begin values in screen and Z buffers
mul ebx
lea ebx,[3*eax]
add edi,ebx
shl eax,2
add esi,eax
movsx eax,word[.x1]
lea ebx,[eax*3]
add edi,ebx
shl eax,2
add esi,eax
movzx ecx,word[.line_lenght]
movsx ebx,word[.r1]
shl ebx,ROUND
mov [.cr],ebx
movsx ebx,word[.g1]
shl ebx,ROUND
mov [.cg],ebx
movsx ebx,word[.b1]
shl ebx,ROUND
mov [.cb],ebx
movsx ebx,word[.z1]
shl ebx,ROUND
mov [.cz],ebx
.d45_draw:
if Ext >= SSE2
movd ebx,xmm1
else
mov ebx,[.cz]
end if
cmp [esi],ebx
jle @f
.draw_pixel
@@:
cmp dword[.delta_y],0
jl @f
add edi,[.xres3] ;SIZE_X*3+3
add edi,3
add esi,[.xres4] ;SIZE_X*4+4
add esi,4
jmp .d45_1
@@:
sub edi,[.xres3] ;(SIZE_X*3)-3
sub edi,3
sub esi,[.xres4] ;(SIZE_X*4)-4
sub esi,4
.d45_1:
.update_cur_var
loop .d45_draw
jmp .end_line
.more_vertical_l:
mov word[.line_lenght],bx
mov ax,[.y1]
cmp [.y2],ax
jge @f
.sort
@@:
mov bx,[.y2]
sub bx,[.y1]
movsx ebx,bx
cmp ebx,0
je .end_line ;=======================
mov [.delta_y],ebx
mov ax,[.x2]
sub ax,[.x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.delta],eax
call .calc_delta
mov eax,[.xres] ;SIZE_X
movsx ebx,word[.y1] ;calc begin values in screen and Z buffers
mul ebx
lea ebx,[3*eax]
add esi,ebx
add esi,eax
add edi,ebx
mov [.cscr],edi
mov [.czbuf],esi
movzx ecx,word[.line_lenght]
movsx ebx,word[.r1]
shl ebx,ROUND
mov [.cr],ebx
movsx ebx,word[.g1]
shl ebx,ROUND
mov [.cg],ebx
movsx ebx,word[.b1]
shl ebx,ROUND
mov [.cb],ebx
movsx ebx,word[.z1]
shl ebx,ROUND
mov [.cz],ebx
if Ext >= SSE2
movups xmm1,[.cz]
end if
movsx ebx,word[.x1]
shl ebx,ROUND
mov [.ccoord],ebx ; .ccoord -> x coordinate
.draw_m_v:
mov edi,[.cscr]
mov esi,[.czbuf]
mov eax,[.ccoord]
sar eax,ROUND
lea ebx,[eax*3]
add edi,ebx
add esi,ebx
add esi,eax
if Ext >= SSE2
movd ebx,xmm1
else
mov ebx,[.cz]
end if
cmp [esi],ebx
jle @f
.draw_pixel
@@:
mov eax,[.delta]
mov ebx,[.xres3]
add [.ccoord],eax
mov eax,[.xres4]
add dword[.cscr],ebx ;SIZE_X*3 ;
add dword[.czbuf],eax ;SIZE_X*4
.d_m_v1:
.update_cur_var
dec ecx
jnz .draw_m_v
jmp .end_line
.more_horizon_l:
mov word[.line_lenght],ax
mov ax,[.x1]
cmp [.x2],ax
jge @f
.sort
@@:
mov bx,[.x2]
sub bx,[.x1]
movsx ebx,bx
cmp ebx,0;=======================
je .end_line
mov [.delta_x],ebx
mov ax,[.y2]
sub ax,[.y1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.delta],eax
call .calc_delta
;calc begin values in screen and Z buffers
movsx ebx,word[.x1]
mov eax,ebx
add esi,ebx
lea ebx,[3*ebx]
add esi,ebx
add edi,ebx
mov [.cscr],edi
mov [.czbuf],esi
movzx ecx,word[.line_lenght]
movsx ebx,word[.r1]
shl ebx,ROUND
mov [.cr],ebx
movsx ebx,word[.g1]
shl ebx,ROUND
mov [.cg],ebx
movsx ebx,word[.b1]
shl ebx,ROUND
mov [.cb],ebx
movsx ebx,word[.z1]
shl ebx,ROUND
mov [.cz],ebx
if Ext >= SSE2
movups xmm1,[.cz]
end if
movsx ebx,word[.y1]
shl ebx,ROUND
mov [.ccoord],ebx ; .ccoord -> y coordinate
.draw_m_h:
mov edi,[.cscr]
mov esi,[.czbuf]
mov eax,[.ccoord] ; ccoord - cur y coordinate
sar eax,ROUND
mov ebx,[.xres] ;SIZE_X
mul ebx
add esi,eax
lea eax,[eax*3]
add esi,eax
add edi,eax
if Ext >= SSE2
movd ebx,xmm1
else
mov ebx,[.cz]
end if
cmp [esi],ebx
jle @f
.draw_pixel
@@:
mov eax,[.delta]
add [.ccoord],eax
add dword[.cscr],3 ;
add dword[.czbuf],4
.update_cur_var
dec ecx
jnz .draw_m_h
.end_line:
mov esp,ebp
ret 24
.calc_delta:
mov ax,[.z2]
sub ax,[.z1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dz],eax
mov ax,[.r2]
sub ax,[.r1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dr],eax
mov ax,[.g2]
sub ax,[.g1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dg],eax
mov ax,[.b2]
sub ax,[.b1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.db],eax
if Ext=MMX | Ext = SSE
movq mm2,[.dz]
movq mm3,[.dg]
else if Ext >= SSE2
movups xmm0,[.dz]
movups xmm6,[.mask]
end if
ret
.mask:
dq 0xffffffff00ffffff
dq 0xffffffffffffffff
; Line drawing procedure by Pablo Reda.
; Gouraud extension by Maciej Guba.
;****************************************************
line_grd: ; eax=x1 ebx=y1 ecx=x2 edx=y2
; xmm0 - color1 argb as 4 dword float
; xmm1 - color2 argb as 4 dword float
; xmm2 - z1 as dword float
; xmm3 - z2 as dword float
; mm0 - Z buffer
; mm1 - screen buffer
; mm2 - screen width
cmp ebx,edx
; je horizontal_grd
jg .noswap
xchg eax,ecx
xchg ebx,edx
movaps xmm7,xmm0
movaps xmm0,xmm1
movaps xmm1,xmm7
movaps xmm7,xmm2
movaps xmm2,xmm3
movaps xmm3,xmm7
.noswap:
cvtsi2ss xmm7,eax
cvtsi2ss xmm6,ebx
cvtsi2ss xmm5,ecx
cvtsi2ss xmm4,edx
subss xmm7,xmm5
subss xmm6,xmm4
andps xmm7,[abs_mask] ; 0x7fff
andps xmm6,[abs_mask] ; 0x7fff
maxss xmm7,xmm6 ; xmm7 - delta
shufps xmm7,xmm7,0
movaps xmm6,xmm3
rcpps xmm7,xmm7
subss xmm6,xmm2
mulss xmm6,xmm7 ; xmm6 - delta z
movaps xmm5,xmm1
subps xmm5,xmm0
mulps xmm5,xmm7 ; xmm5 - delta col argb
shl eax,16
shl ecx,16
sub eax,ecx
push ebx
push edx
sub ebx,edx
add ebx,1
cdq
idiv ebx
mov esi,eax
add ecx,$7fff
pop ebx
pop edx
.lineas:
mov eax,ecx
add eax,esi
push ebx
push eax
push edx
shr ecx,16
shr eax,16
call horizontal_grd
pop edx
pop ecx
pop ebx
add ebx,1
cmp ebx,edx
jle .lineas
ret
horizontal_grd: ; eax=x1 ebx=y1 ecx=x2
cmp ecx,eax
jg .m
xchg ecx,eax
.m:
sub ecx,eax
jnz .nn
add ecx,1
.nn:
movd edx,mm2
imul ebx,edx
add eax,ebx
movd edi,mm1
lea edi,[edi+eax*4]
push eax
push ebx
movd ebx,mm0
lea ebx,[ebx+eax*4]
.l:
; movss xmm4,xmm2 ; xmm2 - cur z
; cmpnltss xmm4,[ebx]
; movd eax,xmm4
; or eax,eax
; jnz @f
comiss xmm2,[ebx]
jng @f
movaps xmm4,xmm0 ; xmm0 - cur col
cvtps2dq xmm4,xmm4
packssdw xmm4,xmm4
packuswb xmm4,xmm4
movd [edi],xmm4
@@:
addss xmm2,xmm6
addps xmm0,xmm5
add edi,4
sub ecx,1
jnz .l
pop ebx
pop eax
ret

View File

@ -1,4 +1,14 @@
View3ds 0.072 - march 2021
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.
-----------------------------------------------------------------------------------
View3ds 0.071 - VIII 2020
1. New displaying model - glass - it's two pass rendering. First pass calculates
Z position of all front pixels, second render image with adding reflective

View File

@ -1,7 +1,12 @@
View3ds 0.072 - tiny viewer to .3ds and .asc files with several graphics
View3ds 0.073 - 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. 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
@ -26,21 +31,23 @@ Buttons description:
8. rand. light: Randomize 3 unlinear lights( so called Phong's illumination).
9. Blur: blur N times; N=0,1,2,3,4,5
10.11,12,13. loseless operations (rotary 90, 180 degrees).
12. emboss: Do emboss effect( flat bumps ), use 'bumps deep' button to do edges more deep.
12. emboss: Do emboss effect( flat bumps ), use 'bumps deep' button to do edges
more deep.
13. fire: do motion blur ( looks like fire ).
14. move: changes meaning x,y,z +/- buttons -> obj: moving object, camr: moving camera, wave: x,y +/- increase,
decrease wave effect frequency and amplitude.
14. move: changes meaning x,y,z +/- buttons -> obj: moving object, camr: moving
camera, wave: x,y +/- increase, decrease wave effect frequency and amplitude.
15. generate: Generates some objects: node, Thorn Crown, heart...
16. bumps: random, according to texture.
17. bumps deep -> create bumps deeper or lighter.
18. re-map tex -> re-map texture and bump map coordinates, to change spherical mapping
around axle use 'xchg' and 'mirror' buttons, then press 're-map tex' button.
18. re-map tex -> re-map texture and bump map coordinates, to change spherical
mapping around axle use 'xchg' and 'mirror' buttons, then press 're-map tex' button.
19. bright + -> increase picture brightness.
20. bright - -> decrease picture brightness.
21. wav effect -> do effect based sine function.
22. editor -> setting editing option. If is "on" then red bars are draw according to each vertex, Pressing
and moving left mouse button (cursor must be on handler)- change vertex position. If left mouse button
is released apply current position. You may also decrease whole handlers count by enable culling (using
appropriate button) - some back handlers become hidden.
22. editor -> setting editing option. If is "on" then red bars are draw according to each
vertex, Pressing and moving left mouse button (cursor must be on handler)- change
vertex position. If left mouse button is released apply current position. You may also
decrease whole handlers count by enable culling (using appropriate button) - some
back handlers become hidden.
Maciej Guba III 2021
Maciej Guba V 2021

File diff suppressed because it is too large Load Diff