Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1245 | hidnplayr | 1 | ;init_envmap_cub2: |
2 | ; mov esi,envmap |
||
3 | ; mov edi,envmap_cub ;take cubic env. map from |
||
4 | ; xor eax,eax ;spherical env. map |
||
5 | ; @@: |
||
6 | ; add esi,eax |
||
7 | ; movsd |
||
8 | ; dec edi |
||
9 | ; dec esi |
||
10 | ; add esi,511*3 |
||
11 | ; add eax,3 |
||
12 | ; cmp eax,511*3 |
||
13 | ; jl @b |
||
14 | ;ret |
||
15 | init_envmap_cub: ; create 512x512 env map |
||
16 | .temp equ word [ebp-2] |
||
17 | push ebp |
||
18 | mov ebp,esp |
||
19 | sub esp,2 |
||
20 | mov edi,envmap_cub |
||
21 | fninit |
||
22 | |||
23 | mov cx,-256 |
||
24 | .ie_hor: |
||
25 | mov .temp,cx |
||
26 | fild .temp |
||
27 | fabs |
||
28 | ; fmul st,st0 |
||
29 | ; fsqrt |
||
30 | mov .temp,255 |
||
31 | fisubr .temp |
||
32 | fmul [env_const] |
||
33 | fistp .temp |
||
34 | mov ax,.temp |
||
35 | |||
36 | or ax,ax |
||
37 | jge .ie_ok1 |
||
38 | xor ax,ax |
||
39 | jmp .ie_ok2 |
||
40 | .ie_ok1: |
||
41 | cmp ax,255 |
||
42 | jle .ie_ok2 |
||
43 | mov ax,255 |
||
44 | .ie_ok2: |
||
45 | stosb |
||
46 | stosb |
||
47 | stosb |
||
48 | |||
49 | inc cx |
||
50 | cmp cx,256 |
||
51 | jne .ie_hor |
||
52 | |||
53 | mov esp,ebp |
||
54 | pop ebp |
||
55 | ret |
||
56 | |||
57 | calc_one_col: |
||
58 | ; procedure don't save registers !!! |
||
59 | ; in - st - dot_product |
||
60 | ; stack - other parameters |
||
61 | ; out - eax - 0x00rrggbb |
||
62 | .dot_prd equ dword[ebp+4] ; dot product - cos x - not now |
||
63 | .min_col_r equ word[ebp+8] ; minimum color - ambient |
||
64 | .min_col_g equ word[ebp+10] |
||
65 | .min_col_b equ word[ebp+12] |
||
66 | .max_col_r equ word[ebp+14] ; maximum color - specular |
||
67 | .max_col_g equ word[ebp+16] |
||
68 | .max_col_b equ word[ebp+18] |
||
69 | .org_col_r equ word[ebp+20] ; orginal color - diffuse |
||
70 | .org_col_g equ word[ebp+22] |
||
71 | .org_col_b equ word[ebp+24] |
||
72 | .n equ word[ebp+26] ; shines - not implemented |
||
73 | .temp equ word[ebp-2] |
||
74 | .color_sum_r equ dword[ebp-6] |
||
75 | .color_sum_g equ dword[ebp-10] |
||
76 | .color_sum_b equ dword[ebp-14] |
||
77 | ; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular |
||
78 | mov ebp,esp |
||
79 | sub esp,14 |
||
80 | |||
81 | mov ax,.min_col_r |
||
82 | add ax,.max_col_r |
||
83 | add ax,.org_col_r |
||
84 | cwde |
||
85 | mov .color_sum_r,eax |
||
86 | |||
87 | mov ax,.min_col_g |
||
88 | add ax,.max_col_g |
||
89 | add ax,.org_col_g |
||
90 | cwde |
||
91 | mov .color_sum_g,eax |
||
92 | |||
93 | mov ax,.min_col_b |
||
94 | add ax,.max_col_b |
||
95 | add ax,.org_col_b |
||
96 | cwde |
||
97 | mov .color_sum_b,eax |
||
98 | |||
99 | |||
100 | ; fld .dot_prd |
||
101 | ; fild .n |
||
102 | ; fxch st1 |
||
103 | ; fabs |
||
104 | ; fyl2x ; |
||
105 | ; f2xm1 |
||
106 | ; fld1 |
||
107 | ; faddp ; st = dot_product ^ n |
||
108 | |||
109 | fld st ; copy dot pr |
||
110 | fmul st,st0 |
||
111 | fmul st,st0 |
||
112 | fmul st,st0 |
||
113 | cmp .n,255 ; .n = 255 -> spot light |
||
114 | jne @f |
||
115 | fmul st,st0 |
||
116 | fmul st,st0 |
||
117 | fmul st,st0 |
||
118 | @@: |
||
119 | fld st ; st0=st1=dot_pr^n, st2=dot_pr |
||
120 | fimul .max_col_b |
||
121 | fild .org_col_b |
||
122 | fmul st,st3 |
||
123 | faddp ; st0=first piece of col, st1=dot_pr^n.. |
||
124 | fiadd .min_col_b |
||
125 | fimul .max_col_b |
||
126 | fidiv .color_sum_b |
||
127 | fistp .temp |
||
128 | movzx eax,.temp |
||
129 | shl eax,16 |
||
130 | |||
131 | fld st |
||
132 | fimul .max_col_g |
||
133 | fild .org_col_g |
||
134 | fmul st,st3 |
||
135 | faddp |
||
136 | fiadd .min_col_g |
||
137 | fimul .max_col_g |
||
138 | fidiv .color_sum_g |
||
139 | fistp .temp |
||
140 | mov ax,.temp |
||
141 | mov ah,al |
||
142 | shl eax,8 |
||
143 | |||
144 | fimul .max_col_r |
||
145 | fild .org_col_r |
||
146 | fmulp st2,st |
||
147 | faddp |
||
148 | fiadd .min_col_r |
||
149 | fimul .max_col_r |
||
150 | fidiv .color_sum_r |
||
151 | fistp .temp |
||
152 | mov ax,.temp ;eax - 0xbbgg00rr |
||
153 | ; mov ah,al |
||
154 | ror eax,16 |
||
155 | xchg al,ah ; eax - 0x00rrggbb |
||
156 | mov esp,ebp |
||
157 | ret 24 |
||
158 | |||
159 | calc_bumpmap: ; calculate random bumpmap |
||
160 | ;--------------in edi _ pointer to TEX_X x TEX_Y bumpmap |
||
161 | |||
162 | push edi |
||
163 | |||
164 | cmp [bumps_flag],0 |
||
165 | je .random_bump_map |
||
166 | ; else bumps according to texture |
||
167 | mov esi,texmap |
||
168 | mov ecx,TEXTURE_SIZE |
||
169 | @@: |
||
170 | movzx ax,byte[esi] |
||
171 | movzx bx,byte[esi+1] |
||
172 | movzx dx,byte[esi+2] |
||
173 | add ax,bx |
||
174 | add ax,dx |
||
175 | cwd |
||
176 | div [i3] |
||
177 | stosb |
||
178 | add esi,3 |
||
179 | loop @b |
||
180 | jmp .blur_map |
||
181 | ; push ecx |
||
182 | ; mov eax,0x88888888 |
||
183 | ; mov ecx,16/4 |
||
184 | ; rep stosd |
||
185 | ; mov eax,0xffffffff |
||
186 | ; mov ecx,16/4 |
||
187 | ; rep stosd |
||
188 | ; pop ecx |
||
189 | ; loop @b |
||
190 | .random_bump_map: |
||
191 | |||
192 | mov ecx,TEXTURE_SIZE |
||
193 | @@: |
||
194 | push ecx |
||
195 | xor ecx,ecx |
||
196 | mov edx,255 |
||
197 | call random |
||
198 | stosb |
||
199 | pop ecx |
||
200 | loop @b |
||
201 | |||
202 | .blur_map: |
||
203 | pop edi |
||
204 | movzx ecx,[bumps_deep_flag] |
||
205 | inc cx |
||
206 | .blur: |
||
207 | xor esi,esi |
||
208 | mov edx,TEXTURE_SIZE |
||
209 | xor eax,eax |
||
210 | xor ebx,ebx |
||
211 | @@: |
||
212 | mov ebp,esi |
||
213 | dec ebp |
||
214 | and ebp,TEXTURE_SIZE |
||
215 | mov al,byte[ebp+edi] |
||
216 | |||
217 | mov ebp,esi |
||
218 | inc ebp |
||
219 | and ebp,TEXTURE_SIZE |
||
220 | mov bl,byte[ebp+edi] |
||
221 | add eax,ebx |
||
222 | |||
223 | mov ebp,esi |
||
224 | sub ebp,TEX_X |
||
225 | and ebp,TEXTURE_SIZE |
||
226 | mov bl,byte[ebp+edi] |
||
227 | add eax,ebx |
||
228 | |||
229 | mov ebp,esi |
||
230 | add ebp,TEX_X |
||
231 | and ebp,TEXTURE_SIZE |
||
232 | mov bl,byte[ebp+edi] |
||
233 | add eax,ebx |
||
234 | |||
235 | shr eax,2 |
||
236 | mov byte[esi+edi],al |
||
237 | |||
238 | inc esi |
||
239 | dec edx |
||
240 | jnz @b |
||
241 | |||
242 | loop .blur |
||
243 | ret |
||
244 | random: |
||
245 | ; in - ecx - min |
||
246 | ; edx - max |
||
247 | ; out - eax - random number |
||
248 | mov bx,[rand_seed] |
||
249 | add bx,0x9248 |
||
250 | ror bx,3 |
||
251 | mov [rand_seed],bx |
||
252 | |||
253 | mov ax,dx |
||
254 | sub ax,cx |
||
255 | mul bx |
||
256 | mov ax,dx |
||
257 | add ax,cx |
||
258 | cwde |
||
259 | ret |
||
260 | |||
261 | optimize_object1: ; setting point (0,0,0) in center of object |
||
262 | ; recalculate all coords , scale object, |
||
263 | ;the coords in <-1.0,1.0> |
||
264 | ;in : real_points - table filled of real float dd coordinates (x,y,z), end mark dd -1 |
||
265 | ; _ global variable |
||
266 | ; points_count_var - dw integer variable with exactly points count |
||
267 | ; - global variable |
||
268 | ; SIZE_X, SIZE_Y must be defined |
||
269 | |||
270 | .max equ dword[ebp-4] |
||
271 | .min equ dword[ebp-8] |
||
272 | .maxxx equ dword[ebp-12] |
||
273 | .center equ dword[ebp-16] |
||
274 | |||
275 | mov ebp,esp |
||
276 | sub esp,16 |
||
277 | fninit |
||
278 | mov .maxxx,0 |
||
279 | mov ecx,3 |
||
280 | xor ebx,ebx ; ebx - x,y,z coord in real_points list |
||
281 | .next_c: ; max/min/center x,y,z |
||
282 | mov edi,[points_ptr] ; in real_point list minimum two points |
||
283 | mov dx,[points_count_var] |
||
284 | fld dword[edi+ebx] |
||
285 | fst .max |
||
286 | fstp .min |
||
287 | add edi,12 |
||
288 | dec dx |
||
289 | .next_coord: ; next coord from real_points list |
||
290 | fld dword [edi+ebx] ; real_points -> x,y,z |
||
291 | fcom .max ; max_x,y,z |
||
292 | fstsw ax |
||
293 | sahf |
||
294 | jbe @f ; jmp less equal |
||
295 | fstp .max ; new max_x,y,z |
||
296 | jmp .end_coords |
||
297 | @@: |
||
298 | fcom .min ; min_x,y,z |
||
299 | fstsw ax |
||
300 | sahf |
||
301 | jnbe @f ; jmp greater |
||
302 | fst .min ; new min_x |
||
303 | @@: |
||
304 | ffree st |
||
305 | .end_coords: |
||
306 | add edi,12 |
||
307 | ; cmp dword[edi],-1 ; cmp with end mark |
||
308 | dec dx |
||
309 | jnz .next_coord |
||
310 | ; ok after this we found max_coord and min_coord |
||
311 | fld .max ; find center point |
||
312 | fadd .min |
||
313 | fld1 |
||
314 | fld1 |
||
315 | faddp |
||
316 | fdivp st1,st ; st0 - center coord |
||
317 | fstp .center |
||
318 | |||
319 | fld .max |
||
320 | fsub .center ; st = .max - .center |
||
321 | fcom .maxxx ; maximum of all .max |
||
322 | fstsw ax |
||
323 | sahf |
||
324 | jbe @f ; jmp lower |
||
325 | fst .maxxx ; new maxx |
||
326 | @@: |
||
327 | ffree st |
||
328 | mov edi,[points_ptr] |
||
329 | mov dx,[points_count_var] ; substraction all coords - center point |
||
330 | @@: |
||
331 | fld dword[edi+ebx] |
||
332 | fsub .center |
||
333 | fstp dword[edi+ebx] |
||
334 | add edi,12 |
||
335 | ; cmp dword[edi],-1 |
||
336 | ; jne @b |
||
337 | dec dx |
||
338 | jnz @b |
||
339 | |||
340 | add ebx,4 ; ebx - x,y,z cooficientes in list real_points |
||
341 | dec ecx |
||
342 | jnz .next_c |
||
343 | |||
344 | fld .maxxx |
||
345 | mov edi,[points_ptr] ; create all coords in <-1.0,1.0> |
||
346 | movzx ecx,[points_count_var] |
||
347 | @@: |
||
348 | fld dword[edi] |
||
349 | fdiv .maxxx |
||
350 | fstp dword[edi] |
||
351 | fld dword[edi+4] |
||
352 | fdiv .maxxx |
||
353 | fstp dword[edi+4] |
||
354 | fld dword[edi+8] |
||
355 | fdiv .maxxx |
||
356 | fstp dword[edi+8] |
||
357 | add edi,12 |
||
358 | loop @b |
||
359 | ; cmp dword[edi],-1 |
||
360 | |||
361 | ; jne @b |
||
362 | |||
363 | mov esp,ebp |
||
364 | ret |
||
365 | |||
366 | generate_object: ; generate node |
||
367 | .N equ 32 |
||
368 | .x equ word[ebp-2] |
||
369 | .Ndiv2 equ word[ebp-10] |
||
370 | .MthickSqr equ dword[ebp-14] ; diameter^2 |
||
371 | .temp equ dword[ebp-18] ; variable for x <-1;1> |
||
372 | .Hthick equ dword[ebp-22] |
||
373 | .cos_temp equ dword[ebp-26] |
||
374 | .next_const equ dword[ebp-30] |
||
375 | .a equ dword[ebp-34] |
||
376 | .Pi2 equ ebp-38 |
||
377 | |||
378 | |||
379 | |||
380 | mov ebp,esp |
||
381 | sub esp,42 |
||
382 | |||
383 | mov .Ndiv2,.N/2 |
||
384 | fninit |
||
385 | fldpi |
||
386 | fadd st,st |
||
387 | fst dword[.Pi2] |
||
388 | fidiv .Ndiv2 |
||
389 | fst .a ; .Ndiv2*.a=2Pi => .a=2pi/.Ndiv2 |
||
390 | |||
391 | fld [.Mthick] ; inside diameter, (outside daiameter = 1) |
||
392 | fmul st,st0 |
||
393 | fstp .MthickSqr |
||
394 | fld1 |
||
395 | |||
396 | fsub [.Mthick] |
||
397 | |||
398 | fst .Hthick ; Hthick = 1 - Mthick |
||
399 | fld st |
||
400 | fadd st,st |
||
401 | faddp |
||
402 | fstp .next_const ; next_const = Hthick * 3 |
||
403 | |||
404 | |||
405 | ;init triangles list |
||
406 | mov edi,[triangles_ptr] |
||
407 | |||
408 | xor si,si |
||
409 | xor ax,ax |
||
410 | mov bx,.N+1 |
||
411 | mov cx,(.N*2)+2 ;-- |
||
412 | mov dx,(.N*3)+3 ;--- |
||
413 | mov [triangles_count_var],0 |
||
414 | .again_tri: |
||
415 | stosw ; main wave |
||
416 | mov word[edi],bx |
||
417 | inc ax |
||
418 | add edi,2 |
||
419 | stosw |
||
420 | stosw |
||
421 | mov word[edi],bx |
||
422 | inc bx |
||
423 | mov word[edi+2],bx |
||
424 | |||
425 | |||
426 | add edi,4 |
||
427 | |||
428 | mov word[edi],cx ;---- ; n2+2 ; xor ax,ax |
||
429 | inc cx ; n2+3 ; mov bx,.N+1 |
||
430 | mov word[edi+2],dx ; ; mov cx,(.N*2)+2 ;-- |
||
431 | mov word[edi+4],cx ; n3+3 ; mov dx,(.N*3)+3 ;--- |
||
432 | mov word[edi+6],dx ; n3+3 ; |
||
433 | inc dx ; ; |
||
434 | mov word[edi+8],dx ; n2+3 ; |
||
435 | mov word[edi+10],cx ; n3+4 |
||
436 | add edi,12 ;---- |
||
437 | |||
438 | dec ax ; border of wave |
||
439 | dec bx |
||
440 | dec cx |
||
441 | dec dx |
||
442 | |||
443 | stosw ; first border |
||
444 | inc ax |
||
445 | stosw |
||
446 | mov word[edi],dx |
||
447 | add edi,2 |
||
448 | |||
449 | mov word[edi],dx |
||
450 | add edi,2 |
||
451 | stosw |
||
452 | inc dx |
||
453 | mov word[edi],dx |
||
454 | |||
455 | mov word[edi+2],bx ; second border |
||
456 | mov word[edi+4],cx |
||
457 | inc bx |
||
458 | mov word[edi+6],bx |
||
459 | |||
460 | mov word[edi+8],bx |
||
461 | mov word[edi+10],cx |
||
462 | inc cx |
||
463 | mov word[edi+12],cx |
||
464 | add edi,14 |
||
465 | |||
466 | add [triangles_count_var],8 ;10 |
||
467 | inc si |
||
468 | cmp si,.N |
||
469 | jne .again_tri |
||
470 | |||
471 | add ax,((.N+1)*3)+1 |
||
472 | add bx,((.N+1)*3)+1 |
||
473 | add cx,((.N+1)*3)+1 |
||
474 | add dx,((.N+1)*3)+1 |
||
475 | xor si,si |
||
476 | cmp ax,(.N*13)+13 ;;;(.N*23)+23 ; ax,(.N*13)+13 |
||
477 | jl .again_tri |
||
478 | |||
479 | mov dword[edi],-1 ; <--- end mark not always in use |
||
480 | |||
481 | ; init real points list |
||
482 | mov .x,-(.N/2) |
||
483 | mov edi,[points_ptr] |
||
484 | lea esi,[edi+(12*(.N+1))] |
||
485 | mov eax,[points_ptr] |
||
486 | mov ebx,eax |
||
487 | add eax,2*12*(.N+1) ;--- |
||
488 | add ebx,3*12*(.N+1) ;--- |
||
489 | mov [points_count_var],0 |
||
490 | |||
491 | |||
492 | .R_P4 equ edi+(4*12*(.N+1)) |
||
493 | .R_P5 equ edi+(5*12*(.N+1)) |
||
494 | .R_P6 equ edi+(6*12*(.N+1)) |
||
495 | .R_P7 equ edi+(7*12*(.N+1)) |
||
496 | |||
497 | .R_P8 equ edi+(8*12*(.N+1)) |
||
498 | .R_P9 equ edi+(9*12*(.N+1)) |
||
499 | .R_P10 equ edi+(10*12*(.N+1)) |
||
500 | .R_P11 equ edi+(11*12*(.N+1)) |
||
501 | |||
502 | .R_P12 equ edi+(12*12*(.N+1)) |
||
503 | .R_P13 equ edi+(13*12*(.N+1)) |
||
504 | .R_P14 equ edi+(14*12*(.N+1)) |
||
505 | .R_P15 equ edi+(15*12*(.N+1)) |
||
506 | |||
507 | @@: |
||
508 | ; x coordinate |
||
509 | fild .x |
||
510 | fld st |
||
511 | ;; fmul .a ; st = <-2pi;2pi> when mul .a |
||
512 | fidiv .Ndiv2 |
||
513 | fst .temp ; temporary x in <-1.0;1.0> |
||
514 | |||
515 | fst dword[edi] ;x coordinate of point |
||
516 | fst dword[esi] |
||
517 | fst dword[eax] ;-- |
||
518 | |||
519 | |||
520 | fst dword[.R_P4] |
||
521 | fst dword[.R_P5] |
||
522 | fst dword[.R_P6] |
||
523 | fst dword[.R_P7] |
||
524 | |||
525 | fst dword[.R_P8] |
||
526 | fst dword[.R_P9] |
||
527 | fst dword[.R_P10] |
||
528 | fst dword[.R_P11] |
||
529 | |||
530 | fst dword[.R_P12] |
||
531 | fst dword[.R_P13] |
||
532 | fst dword[.R_P14] |
||
533 | fst dword[.R_P15] |
||
534 | |||
535 | fstp dword[ebx] ;pop |
||
536 | ;*******y coord dword[offset + 4] |
||
537 | fmul .a ; st = <-2pi;2pi> |
||
538 | fsincos |
||
539 | fmul .next_const |
||
540 | fst dword[edi+4] ; y coordinate of point |
||
541 | fst dword[esi+4] |
||
542 | fst dword[.R_P4+4] |
||
543 | fst dword[.R_P5+4] |
||
544 | fld .Hthick |
||
545 | faddp |
||
546 | fst dword[.R_P6+4] |
||
547 | fst dword[.R_P7+4] |
||
548 | fst dword[eax+4] |
||
549 | fst dword[ebx+4] |
||
550 | |||
551 | fchs |
||
552 | fst dword[.R_P10+4] |
||
553 | fst dword[.R_P11+4] |
||
554 | fst dword[.R_P14+4] |
||
555 | fst dword[.R_P15+4] |
||
556 | fadd .Hthick |
||
557 | fadd .Hthick |
||
558 | fst dword[.R_P8+4] |
||
559 | fst dword[.R_P9+4] |
||
560 | fst dword[.R_P12+4] |
||
561 | fstp dword[.R_P13+4] |
||
562 | |||
563 | |||
564 | fmul .Hthick |
||
565 | fmul .next_const |
||
566 | fstp .cos_temp ; cos_temp = Hthick^2 * 3 |
||
567 | |||
568 | ;***************z coord |
||
569 | fld .temp |
||
570 | fld st |
||
571 | fmul st,st0 ; z coords |
||
572 | fchs |
||
573 | fld1 |
||
574 | faddp |
||
575 | fabs |
||
576 | fsqrt |
||
577 | ; fld st |
||
578 | ; fsub |
||
579 | fld st |
||
580 | fsub .cos_temp |
||
581 | fst dword[esi+8] |
||
582 | fstp dword[eax+8] ;-- |
||
583 | fld st |
||
584 | fadd .cos_temp |
||
585 | fst dword[.R_P9+8] |
||
586 | fstp dword[.R_P10+8] |
||
587 | fchs |
||
588 | fld st |
||
589 | fsub .cos_temp |
||
590 | fst dword[.R_P6+8] |
||
591 | fstp dword[.R_P5+8] |
||
592 | fadd .cos_temp |
||
593 | fst dword[.R_P13+8] |
||
594 | fstp dword[.R_P14+8] |
||
595 | |||
596 | fmul [.Mthick] |
||
597 | fmul st,st0 |
||
598 | fchs |
||
599 | fld .MthickSqr |
||
600 | faddp |
||
601 | fabs |
||
602 | fsqrt |
||
603 | fld st |
||
604 | fsub .cos_temp |
||
605 | fst dword[edi+8] ; z coordinate |
||
606 | fstp dword[ebx+8] ;-- |
||
607 | fld st |
||
608 | fadd .cos_temp |
||
609 | fst dword[.R_P8+8] |
||
610 | fstp dword[.R_P11+8] |
||
611 | fchs |
||
612 | fld st |
||
613 | fsub .cos_temp |
||
614 | fst dword[.R_P7+8] |
||
615 | fstp dword[.R_P4+8] |
||
616 | fadd .cos_temp |
||
617 | fst dword[.R_P12+8] |
||
618 | fstp dword[.R_P15+8] |
||
619 | |||
620 | add edi,12 |
||
621 | add esi,12 |
||
622 | add eax,12 ;-- |
||
623 | add ebx,12 ;--- |
||
624 | add [points_count_var],24 ;16 |
||
625 | inc .x |
||
626 | cmp .x,.N/2 |
||
627 | jng @b |
||
628 | ; mov dword[esi],-1 ; <-- end mark |
||
629 | mov [culling_flag],0 |
||
630 | mov esp,ebp |
||
631 | ret |
||
632 | .Mthick dd 0.85 ; size-thickness |
||
633 | |||
634 | make_random_lights: |
||
635 | .temp1 equ ebp-4 |
||
636 | .temp2 equ ebp-8 ; - light vector generate variables |
||
637 | .temp3 equ ebp-12 |
||
638 | .max equ 800 |
||
1931 | yogev_ezra | 639 | RDTSC |
640 | mov [rand_seed],ax |
||
1245 | hidnplayr | 641 | push ebp |
642 | mov ebp,esp |
||
643 | sub esp,12 |
||
644 | mov edi,lights |
||
645 | fninit |
||
646 | mov dword[.temp2],.max |
||
647 | mov dword[.temp3],.max/2 |
||
648 | |||
649 | .again: |
||
650 | xor esi,esi |
||
651 | @@: |
||
652 | mov edx,.max |
||
653 | xor ecx,ecx |
||
654 | call random |
||
655 | sub eax,.max/2 |
||
656 | mov dword[.temp1],eax |
||
657 | fild dword[.temp1] |
||
658 | fidiv dword[.temp3] |
||
659 | fstp dword[edi+esi*4] |
||
660 | inc esi |
||
661 | cmp esi,2 |
||
662 | jne @b |
||
663 | |||
664 | .max1 equ 1000 |
||
665 | mov dword[.temp2],.max1/2 |
||
666 | mov edx,.max1 |
||
667 | xor ecx,ecx |
||
668 | call random |
||
669 | mov dword[.temp1],eax |
||
670 | fild dword[.temp1] |
||
671 | fchs |
||
672 | fidiv dword[.temp2] |
||
673 | fstp dword[edi+8] |
||
674 | |||
675 | xor esi,esi |
||
676 | @@: |
||
677 | mov ecx,220 ; max colors and shine , ecx = 200 - more bright shading |
||
678 | mov edx,255 |
||
679 | call random |
||
680 | mov byte[edi+18+esi],al |
||
681 | inc esi |
||
682 | cmp esi,4 |
||
683 | jne @b |
||
684 | |||
685 | |||
686 | xor esi,esi |
||
687 | @@: |
||
688 | mov ecx,100 ; orginal colors |
||
689 | movzx edx,byte[edi+18+esi] |
||
690 | call random |
||
691 | mov byte[edi+12+esi],al |
||
692 | inc esi |
||
693 | cmp esi,3 |
||
694 | jne @b |
||
695 | |||
696 | xor esi,esi |
||
697 | @@: |
||
698 | mov ecx,1 ; min cols |
||
699 | movzx edx,byte[edi+12+esi] |
||
700 | call random |
||
701 | mov byte[edi+15+esi],al |
||
702 | inc esi |
||
703 | cmp esi,3 |
||
704 | jne @b |
||
705 | |||
706 | add edi,LIGHT_SIZE ;22 |
||
707 | cmp edi,lightsend ; see file View3ds,asm |
||
708 | jne .again |
||
709 | |||
710 | mov esp,ebp |
||
711 | pop ebp |
||
712 | ret |
||
713 | |||
714 | generate_texture2: |
||
715 | .const equ 32 |
||
716 | mov edi,texmap |
||
717 | xor bx,bx |
||
718 | .next_line: |
||
719 | xor dx,dx |
||
720 | .next2stripes: |
||
721 | mov eax,-1 |
||
722 | mov ecx,(TEX_X/.const)*3/4 |
||
723 | rep stosd |
||
724 | mov eax,0x00ff0000 |
||
725 | mov ecx,(TEX_X/.const) |
||
726 | @@: |
||
727 | stosd |
||
728 | dec edi |
||
729 | loop @b |
||
730 | inc dx |
||
731 | cmp dx,.const/2 |
||
732 | jl .next2stripes |
||
733 | inc bx |
||
734 | cmp bx,TEX_Y |
||
735 | jl .next_line |
||
736 | ret |
||
737 | |||
738 | blur_screen: ;blur n times ; blur or fire |
||
739 | ;in - ecx times count |
||
740 | ;.counter equ dword[esp-4] |
||
741 | .counter1 equ dword[esp-8] |
||
1979 | yogev_ezra | 742 | if Ext>=SSE2 |
743 | push ebp |
||
744 | mov ebp,esp |
||
745 | push dword 0x01010101 |
||
746 | movss xmm5,[esp] |
||
747 | shufps xmm5,xmm5,0 |
||
748 | .again_blur: |
||
749 | push ecx |
||
750 | mov edi,screen |
||
751 | mov ecx,SIZE_X*3/4 |
||
752 | xor eax,eax |
||
753 | rep stosd |
||
754 | |||
755 | mov ecx,(SIZE_X*(SIZE_Y-3))*3/16 |
||
756 | .blr: |
||
757 | @@: |
||
2736 | leency | 758 | movaps xmm0,[edi+SIZE_X*3] |
759 | movaps xmm1,[edi-SIZE_X*3] |
||
1979 | yogev_ezra | 760 | movups xmm2,[edi-3] |
761 | movups xmm3,[edi+3] |
||
762 | |||
763 | pavgb xmm0,xmm1 |
||
764 | pavgb xmm2,xmm3 |
||
765 | pavgb xmm0,xmm2 |
||
766 | |||
767 | psubusb xmm0,xmm5 ; importand if fire |
||
768 | |||
2736 | leency | 769 | movaps [edi],xmm0 |
1979 | yogev_ezra | 770 | add edi,16 |
771 | add esi,16 |
||
772 | |||
773 | loop .blr |
||
774 | |||
775 | xor eax,eax |
||
776 | mov ecx,SIZE_X*3/4 |
||
777 | rep stosd |
||
778 | pop ecx |
||
779 | loop .again_blur |
||
780 | mov esp,ebp |
||
781 | pop ebp |
||
782 | end if |
||
783 | |||
784 | if Ext=SSE |
||
1245 | hidnplayr | 785 | emms |
786 | push ebp |
||
787 | mov ebp,esp |
||
1979 | yogev_ezra | 788 | push dword 0x01010101 |
789 | push dword 0x01010101 |
||
790 | movq mm4,[esp] |
||
791 | .again_blur: |
||
792 | push ecx |
||
793 | mov edi,screen |
||
794 | mov ecx,SIZE_X*3/4 |
||
795 | ; pxor mm5,mm5 |
||
796 | xor eax,eax |
||
797 | rep stosd |
||
798 | |||
799 | mov ecx,(SIZE_X*(SIZE_Y-3))*3/8 |
||
800 | .blr: |
||
801 | @@: |
||
802 | movq mm0,[edi+SIZE_X*3] |
||
803 | movq mm1,[edi-SIZE_X*3] |
||
804 | movq mm2,[edi-3] |
||
805 | movq mm3,[edi+3] |
||
806 | |||
807 | pavgb mm0,mm1 |
||
808 | pavgb mm2,mm3 |
||
809 | pavgb mm0,mm2 |
||
810 | |||
811 | psubusb mm0,mm4 ; importand if fire |
||
812 | |||
813 | movq [edi],mm0 |
||
814 | add edi,8 |
||
815 | add esi,8 |
||
816 | |||
817 | loop .blr |
||
818 | |||
819 | xor eax,eax |
||
820 | mov ecx,SIZE_X*3/4 |
||
821 | rep stosd |
||
822 | pop ecx |
||
823 | loop .again_blur |
||
824 | mov esp,ebp |
||
825 | pop ebp |
||
826 | end if |
||
827 | |||
828 | if Ext=MMX |
||
829 | emms |
||
830 | push ebp |
||
831 | mov ebp,esp |
||
1245 | hidnplayr | 832 | push dword 0x0 |
833 | push dword 0x01010101 |
||
834 | .again_blur: |
||
835 | push ecx |
||
836 | mov edi,screen |
||
837 | mov ecx,SIZE_X*3/4 |
||
838 | pxor mm5,mm5 |
||
839 | xor eax,eax |
||
840 | rep stosd |
||
841 | |||
842 | mov ecx,(SIZE_X*(SIZE_Y-3))*3/4 |
||
843 | .blr: |
||
844 | @@: |
||
845 | |||
846 | movd mm0,[edi+SIZE_X*3] |
||
847 | movd mm1,[edi-SIZE_X*3] |
||
848 | movd mm2,[edi-3] |
||
849 | movd mm3,[edi+3] |
||
850 | |||
851 | punpcklbw mm0,mm5 |
||
852 | punpcklbw mm1,mm5 |
||
853 | punpcklbw mm2,mm5 |
||
854 | punpcklbw mm3,mm5 |
||
855 | paddw mm0,mm1 |
||
856 | paddw mm0,mm2 |
||
857 | paddw mm0,mm3 |
||
858 | psrlw mm0,2 |
||
859 | |||
860 | packuswb mm0,mm5 |
||
861 | psubusb mm0,qword[esp] ; importand if fire |
||
862 | movd eax,mm0 |
||
863 | stosd |
||
864 | |||
865 | loop .blr |
||
866 | |||
867 | xor eax,eax |
||
868 | mov ecx,SIZE_X*3/4 |
||
869 | rep stosd |
||
870 | pop ecx |
||
871 | loop .again_blur |
||
872 | mov esp,ebp |
||
873 | pop ebp |
||
874 | end if |
||
875 | if Ext=NON |
||
876 | .blur: |
||
877 | push ecx |
||
878 | xor ecx,ecx |
||
879 | .next_col_coof: |
||
880 | xor esi,esi |
||
881 | xor eax,eax |
||
882 | xor ebx,ebx |
||
883 | mov edi,SIZE_X*SIZE_Y |
||
884 | .next: |
||
885 | mov ebp,esi |
||
886 | dec ebp |
||
887 | |||
888 | cmp ebp,SIZE_X*SIZE_Y-1 ; clipping |
||
889 | jl @f |
||
890 | mov ebp,SIZE_X*SIZE_Y-1 |
||
891 | @@: |
||
892 | or ebp,ebp |
||
893 | jg @f |
||
894 | xor ebp,ebp |
||
895 | @@: |
||
896 | lea edx,[ebp*3+screen] |
||
897 | mov al,byte[edx+ecx] |
||
898 | |||
899 | mov ebp,esi |
||
900 | inc ebp |
||
901 | cmp ebp,SIZE_X*SIZE_Y-1 ; clipping |
||
902 | jl @f |
||
903 | mov ebp,SIZE_X*SIZE_Y-1 |
||
904 | @@: |
||
905 | or ebp,ebp |
||
906 | jg @f |
||
907 | xor ebp,ebp |
||
908 | @@: |
||
909 | lea edx,[ebp*3+screen] |
||
910 | mov bl,byte[edx+ecx] |
||
911 | add eax,ebx |
||
912 | |||
913 | mov ebp,esi |
||
914 | sub ebp,SIZE_X |
||
915 | cmp ebp,SIZE_X*SIZE_Y-1 ; clipping |
||
916 | jl @f |
||
917 | mov ebp,SIZE_X*SIZE_Y-1 |
||
918 | @@: |
||
919 | or ebp,ebp |
||
920 | jg @f |
||
921 | xor ebp,ebp |
||
922 | @@: |
||
923 | lea edx,[ebp*3+screen] |
||
924 | mov bl,byte[edx+ecx] |
||
925 | add eax,ebx |
||
926 | |||
927 | mov ebp,esi |
||
928 | add ebp,SIZE_X |
||
929 | cmp ebp,SIZE_X*SIZE_Y-1 ; clipping |
||
930 | jl @f |
||
931 | mov ebp,SIZE_X*SIZE_Y-1 |
||
932 | @@: |
||
933 | or ebp,ebp |
||
934 | jg @f |
||
935 | xor ebp,ebp |
||
936 | @@: |
||
937 | lea edx,[ebp*3+screen] |
||
938 | mov bl,byte[edx+ecx] |
||
939 | add eax,ebx |
||
940 | |||
941 | shr eax,2 |
||
942 | lea edx,[esi*3+screen] |
||
943 | or al,al |
||
944 | jz @f |
||
945 | dec al ; not importand if fire |
||
946 | mov byte[edx+ecx],al |
||
947 | @@: |
||
948 | |||
949 | inc esi |
||
950 | dec edi |
||
951 | jnz .next |
||
952 | |||
953 | inc ecx |
||
954 | cmp ecx,3 |
||
955 | jne .next_col_coof |
||
956 | pop ecx |
||
957 | dec ecx |
||
958 | jnz .blur |
||
959 | end if |
||
960 | ret |
||
961 | |||
962 | mirror: ; mirror effect - loseless operation |
||
963 | ; in ah - button id = 11, 12, 13 |
||
964 | mov edi,[points_ptr] ; one real point - triple float |
||
965 | mov esi,[points_normals_ptr] ; one 3dvector - triple float dword x,y,z |
||
966 | fninit |
||
967 | movzx ecx,[points_count_var] |
||
968 | |||
969 | cmp ah,11 |
||
970 | je @f |
||
971 | cmp ah,12 |
||
972 | je .yn |
||
973 | cmp ah,13 |
||
974 | je .zn |
||
975 | |||
976 | @@: ; neg x |
||
977 | fld dword[edi] ;x |
||
978 | fchs |
||
979 | fstp dword[edi] ;x |
||
980 | fld dword[esi] |
||
981 | fchs |
||
982 | fstp dword[esi] |
||
983 | add edi,12 |
||
984 | add esi,12 |
||
985 | loop @b |
||
986 | ret |
||
987 | .yn: |
||
988 | fld dword[edi+4] ;y |
||
989 | fchs |
||
990 | fstp dword[edi+4] ;y |
||
991 | fld dword[esi+4] |
||
992 | fchs |
||
993 | fstp dword[esi+4] |
||
994 | |||
995 | add edi,12 |
||
996 | add esi,12 |
||
997 | loop .yn |
||
998 | ret |
||
999 | .zn: |
||
1000 | fld dword[edi+8] ;z |
||
1001 | fchs |
||
1002 | fstp dword[edi+8] ;z |
||
1003 | fld dword[esi+8] |
||
1004 | fchs |
||
1005 | fstp dword[esi+8] |
||
1006 | |||
1007 | add edi,12 |
||
1008 | add esi,12 |
||
1009 | loop .zn |
||
1010 | ret |
||
1011 | |||
1012 | exchange: ; exchange some coords - loseless operation |
||
1013 | mov edi,[points_ptr] ; one real point - triple float |
||
1014 | mov esi,[points_normals_ptr] ; one 3dvector - triple float dword x,y,z |
||
1015 | fninit ; exchange both points and normal vactors coords/coofics |
||
1016 | movzx ecx,[points_count_var] |
||
1017 | |||
1018 | cmp [xchg_flag],1 |
||
1019 | je @f |
||
1020 | cmp [xchg_flag],2 |
||
1021 | je .zx |
||
1022 | cmp [xchg_flag],3 |
||
1023 | je .yz |
||
1024 | @@: |
||
1025 | fld dword[edi] ;x |
||
1026 | fld dword[edi+4] ;y |
||
1027 | fstp dword[edi] ;x |
||
1028 | fstp dword[edi+4] ;y |
||
1029 | fld dword[esi] ;x |
||
1030 | fld dword[esi+4] ;y |
||
1031 | fstp dword[esi] ;x |
||
1032 | fstp dword[esi+4] ;y |
||
1033 | |||
1034 | add esi,12 |
||
1035 | add edi,12 |
||
1036 | loop @b |
||
1037 | ret |
||
1038 | .zx: |
||
1039 | fld dword[edi] ;x |
||
1040 | fld dword[edi+8] ;z |
||
1041 | fstp dword[edi] ;x |
||
1042 | fstp dword[edi+8] ;z |
||
1043 | fld dword[esi] ;x |
||
1044 | fld dword[esi+8] ;y |
||
1045 | fstp dword[esi] ;x |
||
1046 | fstp dword[esi+8] ;y |
||
1047 | |||
1048 | add esi,12 |
||
1049 | add edi,12 |
||
1050 | loop .zx |
||
1051 | ret |
||
1052 | .yz: |
||
1053 | fld dword[edi+8] ;z |
||
1054 | fld dword[edi+4] ;y |
||
1055 | fstp dword[edi+8] ;z |
||
1056 | fstp dword[edi+4] ;y |
||
1057 | fld dword[esi+8] ;x |
||
1058 | fld dword[esi+4] ;y |
||
1059 | fstp dword[esi+8] ;x |
||
1060 | fstp dword[esi+4] ;y |
||
1061 | |||
1062 | add edi,12 |
||
1063 | add esi,12 |
||
1064 | loop .yz |
||
1065 | ret |
||
1066 | |||
1067 | ;#\\\\\\\\\\\\\\\\\\\\\\\\\comented/////////////////////////////// |
||
1068 | if 0 |
||
1069 | calc_attenuation_light: ;; calculate point to spot_light distance |
||
1070 | ; spot light with attenuation ;; and vector, normalize vector, |
||
1071 | ;; calc dot_pr and unlinear color according |
||
1072 | ;; to dot_product, write to color buff |
||
1073 | .distance equ dword[ebp-4] ;; color buff in bumpmap for save the mem |
||
1074 | .temp_col equ word[ebp-6] |
||
1075 | .vector equ [ebp-20] |
||
1076 | .spot_light_ptr equ dword [ebp-24] |
||
1077 | mov ebp,esp |
||
1078 | sub esp,24 |
||
1079 | mov edi,rotated_points_r ;points_rotated |
||
1080 | mov edx,point_normals_rotated |
||
1081 | mov ecx,bumpmap ; mem area with temp points color list |
||
1082 | xor ax,ax ; counter |
||
1083 | mov esi,spot_light_params |
||
1084 | mov .spot_light_ptr,esi |
||
1085 | .again_color: |
||
1086 | push eax |
||
1087 | lea ebx,.vector |
||
1088 | mov esi,.spot_light_ptr ; calc vector fom light to every point |
||
1089 | call make_vector_r |
||
1090 | ; ebx - ptr to result vector |
||
1091 | fld dword [ebx] |
||
1092 | fmul st, st |
||
1093 | fld dword [ebx+4] |
||
1094 | fmul st, st |
||
1095 | fld dword [ebx+8] |
||
1096 | fmul st, st |
||
1097 | faddp st1, st |
||
1098 | faddp st1, st |
||
1099 | fsqrt |
||
1100 | fstp .distance |
||
1101 | push edi |
||
1102 | mov edi,ebx |
||
1103 | call normalize_vector |
||
1104 | ; edi - normalized distance vector |
||
1105 | mov esi,edx |
||
1106 | call dot_product ; esi first vector, edi second vector |
||
1107 | ; st0 - dot product |
||
1108 | fabs ; why not ? - think about it |
||
1109 | pop edi |
||
1110 | fldz |
||
1111 | fcomip st1 |
||
1112 | jbe @f ; st1>0 |
||
1113 | mov dword[ecx],0 |
||
1114 | mov word[ecx+4],0 |
||
1115 | add ecx,6 |
||
1116 | ffree st0 |
||
1117 | jmp .update_counters |
||
1118 | @@: |
||
1119 | ; pop edi |
||
1120 | |||
1121 | ; calc color(with atenuation), write to buff |
||
1122 | ; buff - color of points list |
||
1123 | ; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular |
||
1124 | |||
1125 | push edx |
||
1126 | push edi |
||
1127 | |||
1128 | push ecx |
||
1129 | push ebp |
||
1130 | |||
1131 | ; mov eax,spot_light_params |
||
1132 | mov eax,.spot_light_ptr |
||
1133 | movzx dx,byte[eax+15] |
||
1134 | push dx ; shines |
||
1135 | movzx dx,byte[eax+8] ; b |
||
1136 | push dx ; orginal col |
||
1137 | movzx dx,byte[eax+7] ; g |
||
1138 | push dx |
||
1139 | movzx dx,byte[eax+6] ; r |
||
1140 | push dx |
||
1141 | movzx dx,byte[eax+14] ; max col |
||
1142 | push dx |
||
1143 | movzx dx,byte[eax+13] |
||
1144 | push dx |
||
1145 | movzx dx,byte[eax+12] |
||
1146 | push dx |
||
1147 | movzx dx,byte[eax+11] ; min col |
||
1148 | push dx |
||
1149 | movzx dx,byte[eax+10] |
||
1150 | push dx |
||
1151 | movzx dx,byte[eax+9] |
||
1152 | push dx |
||
1153 | push eax ; dot pr. (in st0) |
||
1154 | call calc_one_col |
||
1155 | ; eax - 0x00rrggbb |
||
1156 | ; brightness = 1 - (distance/light.fadezero)^fogness |
||
1157 | ; if brightness < 0, then brightness = 0 |
||
1158 | ; attenuetion equation taken from 3dica tutorial - 1/d^2 isn't perfect |
||
1159 | ; color = color * brightness ; fogness = <0.5,2.0> |
||
1160 | pop ebp |
||
1161 | pop ecx |
||
1162 | |||
1163 | fld .distance |
||
1164 | mov esi,.spot_light_ptr |
||
1165 | ; fidiv word[spot_light_params+16] ; fadezero |
||
1166 | fidiv word[esi+16] ; fadezero |
||
1167 | ; fmul st,st0 ; fogness = 2 |
||
1168 | fabs ; to be sure |
||
1169 | fchs |
||
1170 | fld1 |
||
1171 | faddp |
||
1172 | fld1 |
||
1173 | fcomip st1 |
||
1174 | jnbe @f |
||
1175 | ffree st0 |
||
1176 | fld1 |
||
1177 | @@: |
||
1178 | fld st ; st - brightness |
||
1179 | ror eax,16 |
||
1180 | movzx bx,al ; al - r |
||
1181 | mov .temp_col,bx |
||
1182 | fimul .temp_col |
||
1183 | fistp word[ecx] |
||
1184 | cmp word[ecx],0 |
||
1185 | jge @f |
||
1186 | mov word[ecx],0 |
||
1187 | @@: |
||
1188 | ; mov edx,dword[spot_light_params+12] ; max colors |
||
1189 | mov edx,dword[esi+12] ; max colors |
||
1190 | movzx bx,dl ; r max |
||
1191 | cmp word[ecx],bx ; choose the brightest for r, g, b |
||
1192 | jl @f |
||
1193 | mov word[ecx],bx |
||
1194 | @@: |
||
1195 | |||
1196 | add ecx,2 |
||
1197 | fld st |
||
1198 | ror eax,16 |
||
1199 | movzx bx,ah ; g |
||
1200 | mov .temp_col,bx |
||
1201 | fimul .temp_col |
||
1202 | fistp word[ecx] |
||
1203 | cmp word[ecx],0 |
||
1204 | jg @f |
||
1205 | mov word[ecx],0 |
||
1206 | @@: |
||
1207 | movzx bx,dh ; g max |
||
1208 | cmp word[ecx],bx |
||
1209 | jle @f |
||
1210 | mov word[ecx],bx |
||
1211 | @@: |
||
1212 | |||
1213 | add ecx,2 |
||
1214 | movzx bx,al ; b |
||
1215 | mov .temp_col,bx |
||
1216 | fimul .temp_col |
||
1217 | fistp word[ecx] |
||
1218 | cmp word[ecx],0 |
||
1219 | jg @f |
||
1220 | mov word[ecx],0 |
||
1221 | @@: |
||
1222 | shr edx,16 |
||
1223 | movzx bx,dl ; b max |
||
1224 | cmp word[ecx],bx |
||
1225 | jle @f |
||
1226 | mov word[ecx],bx |
||
1227 | @@: |
||
1228 | add ecx,2 |
||
1229 | ;end if |
||
1230 | ; ror eax,16 |
||
1231 | ; movzx bx,al |
||
1232 | ; mov word[ecx],bx |
||
1233 | ; ror eax,16 |
||
1234 | ; movzx bx,ah |
||
1235 | ; mov word[ecx+2],bx |
||
1236 | ; xor ah,ah |
||
1237 | ; mov word[ecx+4],ax |
||
1238 | ; add ecx,6 |
||
1239 | |||
1240 | pop edi |
||
1241 | pop edx |
||
1242 | |||
1243 | .update_counters: |
||
1244 | add edx,12 ; normal_size |
||
1245 | add edi,12 ;6 ; 3d point_coord_size |
||
1246 | |||
1247 | pop eax |
||
1248 | inc ax |
||
1249 | cmp ax,[points_count_var] |
||
1250 | jne .again_color |
||
1251 | |||
1252 | add .spot_light_ptr,18 |
||
1253 | cmp .spot_light_ptr,spot_l_end |
||
1254 | jl .again_color |
||
1255 | |||
1256 | mov esp,ebp |
||
1257 | ret |
||
1258 | end if |
||
1259 | ;#\\\\\\\\\\\\\\\\\\\\\\\\\comented////////////////////////////////////0.5,2.0>>-->-2pi;2pi>-1.0;1.0>-2pi;2pi>--->-1;1>-1.0,1.0>-1.0,1.0> |