Debian Codegraph @

code/renderergl2/tr_shade_calc.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // tr_shade_calc.c
23
24 #include "tr_local.h"
25
26
27 #define WAVEVALUE( table, base, amplitude, phase, freq ) ((base) + table[ ( (int64_t) ( ( (phase) + tess.shaderTime * (freq) ) * FUNCTABLE_SIZE ) ) & FUNCTABLE_MASK ] * (amplitude))
28
29 static float *TableForFunc( genFunc_t func )
30 {
31 switch ( func )
32 {
33 case GF_SIN:
34 return tr.sinTable;
35 case GF_TRIANGLE:
36 return tr.triangleTable;
37 case GF_SQUARE:
38 return tr.squareTable;
39 case GF_SAWTOOTH:
40 return tr.sawToothTable;
41 case GF_INVERSE_SAWTOOTH:
42 return tr.inverseSawToothTable;
43 case GF_NONE:
44 default:
45 break;
46 }
47
48 ri.Error( ERR_DROP, "TableForFunc called with invalid function '%d' in shader '%s'", func, tess.shader->name );
49 return NULL;
50 }
51
52 /*
53 ** EvalWaveForm
54 **
55 ** Evaluates a given waveForm_t, referencing backEnd.refdef.time directly
56 */
57 static float EvalWaveForm( const waveForm_t *wf )
58 {
59 float *table;
60
61 table = TableForFunc( wf->func );
62
63 return WAVEVALUE( table, wf->base, wf->amplitude, wf->phase, wf->frequency );
64 }
65
66 static float EvalWaveFormClamped( const waveForm_t *wf )
67 {
68 float glow = EvalWaveForm( wf );
69
70 if ( glow < 0 )
71 {
72 return 0;
73 }
74
75 if ( glow > 1 )
76 {
77 return 1;
78 }
79
80 return glow;
81 }
82
83 /*
84 ** RB_CalcStretchTexMatrix
85 */
86 void RB_CalcStretchTexMatrix( const waveForm_t *wf, float *matrix )
87 {
88 float p;
89
90 p = 1.0f / EvalWaveForm( wf );
91
92 matrix[0] = p; matrix[2] = 0; matrix[4] = 0.5f - 0.5f * p;
93 matrix[1] = 0; matrix[3] = p; matrix[5] = 0.5f - 0.5f * p;
94 }
95
96 /*
97 ====================================================================
98
99 DEFORMATIONS
100
101 ====================================================================
102 */
103
104 /*
105 ========================
106 RB_CalcDeformVertexes
107
108 ========================
109 */
110 void RB_CalcDeformVertexes( deformStage_t *ds )
111 {
112 int i;
113 vec3_t offset;
114 float scale;
115 float *xyz = ( float * ) tess.xyz;
116 int16_t *normal = tess.normal[0];
117 float *table;
118
119 if ( ds->deformationWave.frequency == 0 )
120 {
121 scale = EvalWaveForm( &ds->deformationWave );
122
123 for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 )
124 {
125 R_VaoUnpackNormal(offset, normal);
126
127 xyz[0] += offset[0] * scale;
128 xyz[1] += offset[1] * scale;
129 xyz[2] += offset[2] * scale;
130 }
131 }
132 else
133 {
134 table = TableForFunc( ds->deformationWave.func );
135
136 for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 )
137 {
138 float off = ( xyz[0] + xyz[1] + xyz[2] ) * ds->deformationSpread;
139
140 scale = WAVEVALUE( table, ds->deformationWave.base,
141 ds->deformationWave.amplitude,
142 ds->deformationWave.phase + off,
143 ds->deformationWave.frequency );
144
145 R_VaoUnpackNormal(offset, normal);
146
147 xyz[0] += offset[0] * scale;
148 xyz[1] += offset[1] * scale;
149 xyz[2] += offset[2] * scale;
150 }
151 }
152 }
153
154 /*
155 =========================
156 RB_CalcDeformNormals
157
158 Wiggle the normals for wavy environment mapping
159 =========================
160 */
161 void RB_CalcDeformNormals( deformStage_t *ds ) {
162 int i;
163 float scale;
164 float *xyz = ( float * ) tess.xyz;
165 int16_t *normal = tess.normal[0];
166
167 for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) {
168 vec3_t fNormal;
169
170 R_VaoUnpackNormal(fNormal, normal);
171
172 scale = 0.98f;
173 scale = R_NoiseGet4f( xyz[0] * scale, xyz[1] * scale, xyz[2] * scale,
174 tess.shaderTime * ds->deformationWave.frequency );
175 fNormal[ 0 ] += ds->deformationWave.amplitude * scale;
176
177 scale = 0.98f;
178 scale = R_NoiseGet4f( 100 + xyz[0] * scale, xyz[1] * scale, xyz[2] * scale,
179 tess.shaderTime * ds->deformationWave.frequency );
180 fNormal[ 1 ] += ds->deformationWave.amplitude * scale;
181
182 scale = 0.98f;
183 scale = R_NoiseGet4f( 200 + xyz[0] * scale, xyz[1] * scale, xyz[2] * scale,
184 tess.shaderTime * ds->deformationWave.frequency );
185 fNormal[ 2 ] += ds->deformationWave.amplitude * scale;
186
187 VectorNormalizeFast( fNormal );
188
189 R_VaoPackNormal(normal, fNormal);
190 }
191 }
192
193 /*
194 ========================
195 RB_CalcBulgeVertexes
196
197 ========================
198 */
199 void RB_CalcBulgeVertexes( deformStage_t *ds ) {
200 int i;
201 const float *st = ( const float * ) tess.texCoords[0];
202 float *xyz = ( float * ) tess.xyz;
203 int16_t *normal = tess.normal[0];
204 double now;
205
206 now = backEnd.refdef.time * 0.001 * ds->bulgeSpeed;
207
208 for ( i = 0; i < tess.numVertexes; i++, xyz += 4, st += 2, normal += 4 ) {
209 int64_t off;
210 float scale;
211 vec3_t fNormal;
212
213 R_VaoUnpackNormal(fNormal, normal);
214
215 off = (float)( FUNCTABLE_SIZE / (M_PI*2) ) * ( st[0] * ds->bulgeWidth + now );
216
217 scale = tr.sinTable[ off & FUNCTABLE_MASK ] * ds->bulgeHeight;
218
219 xyz[0] += fNormal[0] * scale;
220 xyz[1] += fNormal[1] * scale;
221 xyz[2] += fNormal[2] * scale;
222 }
223 }
224
225
226 /*
227 ======================
228 RB_CalcMoveVertexes
229
230 A deformation that can move an entire surface along a wave path
231 ======================
232 */
233 void RB_CalcMoveVertexes( deformStage_t *ds ) {
234 int i;
235 float *xyz;
236 float *table;
237 float scale;
238 vec3_t offset;
239
240 table = TableForFunc( ds->deformationWave.func );
241
242 scale = WAVEVALUE( table, ds->deformationWave.base,
243 ds->deformationWave.amplitude,
244 ds->deformationWave.phase,
245 ds->deformationWave.frequency );
246
247 VectorScale( ds->moveVector, scale, offset );
248
249 xyz = ( float * ) tess.xyz;
250 for ( i = 0; i < tess.numVertexes; i++, xyz += 4 ) {
251 VectorAdd( xyz, offset, xyz );
252 }
253 }
254
255
256 /*
257 =============
258 DeformText
259
260 Change a polygon into a bunch of text polygons
261 =============
262 */
263 void DeformText( const char *text ) {
264 int i;
265 vec3_t origin, width, height;
266 int len;
267 int ch;
268 float color[4];
269 float bottom, top;
270 vec3_t mid;
271 vec3_t fNormal;
272
273 height[0] = 0;
274 height[1] = 0;
275 height[2] = -1;
276
277 R_VaoUnpackNormal(fNormal, tess.normal[0]);
278 CrossProduct( fNormal, height, width );
279
280 // find the midpoint of the box
281 VectorClear( mid );
282 bottom = 999999;
283 top = -999999;
284 for ( i = 0 ; i < 4 ; i++ ) {
285 VectorAdd( tess.xyz[i], mid, mid );
286 if ( tess.xyz[i][2] < bottom ) {
287 bottom = tess.xyz[i][2];
288 }
289 if ( tess.xyz[i][2] > top ) {
290 top = tess.xyz[i][2];
291 }
292 }
293 VectorScale( mid, 0.25f, origin );
294
295 // determine the individual character size
296 height[0] = 0;
297 height[1] = 0;
298 height[2] = ( top - bottom ) * 0.5f;
299
300 VectorScale( width, height[2] * -0.75f, width );
301
302 // determine the starting position
303 len = strlen( text );
304 VectorMA( origin, (len-1), width, origin );
305
306 // clear the shader indexes
307 tess.numIndexes = 0;
308 tess.numVertexes = 0;
309 tess.firstIndex = 0;
310
311 color[0] = color[1] = color[2] = color[3] = 1.0f;
312
313 // draw each character
314 for ( i = 0 ; i < len ; i++ ) {
315 ch = text[i];
316 ch &= 255;
317
318 if ( ch != ' ' ) {
319 int row, col;
320 float frow, fcol, size;
321
322 row = ch>>4;
323 col = ch&15;
324
325 frow = row*0.0625f;
326 fcol = col*0.0625f;
327 size = 0.0625f;
328
329 RB_AddQuadStampExt( origin, width, height, color, fcol, frow, fcol + size, frow + size );
330 }
331 VectorMA( origin, -2, width, origin );
332 }
333 }
334
335 /*
336 ==================
337 GlobalVectorToLocal
338 ==================
339 */
340 static void GlobalVectorToLocal( const vec3_t in, vec3_t out ) {
341 out[0] = DotProduct( in, backEnd.or.axis[0] );
342 out[1] = DotProduct( in, backEnd.or.axis[1] );
343 out[2] = DotProduct( in, backEnd.or.axis[2] );
344 }
345
346 /*
347 =====================
348 AutospriteDeform
349
350 Assuming all the triangles for this shader are independent
351 quads, rebuild them as forward facing sprites
352 =====================
353 */
354 static void AutospriteDeform( void ) {
355 int i;
356 int oldVerts;
357 float *xyz;
358 vec3_t mid, delta;
359 float radius;
360 vec3_t left, up;
361 vec3_t leftDir, upDir;
362
363 if ( tess.numVertexes & 3 ) {
364 ri.Printf( PRINT_WARNING, "Autosprite shader %s had odd vertex count\n", tess.shader->name );
365 }
366 if ( tess.numIndexes != ( tess.numVertexes >> 2 ) * 6 ) {
367 ri.Printf( PRINT_WARNING, "Autosprite shader %s had odd index count\n", tess.shader->name );
368 }
369
370 oldVerts = tess.numVertexes;
371 tess.numVertexes = 0;
372 tess.numIndexes = 0;
373 tess.firstIndex = 0;
374
375 if ( backEnd.currentEntity != &tr.worldEntity ) {
376 GlobalVectorToLocal( backEnd.viewParms.or.axis[1], leftDir );
377 GlobalVectorToLocal( backEnd.viewParms.or.axis[2], upDir );
378 } else {
379 VectorCopy( backEnd.viewParms.or.axis[1], leftDir );
380 VectorCopy( backEnd.viewParms.or.axis[2], upDir );
381 }
382
383 for ( i = 0 ; i < oldVerts ; i+=4 ) {
384 vec4_t color;
385 // find the midpoint
386 xyz = tess.xyz[i];
387
388 mid[0] = 0.25f * (xyz[0] + xyz[4] + xyz[8] + xyz[12]);
389 mid[1] = 0.25f * (xyz[1] + xyz[5] + xyz[9] + xyz[13]);
390 mid[2] = 0.25f * (xyz[2] + xyz[6] + xyz[10] + xyz[14]);
391
392 VectorSubtract( xyz, mid, delta );
393 radius = VectorLength( delta ) * 0.707f; // / sqrt(2)
394
395 VectorScale( leftDir, radius, left );
396 VectorScale( upDir, radius, up );
397
398 if ( backEnd.viewParms.isMirror ) {
399 VectorSubtract( vec3_origin, left, left );
400 }
401
402 // compensate for scale in the axes if necessary
403 if ( backEnd.currentEntity->e.nonNormalizedAxes ) {
404 float axisLength;
405 axisLength = VectorLength( backEnd.currentEntity->e.axis[0] );
406 if ( !axisLength ) {
407 axisLength = 0;
408 } else {
409 axisLength = 1.0f / axisLength;
410 }
411 VectorScale(left, axisLength, left);
412 VectorScale(up, axisLength, up);
413 }
414
415 VectorScale4(tess.color[i], 1.0f / 65535.0f, color);
416 RB_AddQuadStamp( mid, left, up, color );
417 }
418 }
419
420
421 /*
422 =====================
423 Autosprite2Deform
424
425 Autosprite2 will pivot a rectangular quad along the center of its long axis
426 =====================
427 */
428 int edgeVerts[6][2] = {
429 { 0, 1 },
430 { 0, 2 },
431 { 0, 3 },
432 { 1, 2 },
433 { 1, 3 },
434 { 2, 3 }
435 };
436
437 static void Autosprite2Deform( void ) {
438 int i, j, k;
439 int indexes;
440 float *xyz;
441 vec3_t forward;
442
443 if ( tess.numVertexes & 3 ) {
444 ri.Printf( PRINT_WARNING, "Autosprite2 shader %s had odd vertex count\n", tess.shader->name );
445 }
446 if ( tess.numIndexes != ( tess.numVertexes >> 2 ) * 6 ) {
447 ri.Printf( PRINT_WARNING, "Autosprite2 shader %s had odd index count\n", tess.shader->name );
448 }
449
450 if ( backEnd.currentEntity != &tr.worldEntity ) {
451 GlobalVectorToLocal( backEnd.viewParms.or.axis[0], forward );
452 } else {
453 VectorCopy( backEnd.viewParms.or.axis[0], forward );
454 }
455
456 // this is a lot of work for two triangles...
457 // we could precalculate a lot of it is an issue, but it would mess up
458 // the shader abstraction
459 for ( i = 0, indexes = 0 ; i < tess.numVertexes ; i+=4, indexes+=6 ) {
460 float lengths[2];
461 int nums[2];
462 vec3_t mid[2];
463 vec3_t major, minor;
464 float *v1, *v2;
465
466 // find the midpoint
467 xyz = tess.xyz[i];
468
469 // identify the two shortest edges
470 nums[0] = nums[1] = 0;
471 lengths[0] = lengths[1] = 999999;
472
473 for ( j = 0 ; j < 6 ; j++ ) {
474 float l;
475 vec3_t temp;
476
477 v1 = xyz + 4 * edgeVerts[j][0];
478 v2 = xyz + 4 * edgeVerts[j][1];
479
480 VectorSubtract( v1, v2, temp );
481
482 l = DotProduct( temp, temp );
483 if ( l < lengths[0] ) {
484 nums[1] = nums[0];
485 lengths[1] = lengths[0];
486 nums[0] = j;
487 lengths[0] = l;
488 } else if ( l < lengths[1] ) {
489 nums[1] = j;
490 lengths[1] = l;
491 }
492 }
493
494 for ( j = 0 ; j < 2 ; j++ ) {
495 v1 = xyz + 4 * edgeVerts[nums[j]][0];
496 v2 = xyz + 4 * edgeVerts[nums[j]][1];
497
498 mid[j][0] = 0.5f * (v1[0] + v2[0]);
499 mid[j][1] = 0.5f * (v1[1] + v2[1]);
500 mid[j][2] = 0.5f * (v1[2] + v2[2]);
501 }
502
503 // find the vector of the major axis
504 VectorSubtract( mid[1], mid[0], major );
505
506 // cross this with the view direction to get minor axis
507 CrossProduct( major, forward, minor );
508 VectorNormalize( minor );
509
510 // re-project the points
511 for ( j = 0 ; j < 2 ; j++ ) {
512 float l;
513
514 v1 = xyz + 4 * edgeVerts[nums[j]][0];
515 v2 = xyz + 4 * edgeVerts[nums[j]][1];
516
517 l = 0.5 * sqrt( lengths[j] );
518
519 // we need to see which direction this edge
520 // is used to determine direction of projection
521 for ( k = 0 ; k < 5 ; k++ ) {
522 if ( tess.indexes[ indexes + k ] == i + edgeVerts[nums[j]][0]
523 && tess.indexes[ indexes + k + 1 ] == i + edgeVerts[nums[j]][1] ) {
524 break;
525 }
526 }
527
528 if ( k == 5 ) {
529 VectorMA( mid[j], l, minor, v1 );
530 VectorMA( mid[j], -l, minor, v2 );
531 } else {
532 VectorMA( mid[j], -l, minor, v1 );
533 VectorMA( mid[j], l, minor, v2 );
534 }
535 }
536 }
537 }
538
539
540 /*
541 =====================
542 RB_DeformTessGeometry
543
544 =====================
545 */
546 void RB_DeformTessGeometry( void ) {
547 int i;
548 deformStage_t *ds;
549
550 if(!ShaderRequiresCPUDeforms(tess.shader))
551 {
552 // we don't need the following CPU deforms
553 return;
554 }
555
556 for ( i = 0 ; i < tess.shader->numDeforms ; i++ ) {
557 ds = &tess.shader->deforms[ i ];
558
559 switch ( ds->deformation ) {
560 case DEFORM_NONE:
561 break;
562 case DEFORM_NORMALS:
563 RB_CalcDeformNormals( ds );
564 break;
565 case DEFORM_WAVE:
566 RB_CalcDeformVertexes( ds );
567 break;
568 case DEFORM_BULGE:
569 RB_CalcBulgeVertexes( ds );
570 break;
571 case DEFORM_MOVE:
572 RB_CalcMoveVertexes( ds );
573 break;
574 case DEFORM_PROJECTION_SHADOW:
575 RB_ProjectionShadowDeform();
576 break;
577 case DEFORM_AUTOSPRITE:
578 AutospriteDeform();
579 break;
580 case DEFORM_AUTOSPRITE2:
581 Autosprite2Deform();
582 break;
583 case DEFORM_TEXT0:
584 case DEFORM_TEXT1:
585 case DEFORM_TEXT2:
586 case DEFORM_TEXT3:
587 case DEFORM_TEXT4:
588 case DEFORM_TEXT5:
589 case DEFORM_TEXT6:
590 case DEFORM_TEXT7:
591 DeformText( backEnd.refdef.text[ds->deformation - DEFORM_TEXT0] );
592 break;
593 }
594 }
595 }
596
597 /*
598 ====================================================================
599
600 COLORS
601
602 ====================================================================
603 */
604
605
606 /*
607 ** RB_CalcWaveColorSingle
608 */
609 float RB_CalcWaveColorSingle( const waveForm_t *wf )
610 {
611 float glow;
612
613 if ( wf->func == GF_NOISE ) {
614 glow = wf->base + R_NoiseGet4f( 0, 0, 0, ( tess.shaderTime + wf->phase ) * wf->frequency ) * wf->amplitude;
615 } else {
616 glow = EvalWaveForm( wf ) * tr.identityLight;
617 }
618
619 if ( glow < 0 ) {
620 glow = 0;
621 }
622 else if ( glow > 1 ) {
623 glow = 1;
624 }
625
626 return glow;
627 }
628
629 /*
630 ** RB_CalcWaveAlphaSingle
631 */
632 float RB_CalcWaveAlphaSingle( const waveForm_t *wf )
633 {
634 return EvalWaveFormClamped( wf );
635 }
636
637 /*
638 ** RB_CalcModulateColorsByFog
639 */
640 void RB_CalcModulateColorsByFog( unsigned char *colors ) {
641 int i;
642 float texCoords[SHADER_MAX_VERTEXES][2] = {{0.0f}};
643
644 // calculate texcoords so we can derive density
645 // this is not wasted, because it would only have
646 // been previously called if the surface was opaque
647 RB_CalcFogTexCoords( texCoords[0] );
648
649 for ( i = 0; i < tess.numVertexes; i++, colors += 4 ) {
650 float f = 1.0 - R_FogFactor( texCoords[i][0], texCoords[i][1] );
651 colors[0] *= f;
652 colors[1] *= f;
653 colors[2] *= f;
654 }
655 }
656
657
658 /*
659 ====================================================================
660
661 TEX COORDS
662
663 ====================================================================
664 */
665
666 /*
667 ========================
668 RB_CalcFogTexCoords
669
670 To do the clipped fog plane really correctly, we should use
671 projected textures, but I don't trust the drivers and it
672 doesn't fit our shader data.
673 ========================
674 */
675 void RB_CalcFogTexCoords( float *st ) {
676 int i;
677 float *v;
678 float s, t;
679 float eyeT;
680 qboolean eyeOutside;
681 fog_t *fog;
682 vec3_t local;
683 vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0};
684
685 fog = tr.world->fogs + tess.fogNum;
686
687 // all fogging distance is based on world Z units
688 VectorSubtract( backEnd.or.origin, backEnd.viewParms.or.origin, local );
689 fogDistanceVector[0] = -backEnd.or.modelMatrix[2];
690 fogDistanceVector[1] = -backEnd.or.modelMatrix[6];
691 fogDistanceVector[2] = -backEnd.or.modelMatrix[10];
692 fogDistanceVector[3] = DotProduct( local, backEnd.viewParms.or.axis[0] );
693
694 // scale the fog vectors based on the fog's thickness
695 fogDistanceVector[0] *= fog->tcScale;
696 fogDistanceVector[1] *= fog->tcScale;
697 fogDistanceVector[2] *= fog->tcScale;
698 fogDistanceVector[3] *= fog->tcScale;
699
700 // rotate the gradient vector for this orientation
701 if ( fog->hasSurface ) {
702 fogDepthVector[0] = fog->surface[0] * backEnd.or.axis[0][0] +
703 fog->surface[1] * backEnd.or.axis[0][1] + fog->surface[2] * backEnd.or.axis[0][2];
704 fogDepthVector[1] = fog->surface[0] * backEnd.or.axis[1][0] +
705 fog->surface[1] * backEnd.or.axis[1][1] + fog->surface[2] * backEnd.or.axis[1][2];
706 fogDepthVector[2] = fog->surface[0] * backEnd.or.axis[2][0] +
707 fog->surface[1] * backEnd.or.axis[2][1] + fog->surface[2] * backEnd.or.axis[2][2];
708 fogDepthVector[3] = -fog->surface[3] + DotProduct( backEnd.or.origin, fog->surface );
709
710 eyeT = DotProduct( backEnd.or.viewOrigin, fogDepthVector ) + fogDepthVector[3];
711 } else {
712 eyeT = 1; // non-surface fog always has eye inside
713 }
714
715 // see if the viewpoint is outside
716 // this is needed for clipping distance even for constant fog
717
718 if ( eyeT < 0 ) {
719 eyeOutside = qtrue;
720 } else {
721 eyeOutside = qfalse;
722 }
723
724 fogDistanceVector[3] += 1.0/512;
725
726 // calculate density for each point
727 for (i = 0, v = tess.xyz[0] ; i < tess.numVertexes ; i++, v += 4) {
728 // calculate the length in fog
729 s = DotProduct( v, fogDistanceVector ) + fogDistanceVector[3];
730 t = DotProduct( v, fogDepthVector ) + fogDepthVector[3];
731
732 // partially clipped fogs use the T axis
733 if ( eyeOutside ) {
734 if ( t < 1.0 ) {
735 t = 1.0/32; // point is outside, so no fogging
736 } else {
737 t = 1.0/32 + 30.0/32 * t / ( t - eyeT ); // cut the distance at the fog plane
738 }
739 } else {
740 if ( t < 0 ) {
741 t = 1.0/32; // point is outside, so no fogging
742 } else {
743 t = 31.0/32;
744 }
745 }
746
747 st[0] = s;
748 st[1] = t;
749 st += 2;
750 }
751 }
752
753 /*
754 ** RB_CalcTurbulentFactors
755 */
756 void RB_CalcTurbulentFactors( const waveForm_t *wf, float *amplitude, float *now )
757 {
758 *now = wf->phase + tess.shaderTime * wf->frequency;
759 *amplitude = wf->amplitude;
760 }
761
762 /*
763 ** RB_CalcScaleTexMatrix
764 */
765 void RB_CalcScaleTexMatrix( const float scale[2], float *matrix )
766 {
767 matrix[0] = scale[0]; matrix[2] = 0.0f; matrix[4] = 0.0f;
768 matrix[1] = 0.0f; matrix[3] = scale[1]; matrix[5] = 0.0f;
769 }
770
771 /*
772 ** RB_CalcScrollTexMatrix
773 */
774 void RB_CalcScrollTexMatrix( const float scrollSpeed[2], float *matrix )
775 {
776 double timeScale = tess.shaderTime;
777 double adjustedScrollS, adjustedScrollT;
778
779 adjustedScrollS = scrollSpeed[0] * timeScale;
780 adjustedScrollT = scrollSpeed[1] * timeScale;
781
782 // clamp so coordinates don't continuously get larger, causing problems
783 // with hardware limits
784 adjustedScrollS = adjustedScrollS - floor( adjustedScrollS );
785 adjustedScrollT = adjustedScrollT - floor( adjustedScrollT );
786
787 matrix[0] = 1.0f; matrix[2] = 0.0f; matrix[4] = adjustedScrollS;
788 matrix[1] = 0.0f; matrix[3] = 1.0f; matrix[5] = adjustedScrollT;
789 }
790
791 /*
792 ** RB_CalcTransformTexMatrix
793 */
794 void RB_CalcTransformTexMatrix( const texModInfo_t *tmi, float *matrix )
795 {
796 matrix[0] = tmi->matrix[0][0]; matrix[2] = tmi->matrix[1][0]; matrix[4] = tmi->translate[0];
797 matrix[1] = tmi->matrix[0][1]; matrix[3] = tmi->matrix[1][1]; matrix[5] = tmi->translate[1];
798 }
799
800 /*
801 ** RB_CalcRotateTexMatrix
802 */
803 void RB_CalcRotateTexMatrix( float degsPerSecond, float *matrix )
804 {
805 double timeScale = tess.shaderTime;
806 double degs;
807 int64_t index;
808 float sinValue, cosValue;
809
810 degs = -degsPerSecond * timeScale;
811 index = degs * ( FUNCTABLE_SIZE / 360.0f );
812
813 sinValue = tr.sinTable[ index & FUNCTABLE_MASK ];
814 cosValue = tr.sinTable[ ( index + FUNCTABLE_SIZE / 4 ) & FUNCTABLE_MASK ];
815
816 matrix[0] = cosValue; matrix[2] = -sinValue; matrix[4] = 0.5 - 0.5 * cosValue + 0.5 * sinValue;
817 matrix[1] = sinValue; matrix[3] = cosValue; matrix[5] = 0.5 - 0.5 * sinValue - 0.5 * cosValue;
818 }