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