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]
59typedef struct extents_s {
74 for (
int k = 0; k <
curTile->numfaces; k++) {
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++)
258typedef struct facelight_s {
274typedef 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;
490 for (
int i = 0;
i <
curTile->numtheads;
i++) {
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++) {
654 const int v = e >= 0 ?
curTile->edges[e].v[0] :
curTile->edges[-e].v[1];
680 for (
int i = 0;
i <
curTile->numvertexes;
i++) {
687 for (
int j = 0; j < num_vert_faces; j++) {
718 float nearest = 9999.0;
733 if (dist[
i] < nearest) {
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;
934 const byte* bspLightBytes =
curTile->lightdata[lightmapIndex];
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)",
1006 curTile->texinfo[
f->texinfo].texture);
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.0f);
void GetVectorFromString(const char *value, vec3_t vec)
Converts a string into a vec3_t.
void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec)
Converts the value of a entity parameter into a vec3_t.
vec_t FloatForKey(const entity_t *ent, const char *key)
entity_t entities[MAX_MAP_ENTITIES]
const char * ValueForKey(const entity_t *ent, const char *key)
entity_t * FindTargetEntity(const char *target)
Searches the entities array for an entity with the parameter targetname that matches the searched tar...
void Com_Printf(const char *const fmt,...)
#define LEVEL_LASTLIGHTBLOCKING
int FS_Write(const void *buffer, int len, qFILE *f)
Properly handles partial writes.
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
void Sys_Error(const char *error,...)
vec3_t face_offset[MAX_MAP_FACES]
patch_t * face_patches[MAX_MAP_FACES]
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,...
void BuildVertexNormals(void)
Calculate per-vertex (instead of per-plane) normal vectors. This is done by finding all of the faces ...
emittype_t
Different types of sources emitting light.
void BuildLights(void)
Create lights out of patches and entity lights.
static void ExportLightmap(const char *path, const char *name, bool day)
Export all the faces for one particular lightmap (day or night).
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 FinalLightFace(unsigned int facenum)
Add the indirect lighting on top of the direct lighting and save into final map format.
void BuildFacelights(unsigned int facenum)
static void CalcLightinfoExtents(lightinfo_t *l)
static light_t * lights[LIGHTMAP_MAX]
static void CalcLightinfoVectors(lightinfo_t *l)
Fills in texorg, worldtotex. and textoworld.
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...
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...
void ExportLightmaps(const char *bspFileName)
Export the day and night lightmap and direction data for the given map.
static void WriteTGA24(const char *filename, const byte *data, int width, int height, int offset)
static facelight_t facelight[LIGHTMAP_MAX][MAX_MAP_FACES]
static void FacesWithVert(int vert, int *faces, int *nfaces)
Populate faces with indexes of all dBspFace_t's referencing the specified edge.
static const float sampleofs[2][MAX_SAMPLES][2]
static int numlights[LIGHTMAP_MAX]
static extents_t face_extents[MAX_MAP_FACES]
static void BuildFaceExtents(void)
Populates face_extents for all dBspSurface_t, prior to light creation. This is done so that sample po...
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 ...
static void GatherSampleLight(vec3_t pos, const vec3_t normal, float *sample, float *direction, float scale, int *headhints)
#define sun_ambient_color
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...
static const vec3_t luminosity
vec_t VectorNormalize(vec3_t v)
Calculate unit vector for a given vec3_t.
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
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).
void VectorMix(const vec3_t v1, const vec3_t v2, float mix, vec3_t out)
Calculate a position on v1 v2 line.
vec_t ColorNormalize(const vec3_t in, vec3_t out)
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Create the rotation matrix in order to rotate something.
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...
#define Mem_AllocTypeN(type, n)
#define Mem_AllocType(type)
QGL_EXTERN GLuint GLchar GLuint * len
QGL_EXTERN GLenum GLuint * dest
QGL_EXTERN int GLboolean GLfloat * v
QGL_EXTERN GLsizei const GLvoid * data
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void Com_StripExtension(const char *in, char *out, const size_t size)
Removes the file extension from a filename.
const char * Com_SkipPath(const char *pathname)
Returns just the filename from a given path.
void Com_FilePath(const char *in, char *out, size_t size)
Returns the path up to, but not including the last /.
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
int lightofs[LIGHTMAP_MAX]
buckets for sample accumulation - clipped by the surface
lightinfo is a temporary bucket for lighting calculations
static mapTiles_t mapTiles
int TR_TestLine_r(TR_TILE_TYPE *tile, int32_t nodenum, const vec3_t start, const vec3_t end)
static const vec3_t scale
#define Vector2NotEmpty(a)
#define VectorNegate(src, dest)
#define VectorNotEmpty(a)
#define VectorSubtract(a, b, dest)
#define VectorCopy(src, dest)
#define VectorAdd(a, b, dest)
#define DotProduct(x, y)
Returns the distance between two 3-dimensional vectors.
#define VectorSet(v, x, y, z)
#define VectorScale(in, scale, out)