Rev 6387 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6387 | leency | 1 | MAX_SPHERES = 5 |
2 | MAX_LIGHTS = 3 |
||
3 | ;ray |
||
4 | |||
5 | main_loop: |
||
6 | xor eax,eax ; y |
||
7 | .next_line: |
||
8 | xor ebx,ebx ; x |
||
9 | |||
10 | @@: |
||
11 | push eax |
||
12 | push ebx |
||
13 | call find_intersection |
||
14 | pop ebx |
||
15 | pop eax |
||
16 | add ebx,1 |
||
17 | cmp ebx,XRES |
||
18 | jnz @b |
||
19 | |||
20 | add eax,1 |
||
21 | cmp eax,YRES |
||
22 | jnz .next_line |
||
23 | |||
24 | ret |
||
25 | init_calc: ; do some intial calculations |
||
26 | |||
27 | ret |
||
28 | |||
29 | find_intersection: ;with for now single sphere |
||
30 | ; eax - y |
||
31 | ; ebx - x |
||
32 | push ebp |
||
33 | mov ebp,esp |
||
34 | sub esp,128 |
||
35 | and ebp,0xfffffff0 |
||
36 | .dz equ dword[ebp-8] |
||
37 | .dy equ dword[ebp-12] |
||
38 | .dx equ [ebp-16] |
||
39 | .a equ dword[ebp-20] |
||
40 | .b equ dword[ebp-24] |
||
41 | .c equ dword[ebp-28] |
||
42 | .delta equ dword[ebp-32] |
||
43 | .iy equ dword[ebp-36] |
||
44 | .ix equ [ebp-40] |
||
45 | .t1 equ [ebp-44] |
||
46 | .t2 equ [ebp-48] |
||
47 | .n equ [ebp-64] |
||
48 | .sph_xyz equ [ebp-80] |
||
49 | .one_write equ byte [ebp-81] ;tells if sth written in 'nearest' data |
||
50 | .sph_counter equ dword [ebp-85] |
||
51 | |||
52 | |||
53 | mov .iy,eax |
||
54 | mov .ix,ebx |
||
55 | |||
56 | mov .one_write,0 |
||
57 | xorps xmm0,xmm0 |
||
58 | cvtpi2ps xmm0,.ix |
||
59 | mov ecx,XRES |
||
60 | cvtsi2ss xmm2,ecx |
||
61 | shufps xmm2,xmm2,0 |
||
62 | divps xmm0,xmm2 |
||
63 | subps xmm0,[camera] |
||
64 | movaps .dx,xmm0 |
||
65 | movaps xmm1,xmm0 |
||
66 | mulps xmm1,xmm0 |
||
67 | haddps xmm1,xmm1 |
||
68 | haddps xmm1,xmm1 |
||
69 | movss .a,xmm1 |
||
70 | mov .sph_counter,0 |
||
71 | .next_sph: |
||
72 | xorps xmm5,xmm5 |
||
73 | movaps xmm5,[camera] |
||
74 | mov edx,.sph_counter |
||
75 | shl edx,4 |
||
76 | add edx,sphere |
||
77 | subps xmm5,[edx] ;[sphere] ;;[edx] |
||
78 | mulps xmm5,[float2] |
||
79 | movaps xmm0,.dx |
||
80 | mulps xmm5,xmm0 |
||
81 | haddps xmm5,xmm5 |
||
82 | haddps xmm5,xmm5 |
||
83 | movss .b,xmm5 |
||
84 | |||
85 | |||
86 | movaps xmm4,[edx] ;[sphere] ; [edx] |
||
87 | mulps xmm4,xmm4 |
||
88 | ; haddps xmm4,xmm4 |
||
89 | ; haddps xmm4,xmm4 |
||
90 | movaps xmm5,[camera] |
||
91 | mulps xmm5,xmm5 |
||
92 | addps xmm4,xmm5 |
||
93 | haddps xmm4,xmm4 |
||
94 | haddps xmm4,xmm4 |
||
95 | ; addss xmm4,xmm5 |
||
96 | movaps xmm5,[edx] ;;[sphere] ;; [edx] |
||
97 | mulps xmm5,[camera] |
||
98 | haddps xmm5,xmm5 |
||
99 | haddps xmm5,xmm5 |
||
100 | mulss xmm5,[float2] |
||
101 | subss xmm4,xmm5 |
||
102 | mov ebx,.sph_counter |
||
103 | shl ebx,2 |
||
104 | add ebx,sph_radius |
||
105 | movss xmm5,[ebx] ;[R] ; [ebx] |
||
106 | mulss xmm5,xmm5 |
||
107 | subss xmm4,xmm5 |
||
108 | movss .c,xmm4 |
||
109 | |||
110 | movss xmm5,.b |
||
111 | mulss xmm5,xmm5 |
||
112 | mulss xmm4,.a |
||
113 | mulss xmm4,[float4] |
||
114 | subss xmm5,xmm4 |
||
115 | movss .delta,xmm5 |
||
116 | xorps xmm6,xmm6 |
||
117 | cmpnltss xmm5,xmm6 |
||
118 | movd ecx,xmm5 ; ecx = -1 greater than 0.0 |
||
119 | cmp ecx,0 |
||
120 | jnz @f |
||
121 | jmp .next_s ; no intersection |
||
122 | ; add .sph_counter,1 |
||
123 | ; cmp .sph_counter,MAX_SPHERES |
||
124 | ; jnz .next_sph |
||
125 | ; jmp .put_pixel |
||
126 | |||
127 | |||
128 | @@: |
||
129 | movss xmm5,.delta |
||
130 | sqrtss xmm5,xmm5 |
||
131 | movss xmm4,xmm5 |
||
132 | subss xmm6,.b |
||
133 | movss xmm7,xmm6 |
||
134 | subss xmm6,xmm5 |
||
135 | divss xmm6,[float2] |
||
136 | divss xmm6,.a |
||
137 | movss .t1,xmm6 |
||
138 | addss xmm4,xmm7 |
||
139 | divss xmm4,[float2] |
||
140 | divss xmm4,.a |
||
141 | movss .t2,xmm4 |
||
142 | movss xmm5,xmm4 |
||
143 | |||
144 | cmpnltss xmm4,.t1 |
||
145 | movd ecx,xmm4 |
||
146 | or ecx,ecx |
||
147 | jne @f |
||
148 | movss xmm5,.t2 |
||
149 | @@: |
||
150 | cmp .one_write,0 ; test if sth in 'nearest' data is written |
||
151 | jz @f |
||
152 | movss xmm4,xmm5 |
||
153 | cmpnltss xmm4,[smalest_t] |
||
154 | movd ecx,xmm4 |
||
155 | or ecx,ecx |
||
156 | jz .next_s |
||
157 | @@: |
||
158 | movss [smalest_t],xmm5 |
||
159 | ; push .a |
||
160 | ; pop [smalest_a] |
||
161 | ; push .b |
||
162 | ; pop [smalest_b] |
||
163 | ; push .c |
||
164 | ; pop [smalest_c] |
||
165 | ; push .delta |
||
166 | ; pop [smalest_delta] |
||
167 | movaps xmm0,[edx] |
||
168 | movaps [nearest_sphere],xmm0 |
||
169 | push dword[ebx] |
||
170 | pop dword[nearest_radius] |
||
171 | mov .one_write,1 |
||
172 | |||
173 | .next_s: |
||
174 | add .sph_counter,1 |
||
175 | cmp .sph_counter,MAX_SPHERES |
||
176 | jnz .next_sph |
||
177 | |||
178 | .put_pixel: |
||
179 | cmp .one_write,0 |
||
180 | je .end |
||
181 | |||
182 | movss xmm5,[smalest_t] |
||
183 | shufps xmm5,xmm5,0 ; calc and put pixel |
||
184 | movaps xmm6,.dx |
||
185 | mulps xmm6,xmm5 |
||
186 | movaps xmm4,[camera] |
||
187 | addps xmm4,xmm6 ; xmm4 - x,y,z on the sphere |
||
188 | movaps xmm7,xmm4 |
||
189 | subps xmm4,[nearest_sphere] |
||
190 | ; movaps xmm6,xmm7 |
||
191 | ; addps xmm6,[nearest_sphere] |
||
192 | ; movaps .sph_xyz,xmm6 |
||
193 | |||
194 | movss xmm0,[nearest_radius] |
||
195 | shufps xmm0,xmm0,0 |
||
196 | divps xmm4,xmm0 ; xmm4 - normal to surface vector |
||
197 | movaps xmm1,xmm4 ; copy of normal in xmm1 |
||
198 | xor eax,eax |
||
199 | xorps xmm3,xmm3 |
||
200 | movss xmm2,[light_factor] |
||
201 | shufps xmm2,xmm2,0 |
||
202 | |||
203 | .next_light: |
||
204 | ; push eax |
||
205 | mov ebx,eax |
||
206 | shl ebx,4 |
||
207 | ;add eax,light |
||
208 | movaps xmm5,[light+ebx];[light] ;; [eax] |
||
209 | subps xmm5,xmm7 ; calc light unit vector |
||
210 | movaps xmm6,xmm5 |
||
211 | mulps xmm5,xmm5 |
||
212 | haddps xmm5,xmm5 |
||
213 | haddps xmm5,xmm5 |
||
214 | sqrtss xmm5,xmm5 |
||
215 | divps xmm6,xmm5 ; xmm6 - normalized light vector |
||
216 | ; dot_product |
||
217 | movaps xmm4,xmm1 ; xmm4 - normal to surface |
||
218 | mulps xmm4,xmm6 |
||
219 | haddps xmm4,xmm4 |
||
220 | haddps xmm4,xmm4 |
||
221 | shufps xmm4,xmm4,0 |
||
222 | ; movaps xmm5,xmm4 |
||
223 | ; mulps xmm5,xmm5 |
||
224 | ; mulps xmm5,xmm5 |
||
225 | ; mulps xmm5,[color] |
||
226 | mulps xmm4,[lights_color+ebx] ; xmm4 - computed col. light vector dep. |
||
227 | ; addps xmm4,xmm5 |
||
228 | mulps xmm4,xmm2 |
||
229 | addps xmm3,xmm4 |
||
230 | ; pop eax |
||
231 | add eax,1 |
||
232 | cmp eax,MAX_LIGHTS |
||
233 | jnz .next_light |
||
234 | if 0 |
||
235 | ; mix with texture |
||
236 | movaps xmm0,.sph_xyz |
||
237 | movss xmm1,[nearest_radius] |
||
238 | shufps xmm1,xmm1,0 |
||
239 | divps xmm0,xmm1 |
||
240 | mulps xmm0,[correct_tex] ; f64 |
||
241 | ; addps xmm0,[correct_tex] |
||
242 | cvtss2si eax,xmm0 |
||
243 | psrldq xmm0,4 |
||
244 | cvtss2si ebx,xmm0 |
||
245 | imul ebx,[tex_x] |
||
246 | add ebx,eax |
||
247 | lea ebx,[ebx*3] |
||
248 | add ebx,bitmap |
||
249 | ;mov eax,[ebx] |
||
250 | movd xmm1,[ebx] |
||
251 | xorps xmm7,xmm7 |
||
252 | punpcklbw xmm1,xmm7 |
||
253 | punpcklwd xmm1,xmm7 |
||
254 | cvtdq2ps xmm1,xmm1 |
||
255 | mulps xmm3,xmm1 |
||
256 | divps xmm3,[float255] |
||
257 | ; divps xmm1,[float2] |
||
258 | ; divps xmm3,[float2] |
||
259 | ; addps xmm3,xmm1 |
||
260 | end if |
||
261 | |||
262 | |||
263 | minps xmm3,[float255] |
||
264 | cvtps2dq xmm3,xmm3 |
||
265 | packssdw xmm3,xmm3 |
||
266 | packuswb xmm3,xmm3 |
||
267 | |||
268 | |||
269 | |||
270 | |||
271 | mov edi,screen |
||
272 | mov ecx,XRES |
||
273 | imul ecx,.iy |
||
274 | add ecx,.ix |
||
275 | lea ecx,[ecx*3] |
||
276 | add edi,ecx |
||
277 | movd [edi],xmm3 |
||
278 | |||
279 | .end: |
||
280 | add esp,128 |
||
281 | pop ebp |
||
282 | |||
283 | ret |
||
284 |