Subversion Repositories Kolibri OS

Rev

Rev 5218 | Rev 5262 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5153 IgorA 1
 
2
proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword
5256 IgorA 3
; edi -> GLMaterial *m
4
	mov eax,[context]
5
	mov ebx,[p]
6
	mov ecx,[ebx+4] ;ecx = p[1]
7
5153 IgorA 8
 
5256 IgorA 9
	jne @f
10
		mov dword[ebx+4],GL_FRONT ;p[1].i=GL_FRONT
11
		mov edi,ebp
12
		add edi,12
13
		stdcall glopMaterial,eax,edi
14
		mov ecx,GL_BACK
15
	@@:
16
	mov edi,[eax+offs_cont_materials]
17
	cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
18
	je @f
19
		add edi,sizeof.GLMaterial ;else m=&context.materials[1]
20
	@@:
21
5153 IgorA 22
 
5256 IgorA 23
	mov esi,ebx ;esi = &p
24
	add esi,12 ;esi = &p[3]
25
	mov ebx,[ebx+8] ;ebx = p[2]
26
	cmp ebx,GL_EMISSION
27
	jne @f
28
		;add edi,offs_mate_emission ;offs_mate_emission=0
29
		rep movsd
30
		jmp .end_f
31
	@@:
32
	cmp ebx,GL_AMBIENT
33
	jne @f
34
		add edi,offs_mate_ambient
35
		rep movsd
36
		jmp .end_f
37
	@@:
38
	cmp ebx,GL_DIFFUSE
39
	jne @f
40
		add edi,offs_mate_diffuse
41
		rep movsd
42
		jmp .end_f
43
	@@:
44
	cmp ebx,GL_SPECULAR
45
	jne @f
46
		add edi,offs_mate_specular
47
		rep movsd
48
		jmp .end_f
49
	@@:
50
	cmp ebx,GL_SHININESS
51
	jne @f
52
		fld dword[esi]
53
		add edi,offs_mate_shininess
54
		movsd
55
		mov dword[edi],SPECULAR_BUFFER_RESOLUTION
56
		fdiv dword[an180f]
57
		fimul dword[edi]
58
		fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
59
		jmp .end_f
60
	@@:
61
	cmp ebx,GL_AMBIENT_AND_DIFFUSE
62
	jne @f
63
		add edi,offs_mate_ambient
64
		rep movsd
65
		sub esi,16
66
		;edi = &offs_mate_diffuse
67
		mov ecx,4
68
		rep movsd
69
		jmp .end_f
70
	@@: ;default
71
;    assert(0);
5153 IgorA 72
	.end_f:
5256 IgorA 73
	ret
5153 IgorA 74
endp
75
76
 
77
proc glopColorMaterial uses eax ebx ecx, context:dword, p:dword
78
	mov eax,[context]
79
	mov ebx,[p]
80
	mov ecx,[ebx+4] ;ecx = p[1]
81
	mov dword[eax+offs_cont_current_color_material_mode],ecx
82
	mov ecx,[ebx+8] ;ecx = p[2]
83
	mov dword[eax+offs_cont_current_color_material_type],ecx
84
	ret
85
endp
86
87
 
5218 IgorA 88
proc glopLight context:dword, p:dword
5256 IgorA 89
locals
90
	pos V4
91
endl
92
pushad
93
	mov eax,[context]
5218 IgorA 94
	mov ebx,[p]
95
	mov edx,[ebx+4] ;edx = p[1]
96
97
 
98
99
 
100
	imul edx,sizeof.GLLight
101
	add edx,eax
102
	add edx,offs_cont_lights
103
104
 
105
	cmp ecx,GL_AMBIENT
106
	jne @f
107
		mov esi,ebx
108
		add esi,12
109
		mov edi,edx
110
		;add edi,offs_ligh_ambient ;offs_ligh_ambient = 0
111
		mov ecx,4
112
		rep movsd ;l.ambient=v
113
		jmp .end_f
114
	@@:
