Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9237 → Rev 9236

/programs/demos/view3ds/3ray_shd.inc
File deleted
/programs/demos/view3ds/3dmath.inc
4,108 → 4,13
vec_x equ 0
vec_y equ 4
vec_z equ 8
 
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
 
; 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 ------------------------
reverse_mx_3x3:
; esi - source matrix
; edi - desired reversed matrix
236,13 → 141,6
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
296,37 → 194,17
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 >= SSE2
if Ext >= SSE3
movups xmm0,[edi]
andps xmm0,[zero_hgst_dd]
movups xmm1,xmm0
mulps 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
haddps xmm0,xmm0
haddps xmm0,xmm0
rsqrtps xmm0,xmm0
mulps xmm0,xmm1
movlps [edi],xmm0
681,7 → 559,7
; packsdw xmm0,xmm0
; movq [edi]
fld dword[esi]
fiadd word[vect_x]
fiadd [vect_x]
fistp word[edi]
fld dword[esi+4]
fiadd [vect_y]
/programs/demos/view3ds/a_procs.inc
1,200 → 1,3
 
 
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
420,18 → 223,13
 
 
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,30
mov .dr_f,ax
 
sub esp,64
mov dword .x,0
mov dword .y,0
mov esi,[screen_ptr]
445,20 → 243,53
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
467,11 → 298,12
jg .skip
movzx edx,word[size_x_var]
mul edx
; shl eax,9
add eax,dword .x
 
lea ebx,[eax*3]
cmp .dr_f,12 ; 32 bit col cause
jb @f
cmp [dr_flag],12 ; 32 bit col cause
jl @f
add ebx,eax
@@:
mov eax,[esi]
478,8 → 310,8
mov [edi+ebx],eax
.skip:
add esi,3
cmp .dr_f,12
jb @f
cmp [dr_flag],12
jl @f
inc esi
@@:
inc dword .x
498,8 → 330,8
movzx ecx,word[size_x_var]
movzx eax,word[size_y_var]
imul ecx,eax
cmp .dr_f,12
jae @f
cmp [dr_flag],12
jge @f
lea ecx,[ecx*3]
shr ecx,2
; mov ecx,SIZE_X*SIZE_Y*3/4
545,19 → 377,7
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
572,13 → 392,13
sub ecx,ebx
mov esi,[screen_ptr]
mov edi,[Zbuffer_ptr]
cmp .dr_mod,11
cmp [dr_flag],12
jge @f
lea ebx,[ebx*3]
jmp .gf
jmp .f
@@:
shl ebx,2
.gf:
.f:
mov edx,esi
add esi,ebx
lea ebx,[ebx+esi]
585,7 → 405,7
pxor xmm0,xmm0
push eax
.emb:
cmp .dr_mod ,11
cmp [dr_flag],12
jge @f
movlps xmm1,[esi+3]
movhps xmm1,[esi+6]
622,7 → 442,14
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
642,7 → 469,7
mov eax,[eax]
mov [edi+4],eax
 
cmp .dr_mod,11
cmp [dr_flag],12
jl @f
add esi,2
add ebx,2
660,7 → 487,7
pop ecx ;,eax
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
cmp .dr_mod,11
cmp [dr_flag],12
jge .e
@@:
movsd
671,11 → 498,6
 
end if
 
 
 
mov esp,ebp
pop ebp
 
ret
 
;align 16
/programs/demos/view3ds/b_procs.inc
737,33 → 737,22
 
blur_screen: ;blur n times ; blur or fire
;in - ecx times count
; ax - render mode
 
.val equ dword[ebp-4]
.dr_model equ word[ebp-6]
.fire equ dword[ebp-10]
 
;.counter equ dword[esp-4]
.counter1 equ dword[esp-8]
if Ext>=SSE2
push ebp
mov ebp,esp
sub esp,10
; xorps xmm5,xmm5
; or edx,edx
; jz @f
mov .val,0x01010101
movss xmm5,.val
push dword 0x01010101
movss xmm5,[esp]
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_model,11
 
cmp [dr_flag],12
jge @f
lea ecx,[ecx*3+3]
lea ecx,[ecx*3+1]
shr ecx,2
@@:
 
