]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_brush.h
fixed models getting dark in the distance when fogged bug (thanks to Elric for report...
[xonotic/darkplaces.git] / model_brush.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef MODEL_BRUSH_H
22 #define MODEL_BRUSH_H
23
24 /*
25 ==============================================================================
26
27 BRUSH MODELS
28
29 ==============================================================================
30 */
31
32
33 //
34 // in memory representation
35 //
36 typedef struct
37 {
38         vec3_t          position;
39 }
40 mvertex_t;
41
42 #define SIDE_FRONT      0
43 #define SIDE_BACK       1
44 #define SIDE_ON         2
45
46
47 // plane_t structure
48 typedef struct mplane_s
49 {
50         vec3_t  normal;
51         float   dist;
52         int             type;                   // for texture axis selection and fast side tests
53         // LordHavoc: faster than id's signbits system
54         int (*BoxOnPlaneSideFunc) (vec3_t emins, vec3_t emaxs, struct mplane_s *p);
55 }
56 mplane_t;
57
58 typedef struct texture_s
59 {
60         // name
61         char name[16];
62         // size
63         unsigned int width, height;
64         // SURF_ flags
65         unsigned int flags;
66
67         // base texture without fullbrights, never NULL
68         rtexture_t *texture;
69         // fullbrights texture, NULL if no fullbrights used
70         rtexture_t *glowtexture;
71         // alpha texture (used for fogging), NULL if opaque
72         rtexture_t *fogtexture;
73         // detail texture (usually not used if transparent)
74         rtexture_t *detailtexture;
75
76         // total frames in sequence and alternate sequence
77         int anim_total[2];
78         // direct pointers to each of the frames in the sequences
79         // (indexed as [alternate][frame])
80         struct texture_s *anim_frames[2][10];
81         // set if animated or there is an alternate frame set
82         // (this is an optimization in the renderer)
83         int animated;
84 }
85 texture_t;
86
87
88 #define SURF_PLANEBACK          2
89 #define SURF_DRAWSKY            4
90 #define SURF_DRAWTURB           0x10
91 #define SURF_LIGHTMAP           0x20
92 #define SURF_DRAWNOALPHA        0x100
93 #define SURF_DRAWFULLBRIGHT     0x200
94 #define SURF_LIGHTBOTHSIDES     0x400
95 #define SURF_CLIPSOLID          0x800 // this polygon can obscure other polygons
96
97 typedef struct
98 {
99         unsigned short  v[2];
100 }
101 medge_t;
102
103 typedef struct
104 {
105         float           vecs[2][4];
106         texture_t       *texture;
107         int                     flags;
108 }
109 mtexinfo_t;
110
111 typedef struct surfvertex_s
112 {
113         // position
114         float v[3];
115         // offset into lightmap (used by vertex lighting)
116         int lightmapoffset;
117         // texture coordinates
118         float st[2];
119         // lightmap coordinates
120         float uv[2];
121         // detail texture coordinates
122         float ab[2];
123 }
124 surfvertex_t;
125
126 // LordHavoc: replaces glpoly, triangle mesh
127 typedef struct surfmesh_s
128 {
129         // can be multiple meshs per surface
130         struct surfmesh_s *chain;
131         int numverts;
132         int numtriangles;
133         surfvertex_t *vertex;
134         int *index;
135 }
136 surfmesh_t;
137
138 typedef struct msurface_s
139 {
140         // should be drawn if visframe == r_framecount (set by WorldNode functions)
141         int                     visframe;
142
143         // the node plane this is on, backwards if SURF_PLANEBACK flag set
144         mplane_t        *plane;
145         // SURF_ flags
146         int                     flags;
147         struct Cshader_s        *shader;
148         struct msurface_s       *chain; // shader rendering chain
149
150         // look up in model->surfedges[], negative numbers are backwards edges
151         int                     firstedge;
152         int                     numedges;
153
154         short           texturemins[2];
155         short           extents[2];
156
157         mtexinfo_t      *texinfo;
158         texture_t       *currenttexture; // updated (animated) during early surface processing each frame
159
160         // index into d_lightstylevalue array, 255 means not used (black)
161         qbyte           styles[MAXLIGHTMAPS];
162         // RGB lighting data [numstyles][height][width][3]
163         qbyte           *samples;
164         // stain to apply on lightmap (soot/dirt/blood/whatever)
165         qbyte           *stainsamples;
166
167         // these fields are generated during model loading
168         // the lightmap texture fragment to use on the surface
169         rtexture_t *lightmaptexture;
170         // the stride when building lightmaps to comply with fragment update
171         int                     lightmaptexturestride;
172         // mesh for rendering
173         surfmesh_t      *mesh;
174
175         // these are just 3D points defining the outline of the polygon,
176         // no texcoord info (that can be generated from these)
177         int                     poly_numverts;
178         float           *poly_verts;
179         // the center is useful for sorting
180         float           poly_center[3];
181
182         // these are regenerated every frame
183         // lighting info
184         int                     dlightframe;
185         int                     dlightbits[8];
186         // avoid redundent addition of dlights
187         int                     lightframe;
188         // only render each surface once
189         int                     worldnodeframe;
190         // marked when surface is prepared for the frame
191         int                     insertframe;
192
193         // these cause lightmap updates if regenerated
194         // values currently used in lightmap
195         unsigned short cached_light[MAXLIGHTMAPS];
196         // if lightmap was lit by dynamic lights, force update on next frame
197         short           cached_dlight;
198         // to cause lightmap to be rerendered when v_overbrightbits changes
199         short           cached_lightscalebit;
200         // rerender lightmaps when r_ambient changes
201         float           cached_ambient;
202 }
203 msurface_t;
204
205 #define SHADERSTAGE_SKY 0
206 #define SHADERSTAGE_NORMAL 1
207 #define SHADERSTAGE_COUNT 2
208
209 struct entity_render_s;
210 // change this stuff when real shaders are added
211 typedef struct Cshader_s
212 {
213         void (*shaderfunc[SHADERSTAGE_COUNT])(const struct entity_render_s *ent, const msurface_t *firstsurf);
214         // list of surfaces using this shader (used during surface rendering)
215         msurface_t *chain;
216 }
217 Cshader_t;
218
219 extern Cshader_t Cshader_wall_vertex;
220 extern Cshader_t Cshader_wall_lightmap;
221 extern Cshader_t Cshader_wall_fullbright;
222 extern Cshader_t Cshader_water;
223 extern Cshader_t Cshader_sky;
224
225 // warning: if this is changed, references must be updated in cpu_* assembly files
226 typedef struct mnode_s
227 {
228 // common with leaf
229         int                                     contents;               // 0, to differentiate from leafs
230
231         struct mnode_s          *parent;
232         struct mportal_s        *portals;
233
234         // for bounding box culling
235         vec3_t                          mins;
236         vec3_t                          maxs;
237
238 // node specific
239         mplane_t                        *plane;
240         struct mnode_s          *children[2];
241
242         unsigned short          firstsurface;
243         unsigned short          numsurfaces;
244 }
245 mnode_t;
246
247 typedef struct mleaf_s
248 {
249 // common with node
250         int                                     contents;               // will be a negative contents number
251
252         struct mnode_s          *parent;
253         struct mportal_s        *portals;
254
255         // for bounding box culling
256         vec3_t                          mins;
257         vec3_t                          maxs;
258
259 // leaf specific
260         int                                     visframe;               // visible if current (r_framecount)
261         int                                     worldnodeframe; // used by certain worldnode variants to avoid processing the same leaf twice in a frame
262         int                                     portalmarkid;   // used by polygon-through-portals visibility checker
263
264         // LordHavoc: leaf based dynamic lighting
265         int                                     dlightbits[8];
266         int                                     dlightframe;
267
268         qbyte                           *compressed_vis;
269
270         msurface_t                      **firstmarksurface;
271         int                                     nummarksurfaces;
272         qbyte                           ambient_sound_level[NUM_AMBIENTS];
273 }
274 mleaf_t;
275
276 typedef struct
277 {
278         dclipnode_t     *clipnodes;
279         mplane_t        *planes;
280         int                     firstclipnode;
281         int                     lastclipnode;
282         vec3_t          clip_mins;
283         vec3_t          clip_maxs;
284         vec3_t          clip_size;
285 }
286 hull_t;
287
288 typedef struct mportal_s
289 {
290         struct mportal_s *next; // the next portal on this leaf
291         mleaf_t *here; // the leaf this portal is on
292         mleaf_t *past; // the leaf through this portal (infront)
293         mvertex_t *points;
294         int numpoints;
295         mplane_t plane;
296         int visframe; // is this portal visible this frame?
297 }
298 mportal_t;
299
300 typedef struct mlight_s
301 {
302         vec3_t origin;
303         float falloff;
304         vec3_t light;
305         float subtract;
306         vec3_t spotdir;
307         float spotcone; // cosine of spotlight cone angle (or 0 if not a spotlight)
308         float distbias;
309         int style;
310         int numleafs; // used only for loading calculations, number of leafs this shines on
311 }
312 mlight_t;
313
314 extern rtexture_t *r_notexture;
315 extern texture_t r_notexture_mip;
316
317 struct model_s;
318 void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
319 void Mod_BrushInit(void);
320 void Mod_FindNonSolidLocation(vec3_t pos, struct model_s *mod);
321
322 #endif
323