115
	cmp ecx,GL_DIFFUSE
116
	jne @f
117
		mov esi,ebx
118
		add esi,12
119
		mov edi,edx
120
		add edi,offs_ligh_diffuse
121
		mov ecx,4
122
		rep movsd ;l.diffuse=v
123
		jmp .end_f
124
	@@:
125
	cmp ecx,GL_SPECULAR
126
	jne @f
127
		mov esi,ebx
128
		add esi,12
129
		mov edi,edx
130
		add edi,offs_ligh_specular
131
		mov ecx,4
132
		rep movsd ;l.specular=v
133
		jmp .end_f
134
	@@:
135
	cmp ecx,GL_POSITION
136
	jne @f
137
		mov edi,ebx ;ebx = [ebp+12] = [p] = &p[0]
5256 IgorA 138
		add edi,12 ;&p[3]
139
		mov esi,ebp
140
		sub esi,16 ;&pos
141
		stdcall gl_M4_MulV4, esi,dword[eax+offs_cont_matrix_stack_ptr],edi
142
		mov edi,edx
143
		add edi,offs_ligh_position
144
		mov ecx,4
145
		rep movsd ;l.position=pos
146
147
 
148
		ftst
149
		fstsw ax
150
		sahf
151
		jne .end_i
152
			;mov esi,ebp
153
			sub esi,16 ;&pos
154
			mov edi,edx
155
			add edi,offs_ligh_norm_position
156
			mov ecx,3
157
			rep movsd ;l.norm_position=pos[1,2,3]
158
159
 
160
			;add edi,offs_ligh_norm_position
161
			sub edi,12
162
			stdcall gl_V3_Norm,edi ;&l.norm_position
163
		.end_i:
164
		ffree st0
165
		fincstp
166
		jmp .end_f
5218 IgorA 167
	@@:
168
	cmp ecx,GL_SPOT_DIRECTION
169
	jne @f
170
		mov esi,ebx ;&p[0]
5256 IgorA 171
		add esi,12
5218 IgorA 172
		mov edi,edx
173
		add edi,offs_ligh_spot_direction
174
		mov ecx,3
175
		rep movsd ;l.spot_direction=v[0,1,2]
176
		mov esi,ebx
177
		add esi,12
178
		mov edi,edx
179
		add edi,offs_ligh_norm_spot_direction
180
		mov ecx,3
181
		rep movsd ;l.norm_spot_direction=v[0,1,2]
182
		add edx,offs_ligh_norm_spot_direction
183
		stdcall gl_V3_Norm,edx
184
		jmp .end_f
185
	@@:
186
	cmp ecx,GL_SPOT_EXPONENT
187
	jne @f
188
		mov ecx,[ebx+12]
189
		mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3]
190
		jmp .end_f
191
	@@:
192
	cmp ecx,GL_SPOT_CUTOFF
193
	jne .end_spot_c
5256 IgorA 194
		fld dword[ebp+12] ;float a=v.v[0]
195
;      assert(a == 180 || (a>=0 && a<=90));
5153 IgorA 196
		fst dword[edi+offs_ligh_spot_cutoff] ;l.spot_cutoff=a
5256 IgorA 197
		fcom dword[an180f] ;if (a != 180)
198
		fstsw ax
199
		sahf
200
		jne @f
201
			fldpi
202
			fmulp
203
			fdiv dword[an180f]
204
			fcos
205
			fstp dword[edi+offs_ligh_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
206
			jmp .end_f
207
		@@:
208
		ffree st0
209
		fincstp
210
		jmp .end_f
5218 IgorA 211
	.end_spot_c:
5256 IgorA 212
	cmp ecx,GL_CONSTANT_ATTENUATION
5218 IgorA 213
		mov ecx,[ebx+12]
214
		mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
215
		jmp .end_f
216
	@@:
217
	cmp ecx,GL_LINEAR_ATTENUATION
218
		mov ecx,[ebx+12]
219
		mov [edi+offs_ligh_attenuation+4],ecx ;l->attenuation[1]=p[3]
220
		jmp .end_f
221
	@@:
222
	cmp ecx,GL_QUADRATIC_ATTENUATION
223
		mov ecx,[ebx+12]
224
		mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3]