774,7 → 763,7
movzx ecx,word[size_y_var]
sub ecx,3
imul ecx,ebx
cmp .dr_model,11 ; 32 bit per pix cause
cmp [dr_flag],12 ; 32 bit per pix cause
jge @f
lea ecx,[ecx*3]
shr ecx,4
792,7 → 781,7
mov ecx,edi
sub ecx,ebx
movups xmm1,[ecx]
cmp .dr_model,12
cmp [dr_flag],12
jge @f
movups xmm2,[edi-3]
movups xmm3,[edi+3]
813,9 → 802,9
end if
xor eax,eax
movzx ecx,word[size_x_var]
cmp .dr_model,11
cmp [dr_flag],12
jge @f
lea ecx,[ecx*3+3]
lea ecx,[ecx*3]
shr ecx,2
@@:
; mov ecx,SIZE_X*3/4
/programs/demos/view3ds/data.inc
1,7 → 1,5
; DATA AREA ************************************
if Ext > SSE2
isSSE3 db 1
end if
 
i3 dw 3
i6 dd 6
i12 dd 12
8,7 → 6,6
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
28,7 → 25,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:
113,9 → 110,9
dd ?
 
db 7
db 'ray shadow'
db 'catmull '
db 2
ray_shd_flag db 0
catmull_flag db 1
dd onoff_f
 
db 8
168,7 → 165,7
 
db 16
db 'fire '
db 2
db 3
fire_flag db 0
dd blur_f
 
353,7 → 350,7
if Ext=SSE3
db ' (SSE3)'
end if
db ' 0.074',0
db ' 0.073',0
labellen:
STRdata db '-1 '
lab_vert:
428,43 → 425,8
 
 
 
;if Ext >= SSE3
 
align 16
point_light_coords:
dd 50.0
dd 50.0
dd -215.0
dd 0.0
 
 
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:
480,11 → 442,7
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:
505,13 → 463,22
workarea rb 180
EndFile dd ?
align 8
sinbeta dd ?;
sinbeta dd ?;+32
cosbeta dd ?
 
xsub dw ?
zsub dw ?
zsub dw ?;+40
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 ?
520,9 → 487,13
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
539,14 → 510,18
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
560,19 → 535,25
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 2048 ; process info
rb 1024 ; process info
I_Param rb 256
memStack:
rb 2000
/programs/demos/view3ds/history.txt
1,8 → 1,3
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,16 → 1,20
View3ds 0.074 - 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. 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. 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
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
22,7 → 26,7
ptex (real Phong + texturing + transparency).
3. speed: idle, full.
4,5. zoom in, out: no comment.
6. ray shadow: calc ray casted shadows.
6. catmull: disabled
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
46,4 → 50,4
decrease whole handlers count by enable culling (using appropriate button) - some
back handlers become hidden.
 
Maciej Guba IX 2021
Maciej Guba V 2021
/programs/demos/view3ds/view3ds.asm
1,5 → 1,5
 
; application : View3ds ver. 0.074 - tiny .3ds and .asc files viewer
; application : View3ds ver. 0.071 - tiny .3ds and .asc files viewer
; with a few graphics effects demonstration.
; compiler : FASM
; system : KolibriOS
38,9 → 38,6
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.
57,8 → 54,6
dd 0x0 ; I_Icon
 
START: ; start of execution
rdtsc
mov [rand_seed],ax
cld
push dword (SIZE_Y shr 3) * 3
fninit
95,7 → 90,9
; 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
103,25 → 100,17
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
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
;mov [draw_win_at_first],0
;mov eax,40 ; set events mask
;mov ebx,1100000000000000000000000100111b
;int 0x40
 
 
still:
cmp [edit_flag],1
jne @f
133,16 → 122,7
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
154,7 → 134,6
mov eax,10
 
@@:
.intt:
int 0x40
 
cmp eax,1 ; redraw event ?
284,9 → 263,8
jne .next_m5 ; 'grd ' 1
call make_random_lights ; 'env ' 2
call normalize_all_light_vectors ; 'bump' 3
if Ext >= SSE3
call copy_lights
if Ext >= SSE3
call init_point_lights ; for ex. ray casting
end if
call do_color_buffer ; intit color_map ; 'tex ' 4
 
