-
Notifications
You must be signed in to change notification settings - Fork 90
/
r_alias.c
1216 lines (996 loc) · 34.5 KB
/
r_alias.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// r_alias.c: routines for setting up to draw alias models
/*
** use a real variable to control lerping
*/
#include "r_local.h"
//PGM
extern byte iractive;
//PGM
int r_amodels_drawn;
affinetridesc_t r_affinetridesc;
vec3_t r_plightvec;
//qb: colored lighting from leilei
vec3_t r_prlightvec;
vec3_t r_pglightvec;
vec3_t r_pblightvec;
vec3_t r_lerped[1024];
vec3_t r_lerp_frontv, r_lerp_backv, r_lerp_move;
int r_ambientlight;
int r_aliasblendcolor;
float r_shadelight;
daliasframe_t *r_thisframe, *r_lastframe;
dmdl_t *s_pmdl;
float aliastransform[3][4];
float aliasworldtransform[3][4];
float aliasoldworldtransform[3][4];
static float s_ziscale;
static vec3_t s_alias_forward, s_alias_right, s_alias_up;
#define NUMVERTEXNORMALS 162
float r_avertexnormals[NUMVERTEXNORMALS][3] = {
#include "anorms.h"
};
void R_AliasSetUpLerpData(dmdl_t *pmdl, float backlerp);
void R_AliasSetUpTransform(void);
void R_AliasTransformVector(vec3_t in, vec3_t out, float m[3][4]);
void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv);
void R_AliasTransformFinalVerts(int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv);
void R_AliasLerpFrames(dmdl_t *paliashdr, float backlerp);
/*
================
R_AliasCheckBBox
================
*/
#define BBOX_TRIVIAL_ACCEPT 0
#define BBOX_MUST_CLIP_XY 1
#define BBOX_MUST_CLIP_Z 2
#define BBOX_TRIVIAL_REJECT 8
/*
** R_AliasCheckFrameBBox
**
** Checks a specific alias frame bounding box
*/
unsigned long R_AliasCheckFrameBBox(daliasframe_t *frame, float worldxf[3][4])
{
unsigned long aggregate_and_clipcode = ~0U,
aggregate_or_clipcode = 0;
int i;
vec3_t mins, maxs;
vec3_t transformed_min, transformed_max;
qboolean zclipped = false, zfullyclipped = true;
/*
** get the exact frame bounding box
*/
for (i = 0; i < 3; i++)
{
mins[i] = frame->translate[i];
maxs[i] = mins[i] + frame->scale[i] * 255;
}
/*
** transform the min and max values into view space
*/
R_AliasTransformVector(mins, transformed_min, aliastransform);
R_AliasTransformVector(maxs, transformed_max, aliastransform);
if (transformed_min[2] >= ALIAS_Z_CLIP_PLANE)
zfullyclipped = false;
if (transformed_max[2] >= ALIAS_Z_CLIP_PLANE)
zfullyclipped = false;
if (zfullyclipped)
{
return BBOX_TRIVIAL_REJECT;
}
if (zclipped)
{
return (BBOX_MUST_CLIP_XY | BBOX_MUST_CLIP_Z);
}
/*
** build a transformed bounding box from the given min and max
*/
for (i = 0; i < 8; i++)
{
int j;
vec3_t tmp, transformed;
unsigned long clipcode = 0;
if (i & 1)
tmp[0] = mins[0];
else
tmp[0] = maxs[0];
if (i & 2)
tmp[1] = mins[1];
else
tmp[1] = maxs[1];
if (i & 4)
tmp[2] = mins[2];
else
tmp[2] = maxs[2];
R_AliasTransformVector(tmp, transformed, worldxf);
for (j = 0; j < 4; j++)
{
float dp = DotProduct(transformed, view_clipplanes[j].normal);
if ((dp - view_clipplanes[j].dist) < 0.0F)
clipcode |= 1 << j;
}
aggregate_and_clipcode &= clipcode;
aggregate_or_clipcode |= clipcode;
}
if (aggregate_and_clipcode)
{
return BBOX_TRIVIAL_REJECT;
}
if (!aggregate_or_clipcode)
{
return BBOX_TRIVIAL_ACCEPT;
}
return BBOX_MUST_CLIP_XY;
}
qboolean R_AliasCheckBBox(void)
{
unsigned long ccodes[2] = { 0, 0 };
ccodes[0] = R_AliasCheckFrameBBox(r_thisframe, aliasworldtransform);
/*
** non-lerping model
*/
if (currententity->backlerp == 0)
{
if (ccodes[0] == BBOX_TRIVIAL_ACCEPT)
return BBOX_TRIVIAL_ACCEPT;
else if (ccodes[0] & BBOX_TRIVIAL_REJECT)
return BBOX_TRIVIAL_REJECT;
else
return (ccodes[0] & ~BBOX_TRIVIAL_REJECT);
}
ccodes[1] = R_AliasCheckFrameBBox(r_lastframe, aliasoldworldtransform);
if ((ccodes[0] | ccodes[1]) == BBOX_TRIVIAL_ACCEPT)
return BBOX_TRIVIAL_ACCEPT;
else if ((ccodes[0] & ccodes[1]) & BBOX_TRIVIAL_REJECT)
return BBOX_TRIVIAL_REJECT;
else
return (ccodes[0] | ccodes[1]) & ~BBOX_TRIVIAL_REJECT;
}
/*
================
R_AliasTransformVector
================
*/
void R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4])
{
out[0] = DotProduct(in, xf[0]) + xf[0][3];
out[1] = DotProduct(in, xf[1]) + xf[1][3];
out[2] = DotProduct(in, xf[2]) + xf[2][3];
}
/*
================
R_AliasPreparePoints
General clipped case
================
*/
typedef struct
{
int num_points;
dtrivertx_t *last_verts; // verts from the last frame
dtrivertx_t *this_verts; // verts from this frame
finalvert_t *dest_verts; // destination for transformed verts
} aliasbatchedtransformdata_t;
aliasbatchedtransformdata_t aliasbatchedtransformdata;
void R_AliasPreparePoints(void)
{
int i;
dstvert_t *pstverts;
dtriangle_t *ptri;
finalvert_t *pfv[3];
finalvert_t finalverts[MAXALIASVERTS +
((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 3];
finalvert_t *pfinalverts;
//PGM
iractive = (r_newrefdef.rdflags & RDF_IRGOGGLES && currententity->flags & RF_IR_VISIBLE);
// iractive = 0;
// if(r_newrefdef.rdflags & RDF_IRGOGGLES && currententity->flags & RF_IR_VISIBLE)
// iractive = 1;
//PGM
// put work vertexes on stack, cache aligned
pfinalverts = (finalvert_t *)
(((intptr_t)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
aliasbatchedtransformdata.num_points = s_pmdl->num_xyz;
aliasbatchedtransformdata.last_verts = r_lastframe->verts;
aliasbatchedtransformdata.this_verts = r_thisframe->verts;
aliasbatchedtransformdata.dest_verts = pfinalverts;
R_AliasTransformFinalVerts(aliasbatchedtransformdata.num_points,
aliasbatchedtransformdata.dest_verts,
aliasbatchedtransformdata.last_verts,
aliasbatchedtransformdata.this_verts);
// clip and draw all triangles
//
pstverts = (dstvert_t *)((byte *)s_pmdl + s_pmdl->ofs_st);
ptri = (dtriangle_t *)((byte *)s_pmdl + s_pmdl->ofs_tris);
if ((currententity->flags & RF_WEAPONMODEL) && (r_lefthand->value == 1.0F))
{
for (i = 0; i < s_pmdl->num_tris; i++, ptri++)
{
pfv[0] = &pfinalverts[ptri->index_xyz[0]];
pfv[1] = &pfinalverts[ptri->index_xyz[1]];
pfv[2] = &pfinalverts[ptri->index_xyz[2]];
if (pfv[0]->flags & pfv[1]->flags & pfv[2]->flags)
continue; // completely clipped
// insert s/t coordinates
pfv[0]->s = pstverts[ptri->index_st[0]].s << 16;
pfv[0]->t = pstverts[ptri->index_st[0]].t << 16;
pfv[1]->s = pstverts[ptri->index_st[1]].s << 16;
pfv[1]->t = pstverts[ptri->index_st[1]].t << 16;
pfv[2]->s = pstverts[ptri->index_st[2]].s << 16;
pfv[2]->t = pstverts[ptri->index_st[2]].t << 16;
if (!(pfv[0]->flags | pfv[1]->flags | pfv[2]->flags))
{ // totally unclipped
aliastriangleparms.a = pfv[2];
aliastriangleparms.b = pfv[1];
aliastriangleparms.c = pfv[0];
R_DrawTriangle();
}
else
{
if (coloredlights)
R_AliasClipTriangleRGB(pfv[2], pfv[1], pfv[0]);
else
R_AliasClipTriangle(pfv[2], pfv[1], pfv[0]);
}
}
}
else
{
for (i = 0; i < s_pmdl->num_tris; i++, ptri++)
{
pfv[0] = &pfinalverts[ptri->index_xyz[0]];
pfv[1] = &pfinalverts[ptri->index_xyz[1]];
pfv[2] = &pfinalverts[ptri->index_xyz[2]];
if (pfv[0]->flags & pfv[1]->flags & pfv[2]->flags)
continue; // completely clipped
// insert s/t coordinates
pfv[0]->s = pstverts[ptri->index_st[0]].s << 16;
pfv[0]->t = pstverts[ptri->index_st[0]].t << 16;
pfv[1]->s = pstverts[ptri->index_st[1]].s << 16;
pfv[1]->t = pstverts[ptri->index_st[1]].t << 16;
pfv[2]->s = pstverts[ptri->index_st[2]].s << 16;
pfv[2]->t = pstverts[ptri->index_st[2]].t << 16;
if (!(pfv[0]->flags | pfv[1]->flags | pfv[2]->flags))
{ // totally unclipped
aliastriangleparms.a = pfv[0];
aliastriangleparms.b = pfv[1];
aliastriangleparms.c = pfv[2];
R_DrawTriangle();
}
else
{ // partially clipped
if (coloredlights)
R_AliasClipTriangleRGB(pfv[0], pfv[1], pfv[2]);
else
R_AliasClipTriangle(pfv[0], pfv[1], pfv[2]);
}
}
}
}
/*
================
R_AliasSetUpTransform
================
*/
void R_AliasSetUpTransform(void)
{
int i;
static float viewmatrix[3][4];
vec3_t angles;
// TODO: should really be stored with the entity instead of being reconstructed
// TODO: should use a look-up table
// TODO: could cache lazily, stored in the entity
//
angles[ROLL] = currententity->angles[ROLL];
angles[PITCH] = currententity->angles[PITCH];
angles[YAW] = currententity->angles[YAW];
AngleVectors(angles, s_alias_forward, s_alias_right, s_alias_up);
// TODO: can do this with simple matrix rearrangement
memset(aliasworldtransform, 0, sizeof(aliasworldtransform));
memset(aliasoldworldtransform, 0, sizeof(aliasworldtransform));
for (i = 0; i < 3; i++)
{
aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i];
aliasoldworldtransform[i][0] = aliasworldtransform[i][1] = -s_alias_right[i];
aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i];
}
aliasworldtransform[0][3] = currententity->origin[0] - r_origin[0];
aliasworldtransform[1][3] = currententity->origin[1] - r_origin[1];
aliasworldtransform[2][3] = currententity->origin[2] - r_origin[2];
aliasoldworldtransform[0][3] = currententity->oldorigin[0] - r_origin[0];
aliasoldworldtransform[1][3] = currententity->oldorigin[1] - r_origin[1];
aliasoldworldtransform[2][3] = currententity->oldorigin[2] - r_origin[2];
// FIXME: can do more efficiently than full concatenation
// memcpy( rotationmatrix, t2matrix, sizeof( rotationmatrix ) );
// R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix);
// TODO: should be global, set when vright, etc., set
VectorCopy(vright, viewmatrix[0]);
VectorCopy(vup, viewmatrix[1]);
VectorInverse(viewmatrix[1]);
VectorCopy(vpn, viewmatrix[2]);
viewmatrix[0][3] = 0;
viewmatrix[1][3] = 0;
viewmatrix[2][3] = 0;
// memcpy( aliasworldtransform, rotationmatrix, sizeof( aliastransform ) );
R_ConcatTransforms(viewmatrix, aliasworldtransform, aliastransform);
aliasworldtransform[0][3] = currententity->origin[0];
aliasworldtransform[1][3] = currententity->origin[1];
aliasworldtransform[2][3] = currententity->origin[2];
aliasoldworldtransform[0][3] = currententity->oldorigin[0];
aliasoldworldtransform[1][3] = currententity->oldorigin[1];
aliasoldworldtransform[2][3] = currententity->oldorigin[2];
}
/*
================
R_AliasTransformFinalVerts
================
*/
#if id386 && !defined __linux__ && !defined __FreeBSD__
void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv )
{
float lightcos;
float lerped_vert[3];
int byte_to_dword_ptr_var;
int tmpint;
float one = 1.0F;
float zi;
static float FALIAS_Z_CLIP_PLANE = ALIAS_Z_CLIP_PLANE;
static float PS_SCALE = POWERSUIT_SCALE;
__asm mov ecx, numpoints
/*
lerped_vert[0] = r_lerp_move[0] + oldv->v[0]*r_lerp_backv[0] + newv->v[0]*r_lerp_frontv[0];
lerped_vert[1] = r_lerp_move[1] + oldv->v[1]*r_lerp_backv[1] + newv->v[1]*r_lerp_frontv[1];
lerped_vert[2] = r_lerp_move[2] + oldv->v[2]*r_lerp_backv[2] + newv->v[2]*r_lerp_frontv[2];
*/
top_of_loop:
__asm mov esi, oldv
__asm mov edi, newv
__asm xor ebx, ebx
__asm mov bl, byte ptr [esi+DTRIVERTX_V0]
__asm mov byte_to_dword_ptr_var, ebx
__asm fild dword ptr byte_to_dword_ptr_var
__asm fmul dword ptr [r_lerp_backv+0] ; oldv[0]*rlb[0]
__asm mov bl, byte ptr [esi+DTRIVERTX_V1]
__asm mov byte_to_dword_ptr_var, ebx
__asm fild dword ptr byte_to_dword_ptr_var
__asm fmul dword ptr [r_lerp_backv+4] ; oldv[1]*rlb[1] | oldv[0]*rlb[0]
__asm mov bl, byte ptr [esi+DTRIVERTX_V2]
__asm mov byte_to_dword_ptr_var, ebx
__asm fild dword ptr byte_to_dword_ptr_var
__asm fmul dword ptr [r_lerp_backv+8] ; oldv[2]*rlb[2] | oldv[1]*rlb[1] | oldv[0]*rlb[0]
__asm mov bl, byte ptr [edi+DTRIVERTX_V0]
__asm mov byte_to_dword_ptr_var, ebx
__asm fild dword ptr byte_to_dword_ptr_var
__asm fmul dword ptr [r_lerp_frontv+0] ; newv[0]*rlf[0] | oldv[2]*rlb[2] | oldv[1]*rlb[1] | oldv[0]*rlb[0]
__asm mov bl, byte ptr [edi+DTRIVERTX_V1]
__asm mov byte_to_dword_ptr_var, ebx
__asm fild dword ptr byte_to_dword_ptr_var
__asm fmul dword ptr [r_lerp_frontv+4] ; newv[1]*rlf[1] | newv[0]*rlf[0] | oldv[2]*rlb[2] | oldv[1]*rlb[1] | oldv[0]*rlb[0]
__asm mov bl, byte ptr [edi+DTRIVERTX_V2]
__asm mov byte_to_dword_ptr_var, ebx
__asm fild dword ptr byte_to_dword_ptr_var
__asm fmul dword ptr [r_lerp_frontv+8] ; newv[2]*rlf[2] | newv[1]*rlf[1] | newv[0]*rlf[0] | oldv[2]*rlb[2] | oldv[1]*rlb[1] | oldv[0]*rlb[0]
__asm fxch st(5) ; oldv[0]*rlb[0] | newv[1]*rlf[1] | newv[0]*rlf[0] | oldv[2]*rlb[2] | oldv[1]*rlb[1] | newv[2]*rlf[2]
__asm faddp st(2), st ; newv[1]*rlf[1] | oldv[0]*rlb[0] + newv[0]*rlf[0] | oldv[2]*rlb[2] | oldv[1]*rlb[1] | newv[2]*rlf[2]
__asm faddp st(3), st ; oldv[0]*rlb[0] + newv[0]*rlf[0] | oldv[2]*rlb[2] | oldv[1]*rlb[1] + newv[1]*rlf[1] | newv[2]*rlf[2]
__asm fxch st(1) ; oldv[2]*rlb[2] | oldv[0]*rlb[0] + newv[0]*rlf[0] | oldv[1]*rlb[1] + newv[1]*rlf[1] | newv[2]*rlf[2]
__asm faddp st(3), st ; oldv[0]*rlb[0] + newv[0]*rlf[0] | oldv[1]*rlb[1] + newv[1]*rlf[1] | oldv[2]*rlb[2] + newv[2]*rlf[2]
__asm fadd dword ptr [r_lerp_move+0] ; lv0 | oldv[1]*rlb[1] + newv[1]*rlf[1] | oldv[2]*rlb[2] + newv[2]*rlf[2]
__asm fxch st(1) ; oldv[1]*rlb[1] + newv[1]*rlf[1] | lv0 | oldv[2]*rlb[2] + newv[2]*rlf[2]
__asm fadd dword ptr [r_lerp_move+4] ; lv1 | lv0 | oldv[2]*rlb[2] + newv[2]*rlf[2]
__asm fxch st(2) ; oldv[2]*rlb[2] + newv[2]*rlf[2] | lv0 | lv1
__asm fadd dword ptr [r_lerp_move+8] ; lv2 | lv0 | lv1
__asm fxch st(1) ; lv0 | lv2 | lv1
__asm fstp dword ptr [lerped_vert+0] ; lv2 | lv1
__asm fstp dword ptr [lerped_vert+8] ; lv2
__asm fstp dword ptr [lerped_vert+4] ; (empty)
__asm mov eax, currententity
__asm mov eax, dword ptr [eax+ENTITY_FLAGS]
__asm mov ebx, RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM
__asm and eax, ebx
__asm jz not_powersuit
/*
** lerped_vert[0] += lightnormal[0] * POWERSUIT_SCALE
** lerped_vert[1] += lightnormal[1] * POWERSUIT_SCALE
** lerped_vert[2] += lightnormal[2] * POWERSUIT_SCALE
*/
__asm xor ebx, ebx
__asm mov bl, byte ptr [edi+DTRIVERTX_LNI]
__asm mov eax, 12
__asm mul ebx
__asm lea eax, [r_avertexnormals+eax]
__asm fld dword ptr [eax+0] ; n[0]
__asm fmul PS_SCALE ; n[0] * PS
__asm fld dword ptr [eax+4] ; n[1] | n[0] * PS
__asm fmul PS_SCALE ; n[1] * PS | n[0] * PS
__asm fld dword ptr [eax+8] ; n[2] | n[1] * PS | n[0] * PS
__asm fmul PS_SCALE ; n[2] * PS | n[1] * PS | n[0] * PS
__asm fld dword ptr [lerped_vert+0] ; lv0 | n[2] * PS | n[1] * PS | n[0] * PS
__asm faddp st(3), st ; n[2] * PS | n[1] * PS | n[0] * PS + lv0
__asm fld dword ptr [lerped_vert+4] ; lv1 | n[2] * PS | n[1] * PS | n[0] * PS + lv0
__asm faddp st(2), st ; n[2] * PS | n[1] * PS + lv1 | n[0] * PS + lv0
__asm fadd dword ptr [lerped_vert+8] ; n[2] * PS + lv2 | n[1] * PS + lv1 | n[0] * PS + lv0
__asm fxch st(2) ; LV0 | LV1 | LV2
__asm fstp dword ptr [lerped_vert+0] ; LV1 | LV2
__asm fstp dword ptr [lerped_vert+4] ; LV2
__asm fstp dword ptr [lerped_vert+8] ; (empty)
not_powersuit:
/*
fv->flags = 0;
fv->xyz[0] = DotProduct(lerped_vert, aliastransform[0]) + aliastransform[0][3];
fv->xyz[1] = DotProduct(lerped_vert, aliastransform[1]) + aliastransform[1][3];
fv->xyz[2] = DotProduct(lerped_vert, aliastransform[2]) + aliastransform[2][3];
*/
__asm mov eax, fv
__asm mov dword ptr [eax+FINALVERT_FLAGS], 0
__asm fld dword ptr [lerped_vert+0] ; lv0
__asm fmul dword ptr [aliastransform+0] ; lv0*at[0][0]
__asm fld dword ptr [lerped_vert+4] ; lv1 | lv0*at[0][0]
__asm fmul dword ptr [aliastransform+4] ; lv1*at[0][1] | lv0*at[0][0]
__asm fld dword ptr [lerped_vert+8] ; lv2 | lv1*at[0][1] | lv0*at[0][0]
__asm fmul dword ptr [aliastransform+8] ; lv2*at[0][2] | lv1*at[0][1] | lv0*at[0][0]
__asm fxch st(2) ; lv0*at[0][0] | lv1*at[0][1] | lv2*at[0][2]
__asm faddp st(1), st ; lv0*at[0][0] + lv1*at[0][1] | lv2*at[0][2]
__asm faddp st(1), st ; lv0*at[0][0] + lv1*at[0][1] + lv2*at[0][2]
__asm fadd dword ptr [aliastransform+12] ; FV.X
__asm fld dword ptr [lerped_vert+0] ; lv0
__asm fmul dword ptr [aliastransform+16] ; lv0*at[1][0]
__asm fld dword ptr [lerped_vert+4] ; lv1 | lv0*at[1][0]
__asm fmul dword ptr [aliastransform+20] ; lv1*at[1][1] | lv0*at[1][0]
__asm fld dword ptr [lerped_vert+8] ; lv2 | lv1*at[1][1] | lv0*at[1][0]
__asm fmul dword ptr [aliastransform+24] ; lv2*at[1][2] | lv1*at[1][1] | lv0*at[1][0]
__asm fxch st(2) ; lv0*at[1][0] | lv1*at[1][1] | lv2*at[1][2]
__asm faddp st(1), st ; lv0*at[1][0] + lv1*at[1][1] | lv2*at[1][2]
__asm faddp st(1), st ; lv0*at[1][0] + lv1*at[1][1] + lv2*at[1][2]
__asm fadd dword ptr [aliastransform+28] ; FV.Y | FV.X
__asm fxch st(1) ; FV.X | FV.Y
__asm fstp dword ptr [eax+FINALVERT_X] ; FV.Y
__asm fld dword ptr [lerped_vert+0] ; lv0
__asm fmul dword ptr [aliastransform+32] ; lv0*at[2][0]
__asm fld dword ptr [lerped_vert+4] ; lv1 | lv0*at[2][0]
__asm fmul dword ptr [aliastransform+36] ; lv1*at[2][1] | lv0*at[2][0]
__asm fld dword ptr [lerped_vert+8] ; lv2 | lv1*at[2][1] | lv0*at[2][0]
__asm fmul dword ptr [aliastransform+40] ; lv2*at[2][2] | lv1*at[2][1] | lv0*at[2][0]
__asm fxch st(2) ; lv0*at[2][0] | lv1*at[2][1] | lv2*at[2][2]
__asm faddp st(1), st ; lv0*at[2][0] + lv1*at[2][1] | lv2*at[2][2]
__asm faddp st(1), st ; lv0*at[2][0] + lv1*at[2][1] + lv2*at[2][2]
__asm fadd dword ptr [aliastransform+44] ; FV.Z | FV.Y
__asm fxch st(1) ; FV.Y | FV.Z
__asm fstp dword ptr [eax+FINALVERT_Y] ; FV.Z
__asm fstp dword ptr [eax+FINALVERT_Z] ; (empty)
/*
** lighting
**
** plightnormal = r_avertexnormals[newv->lightnormalindex];
** lightcos = DotProduct (plightnormal, r_plightvec);
** temp = r_ambientlight;
*/
__asm xor ebx, ebx
__asm mov bl, byte ptr [edi+DTRIVERTX_LNI]
__asm mov eax, 12
__asm mul ebx
__asm lea eax, [r_avertexnormals+eax]
__asm lea ebx, r_plightvec
__asm fld dword ptr [eax+0]
__asm fmul dword ptr [ebx+0]
__asm fld dword ptr [eax+4]
__asm fmul dword ptr [ebx+4]
__asm fld dword ptr [eax+8]
__asm fmul dword ptr [ebx+8]
__asm fxch st(2)
__asm faddp st(1), st
__asm faddp st(1), st
__asm fstp dword ptr lightcos
__asm mov eax, lightcos
__asm mov ebx, r_ambientlight
/*
if (lightcos < 0)
{
temp += (int)(r_shadelight * lightcos);
// clamp; because we limited the minimum ambient and shading light, we
// don't have to clamp low light, just bright
if (temp < 0)
temp = 0;
}
fv->v[4] = temp;
*/
__asm or eax, eax
__asm jns store_fv4
__asm fld dword ptr r_shadelight
__asm fmul dword ptr lightcos
__asm fistp dword ptr tmpint
__asm add ebx, tmpint
__asm or ebx, ebx
__asm jns store_fv4
__asm mov ebx, 0
store_fv4:
__asm mov edi, fv
__asm mov dword ptr [edi+FINALVERT_V4], ebx
__asm mov edx, dword ptr [edi+FINALVERT_FLAGS]
/*
** do clip testing and projection here
*/
/*
if ( dest_vert->xyz[2] < ALIAS_Z_CLIP_PLANE )
{
dest_vert->flags |= ALIAS_Z_CLIP;
}
else
{
R_AliasProjectAndClipTestFinalVert( dest_vert );
}
*/
__asm mov eax, dword ptr [edi+FINALVERT_Z]
__asm and eax, eax
__asm js alias_z_clip
__asm cmp eax, FALIAS_Z_CLIP_PLANE
__asm jl alias_z_clip
/*
This is the code to R_AliasProjectAndClipTestFinalVert
float zi;
float x, y, z;
x = fv->xyz[0];
y = fv->xyz[1];
z = fv->xyz[2];
zi = 1.0 / z;
fv->v[5] = zi * s_ziscale;
fv->v[0] = (x * aliasxscale * zi) + aliasxcenter;
fv->v[1] = (y * aliasyscale * zi) + aliasycenter;
*/
__asm fld one ; 1
__asm fdiv dword ptr [edi+FINALVERT_Z] ; zi
__asm mov eax, dword ptr [edi+32]
__asm mov eax, dword ptr [edi+64]
__asm fst zi ; zi
__asm fmul s_ziscale ; fv5
__asm fld dword ptr [edi+FINALVERT_X] ; x | fv5
__asm fmul aliasxscale ; x * aliasxscale | fv5
__asm fld dword ptr [edi+FINALVERT_Y] ; y | x * aliasxscale | fv5
__asm fmul aliasyscale ; y * aliasyscale | x * aliasxscale | fv5
__asm fxch st(1) ; x * aliasxscale | y * aliasyscale | fv5
__asm fmul zi ; x * asx * zi | y * asy | fv5
__asm fadd aliasxcenter ; fv0 | y * asy | fv5
__asm fxch st(1) ; y * asy | fv0 | fv5
__asm fmul zi ; y * asy * zi | fv0 | fv5
__asm fadd aliasycenter ; fv1 | fv0 | fv5
__asm fxch st(2) ; fv5 | fv0 | fv1
__asm fistp dword ptr [edi+FINALVERT_V5] ; fv0 | fv1
__asm fistp dword ptr [edi+FINALVERT_V0] ; fv1
__asm fistp dword ptr [edi+FINALVERT_V1] ; (empty)
/*
if (fv->v[0] < r_refdef.aliasvrect.x)
fv->flags |= ALIAS_LEFT_CLIP;
if (fv->v[1] < r_refdef.aliasvrect.y)
fv->flags |= ALIAS_TOP_CLIP;
if (fv->v[0] > r_refdef.aliasvrectright)
fv->flags |= ALIAS_RIGHT_CLIP;
if (fv->v[1] > r_refdef.aliasvrectbottom)
fv->flags |= ALIAS_BOTTOM_CLIP;
*/
__asm mov eax, dword ptr [edi+FINALVERT_V0]
__asm mov ebx, dword ptr [edi+FINALVERT_V1]
__asm cmp eax, r_refdef.aliasvrect.x
__asm jge ct_alias_top
__asm or edx, ALIAS_LEFT_CLIP
ct_alias_top:
__asm cmp ebx, r_refdef.aliasvrect.y
__asm jge ct_alias_right
__asm or edx, ALIAS_TOP_CLIP
ct_alias_right:
__asm cmp eax, r_refdef.aliasvrectright
__asm jle ct_alias_bottom
__asm or edx, ALIAS_RIGHT_CLIP
ct_alias_bottom:
__asm cmp ebx, r_refdef.aliasvrectbottom
__asm jle end_of_loop
__asm or edx, ALIAS_BOTTOM_CLIP
__asm jmp end_of_loop
alias_z_clip:
__asm or edx, ALIAS_Z_CLIP
end_of_loop:
__asm mov dword ptr [edi+FINALVERT_FLAGS], edx
__asm add oldv, DTRIVERTX_SIZE
__asm add newv, DTRIVERTX_SIZE
__asm add fv, FINALVERT_SIZE
__asm dec ecx
__asm jnz top_of_loop
}
#else
void R_AliasTransformFinalVerts(int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv)
{
int i;
for (i = 0; i < numpoints; i++, fv++, oldv++, newv++)
{
int temp;
float lightcos, *plightnormal;
vec3_t lerped_vert;
lerped_vert[0] = r_lerp_move[0] + oldv->v[0] * r_lerp_backv[0] + newv->v[0] * r_lerp_frontv[0];
lerped_vert[1] = r_lerp_move[1] + oldv->v[1] * r_lerp_backv[1] + newv->v[1] * r_lerp_frontv[1];
lerped_vert[2] = r_lerp_move[2] + oldv->v[2] * r_lerp_backv[2] + newv->v[2] * r_lerp_frontv[2];
plightnormal = r_avertexnormals[newv->lightnormalindex];
// PMM - added double damage shell
if (currententity->flags & (RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM))
{
lerped_vert[0] += plightnormal[0] * POWERSUIT_SCALE;
lerped_vert[1] += plightnormal[1] * POWERSUIT_SCALE;
lerped_vert[2] += plightnormal[2] * POWERSUIT_SCALE;
}
fv->xyz[0] = DotProduct(lerped_vert, aliastransform[0]) + aliastransform[0][3];
fv->xyz[1] = DotProduct(lerped_vert, aliastransform[1]) + aliastransform[1][3];
fv->xyz[2] = DotProduct(lerped_vert, aliastransform[2]) + aliastransform[2][3];
fv->flags = 0;
// lighting
lightcos = DotProduct(plightnormal, r_plightvec);
temp = r_ambientlight;
if (lightcos < 0)
{
temp += (int)(r_shadelight * lightcos);
// clamp; because we limited the minimum ambient and shading light, we
// don't have to clamp low light, just bright
if (temp < 0)
temp = 0;
}
fv->l = temp;
if (fv->xyz[2] < ALIAS_Z_CLIP_PLANE)
{
fv->flags |= ALIAS_Z_CLIP;
}
else
{
R_AliasProjectAndClipTestFinalVert(fv);
}
}
}
#endif
/*
================
R_AliasProjectAndClipTestFinalVert
================
*/
void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv)
{
float zi;
float x, y, z;
// project points
x = fv->xyz[0];
y = fv->xyz[1];
z = fv->xyz[2];
zi = 1.0 / z;
fv->zi = zi * s_ziscale;
fv->u = (x * aliasxscale * zi) + aliasxcenter;
fv->v = (y * aliasyscale * zi) + aliasycenter;
if (fv->u < r_refdef.aliasvrect.x)
fv->flags |= ALIAS_LEFT_CLIP;
if (fv->v < r_refdef.aliasvrect.y)
fv->flags |= ALIAS_TOP_CLIP;
if (fv->u > r_refdef.aliasvrectright)
fv->flags |= ALIAS_RIGHT_CLIP;
if (fv->v > r_refdef.aliasvrectbottom)
fv->flags |= ALIAS_BOTTOM_CLIP;
}
/*
===============
R_AliasSetupSkin
===============
*/
static qboolean R_AliasSetupSkin(void)
{
int skinnum;
image_t *pskindesc;
if (currententity->skin)
pskindesc = currententity->skin;
else
{
skinnum = currententity->skinnum;
if ((skinnum >= s_pmdl->num_skins) || (skinnum < 0))
{
ri.Con_Printf(PRINT_ALL, "R_AliasSetupSkin %s: no such skin # %d\n",
currentmodel->name, skinnum);
skinnum = 0;
}
pskindesc = currentmodel->skins[skinnum];
}
if (!pskindesc)
return false;
r_affinetridesc.pskin = pskindesc->pixels[0];
r_affinetridesc.skinwidth = pskindesc->width;
r_affinetridesc.skinheight = pskindesc->height;
R_PolysetUpdateTables(); // FIXME: precalc edge lookups
return true;
}
/*
================
R_AliasSetupLighting
FIXME: put lighting into tables
================
*/
void R_AliasSetupLighting(void)
{
alight_t lighting;
/*
float lightvec[3] = {-1, 0, 0};
float rlightvec[3] = {-1, 0, 0};
float glightvec[3] = {-1, 0, 0};
float blightvec[3] = {-1, 0, 0};
*/
float lightvec[3] = { 0.2, -0.8, 0.6 };
float rlightvec[3] = { -1, 0, 0 };
float glightvec[3] = { 0, -1, 0 };
float blightvec[3] = { 0, 0, -1 };
//qb: use shadelight. vec3_t light;
int i, j;
// all components of light should be identical in software
if (currententity->flags & RF_FULLBRIGHT)
{
for (i = 0; i < 3; i++)
shadelight[i] = 1.0;
}
else
{
R_LightPointColor(currententity->origin, shadelight);
}
// save off light value for server to look at (BIG HACK!)
if (currententity->flags & RF_WEAPONMODEL)
r_lightlevel->value = 150.0 * shadelight[0];
if (currententity->flags & RF_MINLIGHT)
{
for (i = 0; i < 3; i++)
if (shadelight[i] < 0.1)
shadelight[i] = 0.1;
}
if (currententity->flags & RF_GLOW)
{ // bonus items will pulse with time
float scale;
float min;
scale = 0.1 * sin(r_newrefdef.time * 7);
for (i = 0; i < 3; i++)
{
min = shadelight[i] * 0.8;
shadelight[i] += scale;
if (shadelight[i] < min)
shadelight[i] = min;
}
}
j = (shadelight[0] + shadelight[1] + shadelight[2])*0.3333 * 255;
lighting.ambientlight = j;
lighting.shadelight = j;
lighting.plightvec = lightvec;
lighting.prlightvec = rlightvec;
lighting.pglightvec = glightvec;
lighting.pblightvec = blightvec;
// clamp lighting so it doesn't overbright as much
if (lighting.ambientlight > 128)
lighting.ambientlight = 128;
if (lighting.ambientlight + lighting.shadelight > 192)
lighting.shadelight = 192 - lighting.ambientlight;
// guarantee that no vertex will ever be lit below LIGHT_MIN, so we don't have
// to clamp off the bottom
r_ambientlight = lighting.ambientlight;
if (r_ambientlight < LIGHT_MIN)
r_ambientlight = LIGHT_MIN;
r_ambientlight = (255 - r_ambientlight) << VID_CBITS;
if (r_ambientlight < LIGHT_MIN)
r_ambientlight = LIGHT_MIN;
r_shadelight = lighting.shadelight;
if (r_shadelight < 0)
r_shadelight = 0;
r_shadelight *= VID_GRADES;
// rotate the lighting vector into the model's frame of reference
r_plightvec[0] = DotProduct(lighting.plightvec, s_alias_forward);
r_plightvec[1] = -DotProduct(lighting.plightvec, s_alias_right);
r_plightvec[2] = DotProduct(lighting.plightvec, s_alias_up);
r_prlightvec[0] = DotProduct(lighting.prlightvec, s_alias_forward);
r_pglightvec[1] = -DotProduct(lighting.pglightvec, s_alias_right);
r_pblightvec[2] = DotProduct(lighting.pblightvec, s_alias_up);
}
/*
=================
R_AliasSetupFrames
=================
*/
void R_AliasSetupFrames(dmdl_t *pmdl)
{
int thisframe = currententity->frame;
int lastframe = currententity->oldframe;
if ((thisframe >= pmdl->num_frames) || (thisframe < 0))
{