]> icculus.org git repositories - divverent/netradiant.git/blob - tools/quake3/q3map2/surface_fur.c
unfinished -minimap support in bsp.c, do not use yet, format is not correct yet
[divverent/netradiant.git] / tools / quake3 / q3map2 / surface_fur.c
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 {
55         int                                     i, j, k, numLayers;
56         float                           offset, fade, a;
57         mapDrawSurface_t        *fur;
58         bspDrawVert_t           *dv;
59         
60         
61         /* dummy check */
62         if( ds == NULL || ds->fur || ds->shaderInfo->furNumLayers < 1 )
63                 return;
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                 /* set it to fur */
96                 fur->fur = qtrue;
97                 
98                 /* walk the verts */
99                 for( j = 0; j < fur->numVerts; j++ )
100                 {
101                         /* get surface vert */
102                         dv = &ds->verts[ j ];
103                                 
104                         /* offset is scaled by original vertex alpha */
105                         a = (float) dv->color[ 0 ][ 3 ] / 255.0;
106                         
107                         /* get fur vert */
108                         dv = &fur->verts[ j ];
109                         
110                         /* offset it */
111                         VectorMA( dv->xyz, (offset * a * i), dv->normal, dv->xyz );
112                         
113                         /* fade alpha */
114                         for( k = 0; k < MAX_LIGHTMAPS; k++ )
115                         {
116                                 a = (float) dv->color[ k ][ 3 ] - fade;
117                                 if( a > 255.0f )
118                                         dv->color[ k ][ 3 ] = 255;
119                                 else if( a < 0 )
120                                         dv->color[ k ][ 3 ] = 0;
121                                 else
122                                         dv->color[ k ][ 3 ] = a;
123                         }
124                 }
125         }
126 }
127
128
129