418,7 → 396,7
cmp [move_flag],0
jne @f
.x_minus:
sub word[vect_x],10
sub [vect_x],10
jmp .next2
@@:
cmp [move_flag],1
436,7 → 414,7
cmp [move_flag],0
jne @f
.x_plus:
add word[vect_x],10
add [vect_x],10
jmp .next3
@@:
cmp [move_flag],1
544,6 → 522,8
.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
@@:
554,71 → 534,43
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 .no_sin
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
je @f
call do_sinus
; jmp .finito
.no_sin:
@@:
movzx ecx,[fire_flag]
cmp [fire_flag],1
je @f
cmp [fire_flag],0
jne @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
@@:
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
cmp [emboss_flag],0
jne .emb ; if emboss=true -> no fire
movzx ecx,[fire_flag]
call blur_screen ; blur and fire
; jmp .finito
 
.no_blur: ; no blur, no fire
cmp [emboss_flag],0
je @f
movzx eax,[dr_flag]
movzx ebx,[ray_shd_flag]
shl ebx,10
or eax,ebx
.emb:
call do_emboss
.finito:
 
@@:
 
 
755,8 → 707,6
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
814,7 → 764,6
include '3stencil.inc'
include '3glass.inc'
include '3glass_tex.inc'
include '3ray_shd.inc'
end if
clear_vertices_index:
mov edi,[vertices_index_ptr]
1126,7 → 1075,7
fldpi
fadd st,st
mov esi,[points_ptr]
mov edi,[tex_points_ptr]
mov edi,tex_points
mov ecx,[points_count_var]
inc ecx
; cmp [map_tex_flag],1
1440,8 → 1389,7
mov esp,ebp
pop ebp
ret
 
if Ext >= SSE2
if Ext >= SSE3
init_point_normals:
.z equ dword [ebp-8]
.y equ dword [ebp-12]
1449,6 → 1397,7
.point_number equ dword [ebp-28]
.hit_faces equ dword [ebp-32]
 
fninit
push ebp
mov ebp,esp
sub esp,64
1489,25 → 1438,19
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
1633,9 → 1576,11
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
1665,8 → 1610,8
pop ecx
loop .again
ret
end if
 
 
clrscr:
mov edi,[screen_ptr]
movzx ecx,word[size_x_var]
1709,37 → 1654,7
 
 
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
1756,8 → 1671,7
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]
1820,57 → 1734,124
je .draw_smooth_line
 
mov esi,[triangles_ptr]
xor ecx,ecx ;mov ecx,[triangles_count_var]
mov ecx,[triangles_count_var]
.again_dts:
; push ebp
push esi
push ecx
mov .tri_no,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 eax,[esi]
mov ebx,[esi+4]
mov ecx,[esi+8]
pop ebp
 
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
 
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,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
 
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
@@:
 
; push esi
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 ;
fninit ; DO culling AT FIRST
cmp [culling_flag],1 ; (if culling_flag = 1)
jne .no_culling
lea esi,.point_index1 ; *********************************
mov esi,point_index1 ; *********************************
mov ecx,3 ;
@@:
mov eax,dword[esi]
1877,77 → 1858,76
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr]
mov eax,[eax+8]
bt eax,31
jc @f
; *****************************
; CHECKING OF Z COOFICIENT OF
; NORMAL VECTOR
add esi,4
; 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
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
cmp .dr_flag,100
je .ray_shd
 
end if
 
push ebp ; ****************
lea esi,.index3x12 ; do Gouraud shading
lea edi,.zz3
end if ; ****************
mov esi,point_index3 ; do Gouraud shading
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]
push word[edi] ; zz1 ,2 ,3
 
; 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
; @@:
ror eax,16 ; eax -0xxxrrggbb -> 0xggbbxxrr
xor ah,ah
push ax ;r
1958,55 → 1938,98
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]
 
; 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:
push ebp
push word .zz3
 
mov eax, .xx3
ror eax,16
; cmp [catmull_flag],1 ; put on stack z coordinate if necessary
; jne @f
push [zz3]
@@:
mov eax,dword[yy3]
mov ebx,0x00ff00ff
and eax,ebx
push eax
neg al
push ax
push word .zz2
push [zz2]
 
mov eax, .xx2
ror eax,16
mov eax,dword[yy2]
and eax,ebx
push eax
neg al
push ax
push word .zz1
push [zz1]
 
mov eax, .xx1
ror eax,16
mov eax,dword[yy1]
and eax,ebx
push eax
neg al
push ax
.both_draw:
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
call gouraud_triangle_z
pop ebp
jmp .end_draw
 
.flat_draw: ;**************************
fninit ; FLAT DRAWING
mov eax,.index1x12
mov ebx,.index2x12
mov ecx,.index3x12
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]
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]
2014,7 → 2037,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]
2021,12 → 2044,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
2048,32 → 2071,34
; shl eax,8
; mov edx,eax
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
 
