Subversion Repositories Kolibri OS

Rev

Rev 5256 | Rev 5269 | 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
 
5262 IgorA 350
txt_mate db 'Material',0
351
txt_colo db 'Color',0
352
end if
353
354
 
5153 IgorA 355
align 4
356
proc gl_shade_vertex, context:dword, v:dword
357
locals
5256 IgorA 358
	R dd ? ;float ebp-100
5262 IgorA 359
	G dd ? ;float ebp-96
360
	B dd ? ;float ebp-92
361
	A dd ? ;float ebp-88
362
	s V3 ;ebp-84
363
	d V3 ;ebp-72
364
	dist dd ? ;float ebp-60
365
	tmp dd ? ;float ebp-56
366
	att dd ? ;float ebp-52
367
	dot_spot dd ? ;float ebp-48
368
	lR dd ? ;float ebp-44
369
	lB dd ? ;float ebp-40
370
	lG dd ? ;float ebp-36
371
	twoside dd ? ;int ebp-32
372
	idx dd ? ;int ebp-28
373
	n V3 ;ebp-24
5256 IgorA 374
	vcoord V3 ;ebp-12
375
endl
376
pushad
377
; ebx -> GLLight *l
378
; ecx -> GLMaterial *m
379
; esi -> GLVertex *v
380
	mov esi,[v]
381
	mov edx,[context]
382
	mov ecx,[edx+offs_cont_materials] ;ecx(m) = &context.materials[0]
383
	mov eax,[edx+offs_cont_light_model_two_side]
384
	mov [twoside],eax
385
5153 IgorA 386
 
5256 IgorA 387
	mov edi,ebp
388
	sub edi,24 ;edi = &n
389
	movsd ;n.X=v.normal.X
390
	movsd ;n.Y=v.normal.Y
391
	movsd ;n.Z=v.normal.Z
392
	mov esi,[v]
393
5153 IgorA 394
 
5262 IgorA 395
push ecx
396
	stdcall dbg_print,txt_mate,txt_nl
397
	add ecx,offs_mate_emission
398
	stdcall gl_print_matrix,ecx,1
399
	add ecx,offs_mate_ambient-offs_mate_emission
400
	stdcall gl_print_matrix,ecx,1
401
	add ecx,offs_mate_specular-offs_mate_ambient
402
	stdcall gl_print_matrix,ecx,1
403
	add ecx,offs_mate_diffuse-offs_mate_specular
404
	stdcall gl_print_matrix,ecx,1
405
pop ecx
406
end if
407
408
 
5256 IgorA 409
	fmul dword[ecx+offs_mate_ambient]
410
	fadd dword[ecx] ;offs_mate_emission=0
411
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
412
	fld dword[edx+offs_cont_ambient_light_model+4]
413
	fmul dword[ecx+offs_mate_ambient+4]
414
	fadd dword[ecx+offs_mate_emission+4]
415
	fstp dword[G]
416
	fld dword[edx+offs_cont_ambient_light_model+8]
417
	fmul dword[ecx+offs_mate_ambient+8]
418
	fadd dword[ecx+offs_mate_emission+8]
419
	fstp dword[B]
420
	clampf [ecx+offs_mate_diffuse+12],0,1
421
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
422
5153 IgorA 423
 
5256 IgorA 424
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
425
		or ebx,ebx
426
		jz .cycle_0_end
427
5153 IgorA 428
 
5256 IgorA 429
		fld dword[ecx+offs_mate_ambient]
430
		fmul dword[ebx] ;offs_ligh_ambient=0
5262 IgorA 431
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
5256 IgorA 432
		fld dword[ecx+offs_mate_ambient+4]
433
		fmul dword[ebx+offs_ligh_ambient+4]
434
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
435
		fld dword[ecx+offs_mate_ambient+8]
436
		fmul dword[ebx+offs_ligh_ambient+8]
437
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
438
5153 IgorA 439
 
5256 IgorA 440
		jne .els_0
441
			; light at infinity
442
			mov eax,[ebx+offs_ligh_position]
443
			mov [d],eax ;d.X=l.position.v[0]
444
			mov eax,[ebx+offs_ligh_position+4]