225
		jmp .end_f
226
	@@: ;default:
227
;    assert(0);
5153 IgorA 228
	.end_f:
5218 IgorA 229
popad
5256 IgorA 230
	ret
5218 IgorA 231
endp
232
233
 
5153 IgorA 234
 
235
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
236
	mov edi,[context]
237
	mov ebx,[p]
238
	mov ebx,[ebx+4]
5256 IgorA 239
	mov esi,[ebp+12] ;&p[0]
240
	add esi,8 ;&p[2]
241
5153 IgorA 242
 
5256 IgorA 243
	jne @f
5153 IgorA 244
		mov ecx,4
245
		add edi,offs_cont_ambient_light_model
5256 IgorA 246
		rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
5153 IgorA 247
		jmp .end_f
248
	@@:
249
	cmp ebx,GL_LIGHT_MODEL_LOCAL_VIEWER
5256 IgorA 250
	jne @f
5153 IgorA 251
		fld dword[esi] ;st0 = p[2]
5256 IgorA 252
		fistp dword[edi+offs_cont_local_light_model]
5153 IgorA 253
		jmp .end_f
254
	@@:
255
	cmp ebx,GL_LIGHT_MODEL_TWO_SIDE
5256 IgorA 256
	jne @f
5153 IgorA 257
		fld dword[esi] ;st0 = p[2]
5256 IgorA 258
		fistp dword[edi+offs_cont_light_model_two_side]
5153 IgorA 259
		jmp .end_f
260
	@@: ;default:
261
;    tgl_warning("glopLightModel: illegal pname: 0x%x\n", ebx);
5256 IgorA 262
;    //assert(0);
5153 IgorA 263
	.end_f:
264
	ret
265
endp
266
267
 
5256 IgorA 268
{
269
local .o_1
270
local .o_2
271
local .end_m
272
	fld dword a ;if (a<=0.0)
273
	ftst
274
	fstsw ax
275
	sahf
276
	ja .o_1
277
		ffree st0
278
		fincstp
279
		mov eax,0.0
280
		jmp .end_m ;return 0.0
281
	.o_1:
282
	fld1 ;else if (a>=1.0)
283
	fcompp
284
	fstsw ax
285
	sahf
286
	jb .o_2
287
		mov eax,1.0
288
		jmp .end_m ;return 1.0
289
	.o_2:
290
	mov eax,dword a ;else return a
291
	.end_m:
292
}
293
5153 IgorA 294
 
295
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
296
	mov eax,[context]
297
	mov ebx,[light]
298
	imul ebx,sizeof.GLLight
299
	add ebx,eax
5256 IgorA 300
	add ebx,offs_cont_lights
301
5153 IgorA 302
 
303
	cmp dword[ebx+offs_ligh_enabled],0
304
	jne @f
305
		not ecx
306
	@@:
307
	and ecx,[v]
308
	or ecx,ecx
5256 IgorA 309
	jz @f
310
		;if (v && !l.enabled)
5153 IgorA 311
		mov dword[ebx+offs_ligh_enabled],1
312
		mov ecx,[eax+offs_cont_first_light]
313
		mov [ebx+offs_ligh_next],ecx
314
		mov [eax+offs_cont_first_light],ebx ;context.first_light = l
315
		mov dword[ebx+offs_ligh_prev],0 ;l.prev = NULL
316
		jmp .end_f
317
	@@:
318
	xor ecx,ecx
319
	cmp dword[v],0
320
	jne @f
321
		not ecx
322
	@@:
323
	and ecx,[ebx+offs_ligh_enabled]
324
	or ecx,ecx
5256 IgorA 325
	jz .end_f
326
		;else if (!v && l.enabled)
5153 IgorA 327
		mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
328
		mov ecx,[ebx+offs_ligh_next]