mov esi,[Zbuffer_ptr]
push ebp
push word .zz3
push word .zz2
push word .zz1
push word[zz3]
push word[zz2]
push word[zz1]
call flat_triangle_z
pop ebp
jmp .end_draw
 
.env_mapping:
push ebp
push word .zz3
push word .zz2
push word .zz1
push [zz3]
push [zz2]
push [zz1]
 
lea esi, .index1x12
mov esi,point_index1
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]
2090,29 → 2115,33
add esi,4
loop @b
 
mov eax, .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov esi,envmap
 
mov edx,[Zbuffer_ptr]
call tex_triangle_z
pop ebp
 
jmp .end_draw
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.cubic_env_mapping:
push ebp
push word .zz3
push word .zz2
push word .zz1
push [zz3]
push [zz2]
push [zz1]
 
lea esi,.index1x12
mov esi,point_index1
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]
2142,32 → 2171,37
add esi,4
loop @b
 
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
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 word .zz3
push word .zz2
push word .zz1
push [zz3]
push [zz2]
push [zz1]
 
lea esi,.index1x12
mov esi,point_index1
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]
2184,58 → 2218,70
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_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index2
mov esi,[point_index2]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
push dword[esi]
mov esi, .point_index1
; push dword[xx2]
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
push dword[esi]
; push dword[xx1]
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov esi,envmap
mov edx,bumpmap ;BUMP_MAPPING
 
call bump_triangle_z
pop ebp
 
jmp .end_draw
 
.tex_mapping:
push ebp
push word .zz3
push word .zz2
push word .zz1
 
push [zz3]
push [zz2]
push [zz1]
; @@:
mov esi, .point_index3 ; tex map coords
mov esi,[point_index3] ; tex map coords
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index2
mov esi,[point_index2]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index1
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
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
2273,43 → 2319,49
 
.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_ptr]
add esi,tex_points
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_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index1
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
 
lea esi, .index3x12
lea edi, .zz3
mov esi,point_index3
mov ecx,3
 
.aagain_grd_draw:
 
push word[edi] ; zz1 ,2 ,3
lea edx,[ecx*3]
push word[edx*2+xx1-2] ; 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
mov ebx,.temp1
and ebx,0xfffffff ; some onjects need this 'and'
mov eax,[temp2] ;word[ebp-4]
mov ebx,[temp1] ;word[ebp-2]
and ebx,0xfffffff ; some onjects need thid 'and'
shl eax,TEX_SHIFT
add eax,ebx
lea eax,[eax*3]
2324,14 → 2376,17
push ax ;g
shr eax,24
push ax ;b
sub edi,2
 
sub esi,4
dec cx
jnz .aagain_grd_draw
 
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov edx,texmap
mov esi,[Zbuffer_ptr]
2339,30 → 2394,31
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_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index2
mov esi,[point_index2]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index1
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
 
lea esi, .point_index1 ; env coords
mov esi,point_index1 ; env coords
sub esp,12
mov edi,esp
mov ecx,3
2387,46 → 2443,50
add esi,4
loop @b
 
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov esi,texmap
mov edx,envmap
 
call two_tex_triangle_z
pop ebp
jmp .end_draw
 
.bump_tex:
push ebp
mov esi, .point_index3 ; tex map coords
mov esi,[point_index3] ; tex map coords
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index2
mov esi,[point_index2]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index1
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
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]
 
lea esi, .index1x12 ; env coords
mov esi,point_index1 ; 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]
2443,28 → 2503,40
add esi,4
loop @b
 
mov esi, .point_index3 ; bump map coords
; 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
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index2
mov esi,[point_index2]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi, .point_index1
 
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
; 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 edi,[screen_ptr]
mov esi,envmap
mov edx,bumpmap
 
call bump_tex_triangle_z
pop ebp
 
jmp .end_draw
 
 
2477,9 → 2549,12
pshufd xmm5,xmm5,01110011b
 
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
2491,9 → 2566,12
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
2506,9 → 2584,12
 
 
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
 
2522,9 → 2603,12
pshufd xmm5,xmm5,01110011b
 
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
mov eax,[point_index1]
mov ebx ,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
2536,9 → 2620,12
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
2551,9 → 2638,12
 
 
 