445
			mov [d+4],eax ;d.Y=l.position.v[1]
446
			mov eax,[ebx+offs_ligh_position+8]
447
			mov [d+8],eax ;d.Z=l.position.v[2]
448
			mov dword[att],1.0
449
			jmp .els_0_end
450
		.els_0:
451
			; distance attenuation
452
			fld dword[ebx+offs_ligh_position]
453
			fsub dword[esi+offs_vert_ec]
454
			fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
455
			fld dword[ebx+offs_ligh_position+offs_Y]
456
			fsub dword[esi+offs_vert_ec+offs_Y]
457
			fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
458
			fld dword[ebx+offs_ligh_position+offs_Z]
459
			fsub dword[esi+offs_vert_ec+offs_Z]
460
			fstp dword[d+offs_Z] ;d.Z=l.position.v[2]-v.ec.v[2]
461
			fld dword[d]
462
			fmul st0,st0
463
			fld dword[d+offs_Y]
464
			fmul st0,st0
465
			faddp
466
			fld dword[d+offs_Z]
467
			fmul st0,st0
468
			faddp
469
			fsqrt
470
			fst dword[dist] ;dist=sqrt(d.X^2+d^2+d^2)
471
			fcom dword[fl_1e_3]
472
			fstsw ax
473
			sahf
474
			jbe @f ;if (dist>1.0e-3)
475
				fld1
476
				fdiv st0,st1
477
				fld dword[d]
478
				fmul st0,st1
479
				fstp dword[d]
480
				fld dword[d+offs_Y]
481
				fmul st0,st1
482
				fstp dword[d+offs_Y]
483
				fld dword[d+offs_Z]
484
				fmul st0,st1
485
				fstp dword[d+offs_Z]
486
				ffree st0 ;1.0/dist
487
				fincstp
488
			@@:
489
			fld dword[ebx+offs_ligh_attenuation+8]
490
			fmul st0,st1 ;st0 = dist * l.attenuation[2]
491
			fadd dword[ebx+offs_ligh_attenuation+4]
492
			fmul st0,st1
493
			fadd dword[ebx+offs_ligh_attenuation]
494
			fld1
495
			fdiv st0,st1
496
			fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
497
			ffree st0 ;1.0
498
			fincstp
499
			ffree st0 ;dist
500
			fincstp
501
		.els_0_end:
502
		fld dword[d]
503
		fmul dword[n]
504
		fld dword[d+offs_Y]
505
		fmul dword[n+offs_Y]
506
		faddp
507
		fld dword[d+offs_Z]
508
		fmul dword[n+offs_Z]
509
		faddp ;dot = d.X*n.X+d.Y*n.Y+d.Z*n.Z
510
		cmp dword[twoside],0 ;if (twoside && dot < 0)
511
		je @f
512
		ftst ;if (dot<0)
513
		fstsw ax
514
		sahf
515
		jae @f
516
			fchs ;dot = -dot
517
		@@:
518
		ftst ;if (dot>0)
519
		fstsw ax
520
		sahf
521
		jle .if0_end
522
			; diffuse light
523
			fld dword[ecx+offs_mate_diffuse]
524
			fmul dword[ebx+offs_ligh_diffuse]
525
			fmul st0,st1
526
			fadd dword[lR]
527
			fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
528
			fld dword[ecx+offs_mate_diffuse+4]
529
			fmul dword[ebx+offs_ligh_diffuse+4]
530
			fmul st0,st1
531
			fadd dword[lG]
532
			fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
533
			fld dword[ecx+offs_mate_diffuse+8]
534
			fmul dword[ebx+offs_ligh_diffuse+8]
535
			fmul st0,st1
536
			fadd dword[lB]
537
			fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
538
			ffree st0 ;dot
539
			fincstp
540
5153 IgorA 541
 
5256 IgorA 542
			fld dword[ebx+offs_ligh_spot_cutoff]
543
			fcomp dword[an180f] ;if (l.spot_cutoff != 180)
544
			fstsw ax
545
			sahf
546
			jne .if1_end
547
				fld dword[ebx+offs_ligh_norm_spot_direction]
548
				fmul dword[d]
549
				fld dword[ebx+offs_ligh_norm_spot_direction+4]
