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