329
		cmp dword[ebx+offs_ligh_prev],0 ;if (l.prev == NULL)
330
		jne .els_0
331
			mov [eax+offs_cont_first_light],ecx	;context.first_light = l.next
332
			jmp @f
333
		.els_0:
334
			mov eax,[ebx+offs_ligh_prev]
335
			mov [eax+offs_ligh_next],ecx ;l.prev.next = l.next
336
		@@:
337
		cmp dword[ebx+offs_ligh_next],0
338
		je .end_f
339
			mov ecx,[ebx+offs_ligh_prev]
340
			mov eax,[ebx+offs_ligh_next]
341
			mov [eax+offs_ligh_prev],ecx ;l.next.prev = l.prev
342
	.end_f:
343
	ret
344
endp
345
346
 
5256 IgorA 347
fl_1e_3 dd 1.0e-3
348
349
 
5153 IgorA 350
align 4
351
proc gl_shade_vertex, context:dword, v:dword
352
locals
5256 IgorA 353
	R dd ? ;float
354
	G dd ? ;float
355
	B dd ? ;float
356
	A dd ? ;float
357
	s V3
358
	d V3
359
	dist dd ? ;float
360
	tmp dd ? ;float
361
	att dd ? ;float
362
	dot_spot dd ? ;float
363
	lR dd ? ;float
364
	lB dd ? ;float
365
	lG dd ? ;float
366
	twoside dd ? ;int
367
	idx dd ? ;int
368
	n V3 ;ebp-24
369
	vcoord V3 ;ebp-12
370
endl
371
pushad
372
; ebx -> GLLight *l
373
; ecx -> GLMaterial *m
374
; esi -> GLVertex *v
375
	mov esi,[v]
376
	mov edx,[context]
377
	mov ecx,[edx+offs_cont_materials] ;ecx(m) = &context.materials[0]
378
	mov eax,[edx+offs_cont_light_model_two_side]
379
	mov [twoside],eax
380
5153 IgorA 381
 
5256 IgorA 382
	mov edi,ebp
383
	sub edi,24 ;edi = &n
384
	movsd ;n.X=v.normal.X
385
	movsd ;n.Y=v.normal.Y
386
	movsd ;n.Z=v.normal.Z
387
	mov esi,[v]
388
5153 IgorA 389
 
5256 IgorA 390
	fmul dword[ecx+offs_mate_ambient]
391
	fadd dword[ecx] ;offs_mate_emission=0
392
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
393
	fld dword[edx+offs_cont_ambient_light_model+4]
394
	fmul dword[ecx+offs_mate_ambient+4]
395
	fadd dword[ecx+offs_mate_emission+4]
396
	fstp dword[G]
397
	fld dword[edx+offs_cont_ambient_light_model+8]
398
	fmul dword[ecx+offs_mate_ambient+8]
399
	fadd dword[ecx+offs_mate_emission+8]
400
	fstp dword[B]
401
	clampf [ecx+offs_mate_diffuse+12],0,1
402
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
403
5153 IgorA 404
 
5256 IgorA 405
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
406
		or ebx,ebx
407
		jz .cycle_0_end
408
5153 IgorA 409
 
5256 IgorA 410
		fld dword[ecx+offs_mate_ambient]
411
		fmul dword[ebx+offs_ligh_ambient]
412
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
413
		fld dword[ecx+offs_mate_ambient+4]
414
		fmul dword[ebx+offs_ligh_ambient+4]
415
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
416
		fld dword[ecx+offs_mate_ambient+8]
417
		fmul dword[ebx+offs_ligh_ambient+8]
418
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
419
5153 IgorA 420
 
5256 IgorA 421
		jne .els_0
422
			; light at infinity
423
			mov eax,[ebx+offs_ligh_position]
424
			mov [d],eax ;d.X=l.position.v[0]
425
			mov eax,[ebx+offs_ligh_position+4]
426
			mov [d+4],eax ;d.Y=l.position.v[1]
427
			mov eax,[ebx+offs_ligh_position+8]