550
				fmul dword[d+offs_Y]
551
				faddp
552
				fld dword[ebx+offs_ligh_norm_spot_direction+8]
553
				fmul dword[d+offs_Z]
554
				faddp
555
				fchs
556
				fst dword[dot_spot]
557
				cmp dword[twoside],0 ;if (twoside && dot_spot < 0)
558
				je @f
559
				ftst ;if (dot_spot<0)
560
				fstsw ax
561
				sahf
562
				jae @f
563
					fchs ;dot_spot = -dot_spot
564
				@@:
565
				fcom dword[ebx+offs_ligh_cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
566
				fstsw ax
567
				sahf
568
				jae .els_1
569
					; no contribution
570
					ffree st0 ;dot_spot
571
					fincstp
572
					mov ebx,[ebx+offs_ligh_next]
573
					jmp .cycle_0 ;continue
574
				.els_1:
575
					; TODO: optimize
576
					fld dword[ebx+offs_ligh_spot_exponent]
577
					ftst ;if (l.spot_exponent > 0)
578
					fstsw ax
579
					sahf
580
					jbe @f
581
						fxch st1 ;dot_spot <--> l.spot_exponent
582
						;Вычисляем x^y
583
						;fld y
584
						;fld x
585
						fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
586
						;Теперь считаем 2**z:
587
						fld st0 ;Создаем еще одну копию z
588
						frndint ;Округляем
589
						fsubr st0,st1  ;st1=z, st0=z-trunc(z)
590
						f2xm1  ;st1=z, st0=2**(z-trunc(z))-1
591
						fld1
592
						faddp  ;st1=z, st0=2**(z-trunc(z))
593
						fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
594
						fxch st1
595
						fstp st ;Результат остается на вершине стека st0
596
						fmul dword[att]
597
						fstp dword[att] ;att=att*pow(dot_spot,l.spot_exponent)
598
						jmp .if1_end
599
					@@:
600
					ffree st0 ;l.spot_exponent
601
					fincstp
602
					ffree st0 ;dot_spot
603
					fincstp
604
			.if1_end:
605
5153 IgorA 606
 
5256 IgorA 607
			cmp dword[edx+offs_cont_local_light_model],0 ;if (c.local_light_model)
608
			je .els_2
609
				mov eax,[esi+offs_vert_ec]
610
				mov [vcoord],eax ;vcoord.X=v.ec.X
611
				mov eax,[esi+offs_vert_ec+offs_Y]
612
				mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
613
				mov eax,[esi+offs_vert_ec+offs_Z]
614
				mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
615
				mov eax,ebp
616
				sub eax,12 ;eax = &vcoord
617
				stdcall gl_V3_Norm, eax
618
				fld dword[d]
619
				fsub dword[vcoord]
620
				fstp dword[s] ;s.X=d.X-vcoord.X
621
				fld dword[d+offs_Y]
622
				fsub dword[vcoord+offs_Y]
623
				fstp dword[s+offs_Y] ;s.Y=d.Y-vcoord.Y
624
				fld dword[d+offs_Z]
625
				fsub dword[vcoord+offs_Z]
626
				fstp dword[s+offs_Z] ;s.Z=d.Z-vcoord.Z
627
				jmp .els_2_end
628
			.els_2:
629
				mov eax,[d]
630
				mov [s],eax ;s.X=d.X
631
				mov eax,[d+offs_Y]
632
				mov [s+offs_Y],eax ;s.Y=d.Y
633
				fld1
634
				fadd dword[d+offs_Z]
635
				fstp dword[s+offs_Z] ;s.Z=d.Z+1.0
636
			.els_2_end:
637
			fld dword[n]
638
			fmul st0,st0
639
			fld dword[n+offs_Y]
640
			fmul st0,st0
641
			faddp
642
			fld dword[n+offs_Z]
643
			fmul st0,st0
644
			faddp ;dot_spec = n.X^2 +n.Y^2 +n.Z^2
645
			cmp dword[twoside],0 ;if (twoside && dot_spec < 0)
646
			je @f
647
			ftst ;if (dot_spec < 0)
648
			fstsw ax
649
			sahf
650
			jae @f
651
				fchs ;dot_spec = -dot_spec
652
			@@:
653
			ftst ;if (dot_spec > 0)
654
			fstsw ax
655
			sahf
656
			jae .if0_end
657
				fld dword[s]
658
				fmul st0,st0
659
				fld dword[s+offs_Y]
660
				fmul st0,st0
661
				faddp
662
				fld dword[s+offs_Z]
663
				fmul st0,st0
664
				faddp
665
				fsqrt
666
				fcom dword[fl_1e_3]
667
				fstsw ax
668
				sahf
669
				jbe @f ;if (tmp > 1.0e-3)
670
					fdiv st1,st0 ;dot_spec /= tmp
671
				@@:
672
				ffree st0 ;tmp
673
				fincstp
674
5153 IgorA 675
 
5256 IgorA 676
				; testing specular buffer code
677
				; dot_spec= pow(dot_spec,m.shininess)
678
				stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess]