mov eax, .xx1
mov ebx, .xx2
mov ecx, .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
mov edi,[screen_ptr]
mov edx,[Zbuffer_ptr]
mov esi,[Zbuffer_ptr]
2567,9 → 2657,12
punpcklwd xmm5,[the_zero]
pshufd xmm5,xmm5,01110011b
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
add eax,[points_normals_rot_ptr]
add ebx,[points_normals_rot_ptr]
add ecx,[points_normals_rot_ptr]
2581,9 → 2674,12
andps xmm2,[zero_hgst_dd]
xorps xmm3,xmm3
 
mov eax, .index1x12
mov ebx, .index2x12
mov ecx, .index3x12
mov eax,[point_index1]
mov ebx,[point_index2]
mov ecx,[point_index3]
imul eax,[i12]
imul ebx,[i12]
imul ecx,[i12]
add eax,[points_rotated_ptr]
add ebx,[points_rotated_ptr]
add ecx,[points_rotated_ptr]
2594,17 → 2690,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_ptr]
add esi,tex_points
push dword[esi]
mov esi,.point_index2
mov esi,[point_index2]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
mov esi,.point_index1
mov esi,[point_index1]
shl esi,2
add esi,[tex_points_ptr]
add esi,tex_points
push dword[esi]
movups xmm6,[esp]
add esp,12
2618,84 → 2714,31
por xmm6,xmm7
 
 
mov eax,dword .xx1
mov ebx,dword .xx2
mov ecx,dword .xx3
mov eax,dword[xx1]
ror eax,16
mov ebx,dword[xx2]
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
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
 
jmp .eend
pop ecx
dec ecx
 
jnz .again_dts
ret
 
 
.draw_smooth_line:
2746,8 → 2789,7
sub esp,16
movups [esp],xmm1
add esi,4
dec ecx
jnz .aga_n
loop .aga_n
 
movups xmm0,[esp]
movups xmm1,[esp+16]
2765,17 → 2807,11
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
2815,15 → 2851,6
cmp ecx,[edges_count]
jnz .again_s_line
 
 
 
 
 
 
.eend:
add esp,60
pop ebp
 
ret
 
 
2831,9 → 2858,8
 
 
 
draw_handlers:
 
draw_handlers:
; in eax - render model
push ebp
mov ebp,esp
 
2840,15 → 2866,14
.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_model,12
cmp [dr_flag],12
jge @f
lea ebx,[eax*3]
sub ebx,18
2906,7 → 2931,7
add eax,ebx
push eax
lea edi,[eax*3]
cmp .dr_model,12
cmp [dr_flag],12
jl @f
add edi,[esp]
@@:
2931,7 → 2956,7
mov byte[edi+2],0xff ;al
mov word[eax],dx
add eax,2
cmp .dr_model,12
cmp [dr_flag],12
jl @f
add edi,4
loop .do
3201,6 → 3226,7
.exit:
mov dword[edi],-1
ret
 
alloc_mem_for_tp:
mov eax, 68
cmp [re_alloc_flag],1
3267,15 → 3293,7
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]
3284,6 → 3302,7
ret
 
 
 
read_from_disk:
mov eax, 68
mov ebx, 11
3329,11 → 3348,11
mov edi,menu
.again:
mov eax,8 ; function 8 : define and draw button
movzx ebx,word[size_x_var]
mov bx,[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 ecx,2
sub cl,2
lea ecx,[ecx*5]
lea ecx,[ecx*3]
add ecx,25
3345,10 → 3364,10
; BUTTON LABEL
mov eax,4 ; function 4 : write text to window
movzx ebx,byte[edi]
sub ebx,2 ; button id, according to position
sub bl,2 ; button id, according to position
lea ebx,[ebx*3]
lea ebx,[ebx*5]
movzx ecx,word[size_x_var]
mov cx,[size_x_var]
shl ecx,16
add ebx,ecx
add ebx,(12)*65536+28 ; [x start] *65536 + [y start]
3440,9 → 3459,6
; ******* 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
3476,7 → 3492,6
; 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 ++
3629,8 → 3644,6
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
 
 
/programs/demos/view3ds/3glass.inc
1,5 → 1,5
; Glass like rendering triangle by Maciej Guba.
; http://macgub.co.pl, macgub3@wp.pl
; http://macgub.hekko.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.co.pl
; http://macgub.j.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.co.pl
; http://macgub.vxm.pl
 
ROUND2 equ 10
real_phong_tri_z: