28 #define sun_angles config.sun_angles[config.compile_for_day] 29 #define sun_normal config.sun_normal[config.compile_for_day] 30 #define sun_color config.sun_color[config.compile_for_day] 31 #define sun_intensity config.sun_intensity[config.compile_for_day] 32 #define sun_ambient_color config.sun_ambient_color[config.compile_for_day] 59 typedef struct extents_s {
88 VectorSet(maxs, -999999, -999999, -999999);
90 stmins[0] = stmins[1] = 999999;
91 stmaxs[0] = stmaxs[1] = -999999;
103 for (j = 0; j < 3; j++) {
104 if (
v->point[j] > maxs[j])
105 maxs[j] =
v->point[j];
106 if (
v->point[j] < mins[j])
107 mins[j] =
v->point[j];
110 for (j = 0; j < 2; j++) {
120 for (
i = 0;
i < 3;
i++)
121 center[
i] = (mins[
i] + maxs[
i]) / 2.0f;
131 float* stmins, *stmaxs;
133 const int luxelScale = (1 <<
config.lightquant);
140 for (
int i = 0;
i < 2;
i++) {
141 lm_mins[
i] = floor(stmins[
i] / luxelScale);
142 lm_maxs[
i] = ceil(stmaxs[
i] / luxelScale);
160 vec_t distscale, dist;
164 for (
i = 0;
i < 2;
i++)
169 texnormal[0] = tex->
vecs[1][1] * tex->
vecs[0][2]
170 - tex->
vecs[1][2] * tex->
vecs[0][1];
171 texnormal[1] = tex->
vecs[1][2] * tex->
vecs[0][0]
172 - tex->
vecs[1][0] * tex->
vecs[0][2];
173 texnormal[2] = tex->
vecs[1][0] * tex->
vecs[0][1]
174 - tex->
vecs[1][1] * tex->
vecs[0][0];
183 if (distscale < 0.0) {
184 distscale = -distscale;
190 distscale = 1.0 / distscale;
192 for (
i = 0;
i < 2;
i++) {
200 for (
i = 0;
i < 3;
i++)
244 for (
int t = 0; t < h; t++) {
245 for (
int s = 0; s < w; s++, surf += 3) {
246 const vec_t us = starts + (s + sofs) * step;
247 const vec_t ut = startt + (t + tofs) * step;
250 for (
int j = 0; j < 3; j++)
258 typedef struct facelight_s {
274 typedef struct light_s {
331 if (
config.compile_for_day) {
332 const int spawnflags = atoi(
ValueForKey(e,
"spawnflags"));
333 if (!(spawnflags & 1))
350 if (color && color[0] !=
'\0'){
351 if (sscanf(color,
"%f %f %f", &l->
color[0], &l->
color[1], &l->
color[2]) != 3)
352 Sys_Error(
"Invalid _color entity property given: %s", color);
360 if (target[0] !=
'\0' ||
Q_streq(
name,
"light_spot")) {
366 if (target[0] !=
'\0') {
369 Com_Printf(
"WARNING: light at (%i %i %i) has missing target '%s' - e.g. create an info_null that has a 'targetname' set to '%s'\n",
397 const char* ambient, *light, *angles, *color;
401 if (
config.compile_for_day) {
413 if (light[0] !=
'\0')
416 if (angles[0] !=
'\0') {
419 Sys_Error(
"wrong angles values given: '%s'", angles);
423 if (color[0] !=
'\0') {
428 if (ambient[0] !=
'\0')
451 if (
i >= 1 &&
i <= 6)
457 Verb_Printf(
VERB_EXTRA,
"light settings:\n * intensity: %i\n * sun_angles: pitch %f yaw %f\n * sun_color: %f:%f:%f\n * sun_ambient_color: %f:%f:%f\n",
473 static int shared_lastthead = 0;
474 int lastthead = *headhint;
477 lastthead = shared_lastthead;
478 *headhint = lastthead;
497 shared_lastthead = *headhint =
i;
554 for (l =
lights[
config.compile_for_day], headhint = headhints; l; l = l->
next, headhint++) {
575 light = (l->
intensity / (dist * dist)) * dot;
613 #define SAMPLE_NUDGE 0.25 633 #define MAX_VERT_FACES 256 652 for (
int j = 0; j < face->
numedges; j++) {
687 for (
int j = 0; j < num_vert_faces; j++) {
718 float nearest = 9999.0;
733 if (dist[
i] < nearest) {
742 #define MAX_SAMPLES 5 743 #define SOFT_SAMPLES 4 745 {{0.0, 0.0}, {-0.125, -0.125}, {0.125, -0.125}, {0.125, 0.125}, {-0.125, 0.125}},
746 {{-0.66, 0.33}, {-0.33, -0.66}, {0.33, 0.66}, {0.66, -0.33},{0.0,0.0}}
767 float* sdir = tex->
vecs[0];
768 float* tdir = tex->
vecs[1];
780 float scale = 1.0 / numsamples;
817 float*
const sample = fl->
samples[
i];
829 const int grid_type =
config.soft ? 1 : 0;
830 for (
int j = 0; j < numsamples; j++) {
871 #define TGA_HEADER_SIZE 18 874 const int size = width * height * 3;
879 buffer[12] = width & 255;
880 buffer[13] = width >> 8;
881 buffer[14] = height & 255;
882 buffer[15] = height >> 8;
888 for (
int i = 0;
i <
size;
i += 3) {
917 for (
int i = 0;
i < 2;
i++) {
918 const float mins = floor(stmins[
i] /
scale);
919 const float maxs = ceil(stmaxs[
i] /
scale);
921 texsize[
i] = maxs - mins + 1;
933 const int lightmapIndex = day ? 1 : 0;
935 const byte quant = *bspLightBytes;
936 const int scale = 1 << quant;
940 const byte* lightmap = bspLightBytes + face->
lightofs[lightmapIndex];
1004 Sys_Error(
"MAX_MAP_LIGHTING (%i exceeded %i) - try to reduce the brush size (%s)",
1032 for (k = 0; k < 3; k++) {
1044 for (k = 0; k < 3; k++) {
1047 temp[k] *=
config.contrast;
1053 else if (temp[k] < 0)
1064 for (k = 0; k < 3; k++) {
1067 if (temp[k] > 255.0)
1069 else if (temp[k] < 0.0)
1078 for (k = 0; k < 3; k++)
1079 *
dest++ = (
byte)((dir[k] + 1.0f) * 127.0
f);
#define Vector2NotEmpty(a)
void VectorMix(const vec3_t v1, const vec3_t v2, float mix, vec3_t out)
Calculate a position on v1 v2 line.
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
static void GatherSampleLight(vec3_t pos, const vec3_t normal, float *sample, float *direction, float scale, int *headhints)
#define LEVEL_LASTLIGHTBLOCKING
#define VectorCopy(src, dest)
#define Mem_AllocTypeN(type, n)
void Sys_Error(const char *error,...)
static void BuildFaceExtents(void)
Populates face_extents for all dBspSurface_t, prior to light creation. This is done so that sample po...
#define VectorSet(v, x, y, z)
int surfedges[MAX_MAP_SURFEDGES]
static void CalcLightinfoExtents(lightinfo_t *l)
void VectorMA(const vec3_t veca, const float scale, const vec3_t vecb, vec3_t outVector)
Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb)
const char * Com_SkipPath(const char *pathname)
Returns just the filename from a given path.
dBspVertex_t vertexes[MAX_MAP_VERTS]
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
static void SampleNormal(const lightinfo_t *l, const vec3_t pos, vec3_t normal)
For Phong-shaded samples, interpolate the vertex normals for the surface in question, weighting them according to their proximity to the sample position.
vec_t ColorNormalize(const vec3_t in, vec3_t out)
static const vec3_t scale
byte lightdata[LIGHTMAP_MAX][MAX_MAP_LIGHTING]
void BuildLights(void)
Create lights out of patches and entity lights.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
void Com_StripExtension(const char *in, char *out, const size_t size)
Removes the file extension from a filename.
static const vec3_t luminosity
#define VectorNegate(src, dest)
void Com_FilePath(const char *in, char *out, size_t size)
Returns the path up to, but not including the last /.
static void WriteTGA24(const char *filename, const byte *data, int width, int height, int offset)
static void GatherSampleSunlight(const vec3_t pos, const vec3_t normal, float *sample, float *direction, float scale, int *headhint)
A follow-up to GatherSampleLight, simply trace along the sun normal, adding sunlight.
void ExportLightmaps(const char *bspFileName)
Export the day and night lightmap and direction data for the given map.
static bool TR_TestLineSingleTile(const vec3_t start, const vec3_t stop, int *headhint)
Checks traces against a single-tile map, optimized for ufo2map. This trace is only for visible levels...
QGL_EXTERN GLsizei const GLvoid * data
void Com_Printf(const char *const fmt,...)
static void CalcPoints(lightinfo_t *l, float sofs, float tofs)
For each texture aligned grid point, back project onto the plane to get the world xyz value of the sa...
entity_t entities[MAX_MAP_ENTITIES]
static void ExportLightmap(const char *path, const char *name, bool day)
Export all the faces for one particular lightmap (day or night)
void BuildFacelights(unsigned int facenum)
#define VectorScale(in, scale, out)
static light_t * lights[LIGHTMAP_MAX]
static extents_t face_extents[MAX_MAP_FACES]
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Create the rotation matrix in order to rotate something.
int theadlevel[LEVEL_MAX]
lightinfo is a temporary bucket for lighting calculations
#define DotProduct(x, y)
Returns the distance between two 3-dimensional vectors.
void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec)
Converts the value of a entity parameter into a vec3_t.
entity_t * FindTargetEntity(const char *target)
Searches the entities array for an entity with the parameter targetname that matches the searched tar...
void TangentVectors(const vec3_t normal, const vec3_t sdir, const vec3_t tdir, vec4_t tangent, vec3_t binormal)
Projects the normalized directional vectors on to the normal's plane. The fourth component of the res...
static facelight_t facelight[LIGHTMAP_MAX][MAX_MAP_FACES]
static int numlights[LIGHTMAP_MAX]
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
int TR_TestLine_r(TR_TILE_TYPE *tile, int32_t nodenum, const vec3_t start, const vec3_t end)
int lightdatasize[LIGHTMAP_MAX]
void GetVectorFromString(const char *value, vec3_t vec)
Converts a string into a vec3_t.
#define VectorNotEmpty(a)
dBspTexinfo_t texinfo[MAX_MAP_TEXINFO]
static void CalcTextureSize(const dBspSurface_t *s, vec2_t texsize, int scale)
Calculates the texture width for the lightmap texture. This depends on the surface mins and maxs and ...
void BuildVertexNormals(void)
Calculate per-vertex (instead of per-plane) normal vectors. This is done by finding all of the faces ...
QGL_EXTERN GLenum GLuint * dest
patch_t * face_patches[MAX_MAP_FACES]
dBspSurface_t faces[MAX_MAP_FACES]
dBspEdge_t edges[MAX_MAP_EDGES]
#define VectorAdd(a, b, dest)
QGL_EXTERN GLuint GLchar GLuint * len
buckets for sample accumulation - clipped by the surface
static void NudgeSamplePosition(const vec3_t in, const vec3_t normal, const vec3_t center, vec3_t out)
Move the incoming sample position towards the surface center and along the surface normal to reduce f...
vec3_t face_offset[MAX_MAP_FACES]
static void CalcLightinfoVectors(lightinfo_t *l)
Fills in texorg, worldtotex. and textoworld.
vec_t VectorNormalize(vec3_t v)
Calculate unit vector for a given vec3_t.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
vec_t FloatForKey(const entity_t *ent, const char *key)
#define sun_ambient_color
static void FacesWithVert(int vert, int *faces, int *nfaces)
Populate faces with indexes of all dBspFace_t's referencing the specified edge.
dBspNormal_t normals[MAX_MAP_VERTS]
#define Mem_AllocType(type)
const char * ValueForKey(const entity_t *ent, const char *key)
int lightofs[LIGHTMAP_MAX]
dBspPlane_t planes[MAX_MAP_PLANES]
QGL_EXTERN int GLboolean GLfloat * v
#define VectorSubtract(a, b, dest)
static mapTiles_t mapTiles
int FS_Write(const void *buffer, int len, qFILE *f)
Properly handles partial writes.
static const float sampleofs[2][MAX_SAMPLES][2]
emittype_t
Different types of sources emitting light.
void FinalLightFace(unsigned int facenum)
Add the indirect lighting on top of the direct lighting and save into final map format.