428
			mov [d+8],eax ;d.Z=l.position.v[2]
429
			mov dword[att],1.0
430
			jmp .els_0_end
431
		.els_0:
432
			; distance attenuation
433
			fld dword[ebx+offs_ligh_position]
434
			fsub dword[esi+offs_vert_ec]
435
			fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
436
			fld dword[ebx+offs_ligh_position+offs_Y]
437
			fsub dword[esi+offs_vert_ec+offs_Y]
438
			fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
439
			fld dword[ebx+offs_ligh_position+offs_Z]
440
			fsub dword[esi+offs_vert_ec+offs_Z]
441
			fstp dword[d+offs_Z] ;d.Z=l.position.v[2]-v.ec.v[2]
442
			fld dword[d]
443
			fmul st0,st0
444
			fld dword[d+offs_Y]
445
			fmul st0,st0
446
			faddp
447
			fld dword[d+offs_Z]
448
			fmul st0,st0
449
			faddp
450
			fsqrt
451
			fst dword[dist] ;dist=sqrt(d.X^2+d^2+d^2)
452
			fcom dword[fl_1e_3]
453
			fstsw ax
454
			sahf
455
			jbe @f ;if (dist>1.0e-3)
456
				fld1
457
				fdiv st0,st1
458
				fld dword[d]
459
				fmul st0,st1
460
				fstp dword[d]
461
				fld dword[d+offs_Y]
462
				fmul st0,st1
463
				fstp dword[d+offs_Y]
464
				fld dword[d+offs_Z]
465
				fmul st0,st1
466
				fstp dword[d+offs_Z]
467
				ffree st0 ;1.0/dist
468
				fincstp
469
			@@:
470
			fld dword[ebx+offs_ligh_attenuation+8]
471
			fmul st0,st1 ;st0 = dist * l.attenuation[2]
472
			fadd dword[ebx+offs_ligh_attenuation+4]
473
			fmul st0,st1
474
			fadd dword[ebx+offs_ligh_attenuation]
475
			fld1
476
			fdiv st0,st1
477
			fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
478
			ffree st0 ;1.0
479
			fincstp
480
			ffree st0 ;dist
481
			fincstp
482
		.els_0_end:
483
		fld dword[d]
484
		fmul dword[n]
485
		fld dword[d+offs_Y]
486
		fmul dword[n+offs_Y]
487
		faddp
488
		fld dword[d+offs_Z]
489
		fmul dword[n+offs_Z]
490
		faddp ;dot = d.X*n.X+d.Y*n.Y+d.Z*n.Z
491
		cmp dword[twoside],0 ;if (twoside && dot < 0)
492
		je @f
493
		ftst ;if (dot<0)
494
		fstsw ax
495
		sahf
496
		jae @f
497
			fchs ;dot = -dot
498
		@@:
499
		ftst ;if (dot>0)
500
		fstsw ax
501
		sahf
502
		jle .if0_end
503
			; diffuse light
504
			fld dword[ecx+offs_mate_diffuse]
505
			fmul dword[ebx+offs_ligh_diffuse]
506
			fmul st0,st1
507
			fadd dword[lR]
508
			fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
509
			fld dword[ecx+offs_mate_diffuse+4]
510
			fmul dword[ebx+offs_ligh_diffuse+4]
511
			fmul st0,st1
512
			fadd dword[lG]
513
			fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
514
			fld dword[ecx+offs_mate_diffuse+8]
515
			fmul dword[ebx+offs_ligh_diffuse+8]
516
			fmul st0,st1
517
			fadd dword[lB]
518
			fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
519
			ffree st0 ;dot
520
			fincstp
521
5153 IgorA 522
 
5256 IgorA 523
			fld dword[ebx+offs_ligh_spot_cutoff]
524
			fcomp dword[an180f] ;if (l.spot_cutoff != 180)
525
			fstsw ax
526
			sahf
527
			jne .if1_end
528
				fld dword[ebx+offs_ligh_norm_spot_direction]
