Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lightmap.hpp
Go to the documentation of this file.
1 
2 #pragma once
3 
4 // lightmaps are textures covering all static planes to add lighting.
5 #include "inexor/shared/cube_types.hpp" // for ushort, uchar, uint
6 #include "inexor/shared/cube_vector.hpp" // for vector
7 #include "inexor/shared/geom.hpp" // for vec, vec2, bvec, ivec (ptr ...
8 
9 struct cube;
10 struct entity;
11 struct extentity;
12 struct surfaceinfo;
13 struct vertinfo;
14 
15 #define LM_MINW 2
16 #define LM_MINH 2
17 #define LM_MAXW 128
18 #define LM_MAXH 128 //min and maximum dimensions of one lightmap-sample (the smaller the samples the bigger the resolution)
19 #define LM_PACKW 512 //size of one packed and saved lightmap
20 #define LM_PACKH 512
21 
22 //a helper node to save more lightmaps on a lightmaptexture
23 //it basicly just containes its position on the lmtex (x, y) , the area it contains (w,h) and how much unused pixels in this area are
24 //structure is as follows:
25 // rootnode (every lightmaptex has one)
26 // child1 child2
27 // child1a child1b child2a child2b
28 // ...
29 //
30 struct PackNode
31 {
33  ushort x, y, w, h;
34  int available; //amount of pixels without lightmap-information
35 
36  PackNode();
38 
39  void clear();
40 
42  {
43  clear();
44  }
45 
46  bool insert(ushort &tx, ushort &ty, ushort tw, ushort th);
47 };
48 
49 enum
50 {
51  LM_DIFFUSE = 0,
54  LM_TYPE = 0x0F,
55 
56  LM_ALPHA = 1<<4,
57  LM_FLAGS = 0xF0
58 };
59 
60 struct LightMap
61 {
63  PackNode packroot; //the availability-information-tree
64  uint lightmaps, lumels; //lumel = lightmap pixel
65  int unlitx, unlity; //one unlit lumel
67 
69  : type(LM_DIFFUSE), bpp(3), tex(-1), offsetx(-1), offsety(-1),
70  lightmaps(0), lumels(0), unlitx(-1), unlity(-1),
71  data(nullptr)
72  {
73  }
74 
76  {
77  if(data) delete[] data;
78  }
79 
80  void finalize()
81  {
82  packroot.clear();
83  packroot.available = 0;
84  }
85 
86  void copy(ushort tx, ushort ty, uchar *src, ushort tw, ushort th);
87  bool insert(ushort &tx, ushort &ty, uchar *src, ushort tw, ushort th);
88 };
89 
91 
93 {
94  int w, h, type;
96  int unlitx, unlity;
97 
99  : w(0), h(0), type(LM_DIFFUSE), id(0), unlitx(-1), unlity(-1)
100  {}
101 };
102 
104 
106 
107 extern void clearlights();
108 extern void initlights();
109 extern void lightents(bool force = false);
110 extern void clearlightcache(int id = -1);
111 extern void resetlightmaps(bool fullclean = true);
112 extern void brightencube(cube &c);
113 extern void setsurfaces(cube &c, const surfaceinfo *surfs, const vertinfo *verts, int numverts);
114 extern void setsurface(cube &c, int orient, const surfaceinfo &surf, const vertinfo *verts, int numverts);
115 extern void previewblends(const ivec &bo, const ivec &bs);
116 
117 struct lerpvert
118 {
121 
122  bool operator==(const lerpvert &l) const { return tc == l.tc;; }
123  bool operator!=(const lerpvert &l) const { return tc != l.tc; }
124 };
125 
127 {
128  const lerpvert *min;
129  const lerpvert *max;
130  float u, ustep;
132  int winding;
133 };
134 
135 extern void calcnormals(bool lerptjoints = false);
136 extern void clearnormals();
137 extern void findnormal(const vec &key, const vec &surface, vec &v);
138 extern void calclerpverts(const vec2 *c, const vec *n, lerpvert *lv, int &numv);
139 extern void initlerpbounds(float u, float v, const lerpvert *lv, int numv, lerpbounds &start, lerpbounds &end);
140 extern void lerpnormal(float u, float v, const lerpvert *lv, int numv, lerpbounds &start, lerpbounds &end, vec &normal, vec &nstep);
141 
142 #define CHECK_CALCLIGHT_PROGRESS_LOCKED(exit, show_calclight_progress, before, after) \
143  if(check_calclight_progress) \
144  { \
145  if(!calclight_canceled) \
146  { \
147  before; \
148  show_calclight_progress(); \
149  check_calclight_canceled(); \
150  after; \
151  } \
152  if(calclight_canceled) { exit; } \
153  }
154 #define CHECK_CALCLIGHT_PROGRESS(exit, show_calclight_progress) CHECK_CALCLIGHT_PROGRESS_LOCKED(exit, show_calclight_progress, , )
155 
156 extern bool calclight_canceled;
157 extern volatile bool check_calclight_progress;
158 
159 extern void check_calclight_canceled();
160 
161 extern int lightmapping;
162 
163 
164 extern void lightent(extentity &e, float height = 8.0f);
165 extern void lightreaching(const vec &target, vec &color, vec &dir, bool fast = false, extentity *e = nullptr, float ambient = 0.4f);
166 extern entity *brightestlight(const vec &target, const vec &dir);
Definition: lightmap.hpp:60
PackNode()
Definition: lightmap.cpp:375
bool insert(ushort &tx, ushort &ty, uchar *src, ushort tw, ushort th)
Definition: lightmap.cpp:379
Vector template.
Definition: cube_vector.hpp:22
void calcnormals(bool lerptjoints=false)
Definition: normal.cpp:247
int type
Definition: lightmap.hpp:94
vec normal
Definition: lightmap.hpp:131
ushort h
Definition: lightmap.hpp:33
Definition: normal.cpp:31
uint lumels
Definition: lightmap.hpp:64
void brightencube(cube &c)
Definition: lightmap.cpp:192
void initlights()
Definition: lightmap.cpp:2772
GLenum GLsizei GLsizei height
Definition: glexts.hpp:291
float u
Definition: lightmap.hpp:130
vec nstep
Definition: lightmap.hpp:131
unsigned int uint
Definition: cube_types.hpp:9
void resetlightmaps(bool fullclean=true)
Definition: lightmap.cpp:2173
void clearnormals()
Definition: normal.cpp:257
~PackNode()
Definition: lightmap.hpp:41
int unlity
Definition: lightmap.hpp:96
vector< LightMapTexture > lightmaptexs
Definition: lightmap.cpp:2468
Definition: octree.hpp:74
int bpp
Definition: lightmap.hpp:62
int type
Definition: lightmap.hpp:62
int unlitx
Definition: lightmap.hpp:96
Definition: lightmap.hpp:57
bool operator!=(const lerpvert &l) const
Definition: lightmap.hpp:123
2-dimensional float vectors
Definition: geom.hpp:38
Definition: lightmap.hpp:53
void copy(ushort tx, ushort ty, uchar *src, ushort tw, ushort th)
Definition: lightmap.cpp:389
int numverts
Definition: explosion.cpp:35
int unlity
Definition: lightmap.hpp:65
void lerpnormal(float u, float v, const lerpvert *lv, int numv, lerpbounds &start, lerpbounds &end, vec &normal, vec &nstep)
Definition: normal.cpp:367
uint lightmaps
Definition: lightmap.hpp:64
persistent map entity.
Definition: ents.hpp:66
Definition: lightmap.hpp:51
float ustep
Definition: lightmap.hpp:130
int h
Definition: lightmap.hpp:94
void lightent(extentity &e, float height=8.0f)
Definition: lightmap.cpp:2748
ICOMMAND * f(float *a, float *b), floatret(*a **b)
bvec ambientcolor
ushort x
Definition: lightmap.hpp:33
unsigned short ushort
Definition: cube_types.hpp:8
Definition: lightmap.hpp:54
vec normal
Definition: lightmap.hpp:119
void check_calclight_canceled()
Definition: lightmap.cpp:291
void setsurface(cube &c, int orient, const surfaceinfo &surf, const vertinfo *verts, int numverts)
Definition: lightmap.cpp:205
PackNode * child2
Definition: lightmap.hpp:32
void start(const char *filename, int videofps, int videow, int videoh, bool sound)
Definition: movie.cpp:975
int available
Definition: lightmap.hpp:34
Definition: ents.hpp:102
vector with 3 floats and some useful methods.
Definition: geom.hpp:110
void lightents(bool force=false)
Definition: lightmap.cpp:2762
volatile bool check_calclight_progress
Definition: lightmap.cpp:289
~LightMap()
Definition: lightmap.hpp:75
Definition: lightmap.hpp:126
void initlerpbounds(float u, float v, const lerpvert *lv, int numv, lerpbounds &start, lerpbounds &end)
Definition: normal.cpp:309
void clearlightcache(int id=-1)
Definition: lightmap.cpp:1237
3-dimensional UNSIGNED CHAR vector.
Definition: geom.hpp:1398
void lightreaching(const vec &target, vec &color, vec &dir, bool fast=false, extentity *e=nullptr, float ambient=0.4f)
Definition: lightmap.cpp:2814
LightMap()
Definition: lightmap.hpp:68
int tex
Definition: lightmap.hpp:62
void setsurfaces(cube &c, const surfaceinfo *surfs, const vertinfo *verts, int numverts)
Definition: lightmap.cpp:198
int winding
Definition: lightmap.hpp:132
const lerpvert * max
Definition: lightmap.hpp:129
int orient
Definition: octaedit.cpp:164
Definition: lightmap.hpp:117
vector< LightMap > lightmaps
Definition: lightmap.cpp:127
PackNode packroot
Definition: lightmap.hpp:63
#define dir(name, v, d, s, os)
Definition: physics.cpp:2014
bvec skylightcolor
unsigned char uchar
Basic type definitions.
Definition: cube_types.hpp:7
int lightmapping
Definition: lightmap.cpp:125
bool calclight_canceled
Definition: lightmap.cpp:288
int offsetx
Definition: lightmap.hpp:62
int end()
Definition: glemu.cpp:256
struct sphere::vert * verts
int offsety
Definition: lightmap.hpp:62
Definition: lightmap.hpp:92
void calclerpverts(const vec2 *c, const vec *n, lerpvert *lv, int &numv)
Definition: normal.cpp:264
uint id
Definition: lightmap.hpp:95
ushort y
Definition: lightmap.hpp:33
Definition: lightmap.hpp:30
int unlitx
Definition: lightmap.hpp:65
static int lerptjoints
Definition: lightmap.cpp:282
ushort w
Definition: lightmap.hpp:33
const lerpvert * min
Definition: lightmap.hpp:128
bool operator==(const lerpvert &l) const
Definition: lightmap.hpp:122
mathmatics for vectors, matrices, quaterions and more
void previewblends(const ivec &bo, const ivec &bs)
Definition: lightmap.cpp:2152
static void color(const bvec &v, uchar alpha=255)
Definition: glemu.hpp:71
int w
Definition: lightmap.hpp:94
Definition: lightmap.hpp:56
void findnormal(const vec &key, const vec &surface, vec &v)
Definition: normal.cpp:135
3-dimensional INTEGER vectors
Definition: geom.hpp:1226
void clear()
Definition: lightmap.cpp:369
entity * brightestlight(const vec &target, const vec &dir)
Definition: lightmap.cpp:2885
uchar * data
Definition: lightmap.hpp:66
void finalize()
Definition: lightmap.hpp:80
bool insert(ushort &tx, ushort &ty, ushort tw, ushort th)
Definition: lightmap.cpp:333
bool target(fpsent *d, aistate &b, int pursue=0, bool force=false, float mindist=0.f)
Definition: ai.cpp:393
Definition: octree.hpp:208
PackNode * child1
Definition: lightmap.hpp:32
LightMapTexture()
Definition: lightmap.hpp:98
vec2 tc
Definition: lightmap.hpp:120
Definition: lightmap.hpp:52
void clearlights()
Definition: lightmap.cpp:2731
Definition: octree.hpp:50