Debian Codegraph @

tools/quake3/q3map2/surface_fur.c

raw symbols SCIP
1 /* -------------------------------------------------------------------------------
2
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6 This file is part of GtkRadiant.
7
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22 ----------------------------------------------------------------------------------
23
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27 ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define SURFACE_FUR_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39
40
41
42 /* -------------------------------------------------------------------------------
43
44 ydnar: fur module
45
46 ------------------------------------------------------------------------------- */
47
48 /*
49 Fur()
50 runs the fur processing algorithm on a map drawsurface
51 */
52
53 void Fur( mapDrawSurface_t *ds ){
54 int i, j, k, numLayers;
55 float offset, fade, a;
56 mapDrawSurface_t *fur;
57 bspDrawVert_t *dv;
58
59
60 /* dummy check */
61 if ( ds == NULL || ds->fur || ds->shaderInfo->furNumLayers < 1 ) {
62 return;
63 }
64
65 /* get basic info */
66 numLayers = ds->shaderInfo->furNumLayers;
67 offset = ds->shaderInfo->furOffset;
68 fade = ds->shaderInfo->furFade * 255.0f;
69
70 /* debug code */
71 //% Sys_FPrintf( SYS_VRB, "Fur(): layers: %d offset: %f fade: %f %s\n",
72 //% numLayers, offset, fade, ds->shaderInfo->shader );
73
74 /* initial offset */
75 for ( j = 0; j < ds->numVerts; j++ )
76 {
77 /* get surface vert */
78 dv = &ds->verts[ j ];
79
80 /* offset is scaled by original vertex alpha */
81 a = (float) dv->color[ 0 ][ 3 ] / 255.0;
82
83 /* offset it */
84 VectorMA( dv->xyz, ( offset * a ), dv->normal, dv->xyz );
85 }
86
87 /* wash, rinse, repeat */
88 for ( i = 1; i < numLayers; i++ )
89 {
90 /* clone the surface */
91 fur = CloneSurface( ds, ds->shaderInfo );
92 if ( fur == NULL ) {
93 return;
94 }
95
96 /* set it to fur */
97 fur->fur = qtrue;
98
99 /* walk the verts */
100 for ( j = 0; j < fur->numVerts; j++ )
101 {
102 /* get surface vert */
103 dv = &ds->verts[ j ];
104
105 /* offset is scaled by original vertex alpha */
106 a = (float) dv->color[ 0 ][ 3 ] / 255.0;
107
108 /* get fur vert */
109 dv = &fur->verts[ j ];
110
111 /* offset it */
112 VectorMA( dv->xyz, ( offset * a * i ), dv->normal, dv->xyz );
113
114 /* fade alpha */
115 for ( k = 0; k < MAX_LIGHTMAPS; k++ )
116 {
117 a = (float) dv->color[ k ][ 3 ] - fade;
118 if ( a > 255.0f ) {
119 dv->color[ k ][ 3 ] = 255;
120 }
121 else if ( a < 0 ) {
122 dv->color[ k ][ 3 ] = 0;
123 }
124 else{
125 dv->color[ k ][ 3 ] = a;
126 }
127 }
128 }
129 }
130 }