529
				fmul dword[d]
530
				fld dword[ebx+offs_ligh_norm_spot_direction+4]
531
				fmul dword[d+offs_Y]
532
				faddp
533
				fld dword[ebx+offs_ligh_norm_spot_direction+8]
534
				fmul dword[d+offs_Z]
535
				faddp
536
				fchs
537
				fst dword[dot_spot]
538
				cmp dword[twoside],0 ;if (twoside && dot_spot < 0)
539
				je @f
540
				ftst ;if (dot_spot<0)
541
				fstsw ax
542
				sahf
543
				jae @f
544
					fchs ;dot_spot = -dot_spot
545
				@@:
546
				fcom dword[ebx+offs_ligh_cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
547
				fstsw ax
548
				sahf
549
				jae .els_1
550
					; no contribution
551
					ffree st0 ;dot_spot
552
					fincstp
553
					mov ebx,[ebx+offs_ligh_next]
554
					jmp .cycle_0 ;continue
555
				.els_1:
556
					; TODO: optimize
557
					fld dword[ebx+offs_ligh_spot_exponent]
558
					ftst ;if (l.spot_exponent > 0)
559
					fstsw ax
560
					sahf
561
					jbe @f
562
						fxch st1 ;dot_spot <--> l.spot_exponent
563
						;Вычисляем x^y
564
						;fld y
565
						;fld x
566
						fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
567
						;Теперь считаем 2**z:
568
						fld st0 ;Создаем еще одну копию z
569
						frndint ;Округляем
570
						fsubr st0,st1  ;st1=z, st0=z-trunc(z)
571
						f2xm1  ;st1=z, st0=2**(z-trunc(z))-1
572
						fld1
573
						faddp  ;st1=z, st0=2**(z-trunc(z))
574
						fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
575
						fxch st1
576
						fstp st ;Результат остается на вершине стека st0
577
						fmul dword[att]
578
						fstp dword[att] ;att=att*pow(dot_spot,l.spot_exponent)
579
						jmp .if1_end
580
					@@:
581
					ffree st0 ;l.spot_exponent
582
					fincstp
583
					ffree st0 ;dot_spot
584
					fincstp
585
			.if1_end:
586
5153 IgorA 587
 
5256 IgorA 588
			cmp dword[edx+offs_cont_local_light_model],0 ;if (c.local_light_model)
589
			je .els_2
590
				mov eax,[esi+offs_vert_ec]
591
				mov [vcoord],eax ;vcoord.X=v.ec.X
592
				mov eax,[esi+offs_vert_ec+offs_Y]
593
				mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
594
				mov eax,[esi+offs_vert_ec+offs_Z]
595
				mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
596
				mov eax,ebp
597
				sub eax,12 ;eax = &vcoord
598
				stdcall gl_V3_Norm, eax
599
				fld dword[d]
600
				fsub dword[vcoord]
601
				fstp dword[s] ;s.X=d.X-vcoord.X
602
				fld dword[d+offs_Y]
603
				fsub dword[vcoord+offs_Y]
604
				fstp dword[s+offs_Y] ;s.Y=d.Y-vcoord.Y
605
				fld dword[d+offs_Z]
606
				fsub dword[vcoord+offs_Z]
607
				fstp dword[s+offs_Z] ;s.Z=d.Z-vcoord.Z
608
				jmp .els_2_end
609
			.els_2:
610
				mov eax,[d]
611
				mov [s],eax ;s.X=d.X
612
				mov eax,[d+offs_Y]
613
				mov [s+offs_Y],eax ;s.Y=d.Y
614
				fld1
615
				fadd dword[d+offs_Z]
616
				fstp dword[s+offs_Z] ;s.Z=d.Z+1.0
617
			.els_2_end:
618
			fld dword[n]
619
			fmul st0,st0
620
			fld dword[n+offs_Y]
621
			fmul st0,st0
622
			faddp
623
			fld dword[n+offs_Z]
624
			fmul st0,st0
625
			faddp ;dot_spec = n.X^2 +n.Y^2 +n.Z^2
626
			cmp dword[twoside],0 ;if (twoside && dot_spec < 0)
627
			je @f
628
			ftst ;if (dot_spec < 0)
629
			fstsw ax
630
			sahf
631
			jae @f
632
				fchs ;dot_spec = -dot_spec
633
			@@:
634
			ftst ;if (dot_spec > 0)
635
			fstsw ax
636
			sahf
637
			jae .if0_end
638
				fld dword[s]
639
				fmul st0,st0
640
				fld dword[s+offs_Y]
641
				fmul st0,st0
642
				faddp
643
				fld dword[s+offs_Z]
644
				fmul st0,st0
645
				faddp
646
				fsqrt
647
				fcom dword[fl_1e_3]
648
				fstsw ax
649
				sahf
650
				jbe @f ;if (tmp > 1.0e-3)
651
					fdiv st1,st0 ;dot_spec /= tmp
652
				@@:
653
				ffree st0 ;tmp
654
				fincstp
655
5153 IgorA 656
 
5256 IgorA 657
				; testing specular buffer code
658
				; dot_spec= pow(dot_spec,m.shininess)
659
				stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess]