679
				mov edi,eax ;edi = specbuf
5262 IgorA 680
				mov dword[idx],SPECULAR_BUFFER_SIZE
5256 IgorA 681
				fild dword[idx]
682
				fld1
683
				fcomp
684
				fstsw ax
685
				sahf
686
				jae @f
687
					fmul st0,st1
688
				@@:
689
				fistp dword[idx] ;if (dot_spec < 1.0) idx = (int)(dot_spec*SPECULAR_BUFFER_SIZE)
690
					;else idx = SPECULAR_BUFFER_SIZE;
691
				ffree st0 ;dot_spec
692
				fincstp
693
				shl dword[idx],2
694
				add edi,dword[idx]
5262 IgorA 695
				fld dword[edi+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
696
				fld dword[ebx+offs_ligh_specular]
5256 IgorA 697
				fmul st0,st1
698
				fmul dword[ecx+offs_mate_specular]
699
				fadd dword[lR]
700
				fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
701
				fld dword[ebx+offs_ligh_specular+4]
5262 IgorA 702
				fmul st0,st1
5256 IgorA 703
				fmul dword[ecx+offs_mate_specular+4]
5262 IgorA 704
				fadd dword[lG]
5256 IgorA 705
				fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
706
				fld dword[ebx+offs_ligh_specular+8]
5262 IgorA 707
				fmul st0,st1
5256 IgorA 708
				fmul dword[ecx+offs_mate_specular+8]
5262 IgorA 709
				fadd dword[lB]
5256 IgorA 710
				fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
711
				ffree st0 ;dot_spec
712
				fincstp
713
			jmp .if2_end
714
		.if0_end:
715
		ffree st0 ;dot [or] dot_spec
716
		fincstp
717
		.if2_end:
718
5153 IgorA 719
 
5256 IgorA 720
		fld dword[lR]
721
		fmul st0,st1
722
		fadd dword[R]
723
		fstp dword[R] ;R += att * lR
724
		fld dword[lG]
725
		fmul st0,st1
726
		fadd dword[G]
727
		fstp dword[G] ;G += att * lG
728
		fld dword[lB]
729
		fmul st0,st1
730
		fadd dword[B]
731
		fstp dword[B] ;B += att * lB
732
		ffree st0 ;att
733
		fincstp
734
		mov ebx,[ebx+offs_ligh_next]
735
		jmp .cycle_0
736
	.cycle_0_end:
737
5153 IgorA 738
 
5256 IgorA 739
	mov [esi+offs_vert_color],eax ;v.color.v[0]=clampf(R,0,1)
740
	clampf [G],0,1
741
	mov [esi+offs_vert_color+4],eax ;v.color.v[1]=clampf(G,0,1)
742
	clampf [B],0,1
743
	mov [esi+offs_vert_color+8],eax ;v.color.v[2]=clampf(B,0,1)
744
	mov eax,[A]
745
	mov [esi+offs_vert_color+12],eax ;v.color.v[3]=A
746
if DEBUG ;offs_vert_color
5262 IgorA 747
push esi
748
	stdcall dbg_print,txt_colo,txt_nl
749
	add esi,offs_vert_color
750
	stdcall gl_print_matrix,esi,1
751
pop esi
752
end if
753
popad
5256 IgorA 754
	ret
5153 IgorA 755
endp
756
>
757