660
				;eax = specbuf
661
				mov dword[idx],SPECULAR_BUFFER_SIZE
662
				fild dword[idx]
663
				fld1
664
				fcomp
665
				fstsw ax
666
				sahf
667
				jae @f
668
					fmul st0,st1
669
				@@:
670
				fistp dword[idx] ;if (dot_spec < 1.0) idx = (int)(dot_spec*SPECULAR_BUFFER_SIZE)
671
					;else idx = SPECULAR_BUFFER_SIZE;
672
				ffree st0 ;dot_spec
673
				fincstp
674
				shl dword[idx],2
675
				add eax,dword[idx]
676
				fld dword[eax+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
677
				fld dword[ebx+offs_ligh_specular]
678
				fmul st0,st1
679
				fmul dword[ecx+offs_mate_specular]
680
				fadd dword[lR]
681
				fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
682
				fld dword[ebx+offs_ligh_specular+offs_Y]
683
				fmul st0,st1
684
				fmul dword[ecx+offs_mate_specular+offs_Y]
685
				fadd dword[lG]
686
				fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
687
				fld dword[ebx+offs_ligh_specular+offs_Z]
688
				fmul st0,st1
689
				fmul dword[ecx+offs_mate_specular+offs_Z]
690
				fadd dword[lB]
691
				fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
692
				ffree st0 ;dot_spec
693
				fincstp
694
			jmp .if2_end
695
		.if0_end:
696
		ffree st0 ;dot [or] dot_spec
697
		fincstp
698
		.if2_end:
699
5153 IgorA 700
 
5256 IgorA 701
		fld dword[lR]
702
		fmul st0,st1
703
		fadd dword[R]
704
		fstp dword[R] ;R += att * lR
705
		fld dword[lG]
706
		fmul st0,st1
707
		fadd dword[G]
708
		fstp dword[G] ;G += att * lG
709
		fld dword[lB]
710
		fmul st0,st1
711
		fadd dword[B]
712
		fstp dword[B] ;B += att * lB
713
		ffree st0 ;att
714
		fincstp
715
		mov ebx,[ebx+offs_ligh_next]
716
		jmp .cycle_0
717
	.cycle_0_end:
718
5153 IgorA 719
 
5256 IgorA 720
	mov [esi+offs_vert_color],eax ;v.color.v[0]=clampf(R,0,1)
721
	clampf [G],0,1
722
	mov [esi+offs_vert_color+4],eax ;v.color.v[1]=clampf(G,0,1)
723
	clampf [B],0,1
724
	mov [esi+offs_vert_color+8],eax ;v.color.v[2]=clampf(B,0,1)
725
	mov eax,[A]
726
	mov [esi+offs_vert_color+12],eax ;v.color.v[3]=A
727
popad
728
	ret
5153 IgorA 729
endp
730
>
731