lightmap.c File Reference

#include "lighting.h"
#include "bsp.h"
Include dependency graph for lightmap.c:

Go to the source code of this file.

Data Structures

struct  lightinfo_t
 lightinfo is a temporary bucket for lighting calculations More...
struct  extents_s
 face extents More...
struct  facelight_s
 buckets for sample accumulation - clipped by the surface More...
struct  light_s
 a light source More...

Defines

#define sun_angles   config.sun_angles[config.compile_for_day]
#define sun_normal   config.sun_normal[config.compile_for_day]
#define sun_color   config.sun_color[config.compile_for_day]
#define sun_intensity   config.sun_intensity[config.compile_for_day]
#define sun_ambient_color   config.sun_ambient_color[config.compile_for_day]
#define SAMPLE_NUDGE   0.25
#define MAX_VERT_FACES   256
#define MAX_SAMPLES   5

Typedefs

typedef struct extents_s extents_t
 face extents
typedef struct facelight_s facelight_t
 buckets for sample accumulation - clipped by the surface
typedef struct light_s light_t
 a light source

Enumerations

enum  emittype_t { emit_surface, emit_point, emit_spotlight }
 

Different types of sources emitting light.

More...

Functions

static void BuildFaceExtents (void)
 Populates face_extents for all dBspSurface_t, prior to light creation. This is done so that sample positions may be nudged outward along the face normal and towards the face center to help with traces.
static void CalcLightinfoExtents (lightinfo_t *l)
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 sample point.
void BuildLights (void)
 Create lights out of patches and lights.
static qboolean 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.
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.
static void GatherSampleLight (vec3_t pos, const vec3_t normal, float *sample, float *direction, float scale, int *headhints)
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 false-positive traces.
static void FacesWithVert (int vert, int *faces, int *nfaces)
 Populate faces with indexes of all dBspFace_t's referencing the specified edge.
void BuildVertexNormals (void)
 Calculate per-vertex (instead of per-plane) normal vectors. This is done by finding all of the faces which share a given vertex, and calculating a weighted average of their normals.
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.
void BuildFacelights (unsigned int facenum)
static void WriteTGA24 (const char *filename, const byte *data, int width, int height, int offset)
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 the texture scale.
static void ExportLightmap (const char *path, const char *name, qboolean day)
 Export all the faces for one particular lightmap (day or night).
void ExportLightmaps (const char *bspFileName)
 Export the day and night lightmap and direction data for the given map.
void FinalLightFace (unsigned int facenum)
 Add the indirect lighting on top of the direct lighting and save into final map format.

Variables

vec3_t face_offset [MAX_MAP_FACES]
static extents_t face_extents [MAX_MAP_FACES]
static facelight_t facelight [LIGHTMAP_MAX][MAX_MAP_FACES]
static light_tlights [LIGHTMAP_MAX]
static int numlights [LIGHTMAP_MAX]
static const float sampleofs [MAX_SAMPLES][2]
static const vec3_t luminosity = {0.2125, 0.7154, 0.0721}

Detailed Description

Definition in file lightmap.c.


Define Documentation

#define MAX_SAMPLES   5

Definition at line 735 of file lightmap.c.

Referenced by BuildFacelights().

#define MAX_VERT_FACES   256

Definition at line 625 of file lightmap.c.

Referenced by BuildVertexNormals(), FacesWithVert(), and SampleNormal().

#define SAMPLE_NUDGE   0.25

Definition at line 605 of file lightmap.c.

Referenced by NudgeSamplePosition().

#define sun_ambient_color   config.sun_ambient_color[config.compile_for_day]

Definition at line 32 of file lightmap.c.

Referenced by BuildLights(), and FinalLightFace().

#define sun_angles   config.sun_angles[config.compile_for_day]

Definition at line 28 of file lightmap.c.

Referenced by BuildLights().

#define sun_color   config.sun_color[config.compile_for_day]

Definition at line 30 of file lightmap.c.

Referenced by BuildLights(), and GatherSampleSunlight().

#define sun_intensity   config.sun_intensity[config.compile_for_day]

Definition at line 31 of file lightmap.c.

Referenced by BuildLights(), and GatherSampleSunlight().

#define sun_normal   config.sun_normal[config.compile_for_day]

Definition at line 29 of file lightmap.c.

Referenced by BuildLights(), and GatherSampleSunlight().


Typedef Documentation

typedef struct extents_s extents_t

face extents

typedef struct facelight_s facelight_t

buckets for sample accumulation - clipped by the surface

typedef struct light_s light_t

a light source


Enumeration Type Documentation

enum emittype_t

Different types of sources emitting light.

Enumerator:
emit_surface 

surface light via SURF_LIGHT

emit_point 

point light given via light entity

emit_spotlight 

spotlight given via light entity (+target) or via light_spot entity

Definition at line 265 of file lightmap.c.


Function Documentation

static void BuildFaceExtents ( void   )  [static]

Populates face_extents for all dBspSurface_t, prior to light creation. This is done so that sample positions may be nudged outward along the face normal and towards the face center to help with traces.

Definition at line 68 of file lightmap.c.

References extents_s::center, curTile, DotProduct, dMapTile_t::edges, dMapTile_t::faces, dBspSurface_t::firstedge, i, extents_s::maxs, extents_s::mins, dBspSurface_t::numedges, dMapTile_t::numfaces, dBspVertex_t::point, extents_s::stmaxs, extents_s::stmins, dMapTile_t::surfedges, dBspSurface_t::texinfo, dMapTile_t::texinfo, dBspEdge_t::v, texinfo_s::vecs, VectorSet, and dMapTile_t::vertexes.

Referenced by BuildVertexNormals(), and ExportLightmaps().

void BuildFacelights ( unsigned int  facenum  ) 
void BuildLights ( void   ) 
void BuildVertexNormals ( void   ) 

Calculate per-vertex (instead of per-plane) normal vectors. This is done by finding all of the faces which share a given vertex, and calculating a weighted average of their normals.

Definition at line 665 of file lightmap.c.

References BuildFaceExtents(), curTile, dMapTile_t::faces, FacesWithVert(), i, MAX_VERT_FACES, dBspPlane_t::normal, dBspNormal_t::normal, dMapTile_t::normals, dMapTile_t::numvertexes, dBspSurface_t::planenum, dMapTile_t::planes, scale, dBspSurface_t::side, VectorAdd, VectorClear, VectorLength(), VectorNormalize(), VectorScale, and VectorSubtract.

Referenced by LightWorld(), and main().

static void CalcLightinfoExtents ( lightinfo_t l  )  [static]
static void CalcLightinfoVectors ( lightinfo_t l  )  [static]
static void CalcPoints ( lightinfo_t l,
float  sofs,
float  tofs 
) [static]

For each texture aligned grid point, back project onto the plane to get the world xyz value of the sample point.

Definition at line 222 of file lightmap.c.

References config, lightinfo_t::surfpt, lightinfo_t::texmins, lightinfo_t::texorg, lightinfo_t::texsize, and lightinfo_t::textoworld.

Referenced by BuildFacelights().

static void CalcTextureSize ( const dBspSurface_t s,
vec2_t  texsize,
int  scale 
) [static]

Calculates the texture width for the lightmap texture. This depends on the surface mins and maxs and the texture scale.

Parameters:
[in] s The surface to calculate the lightmap size for
[out] texsize The resulting texture size vector. First value is width, second value is height
[in] scale The scale (1/scale) of the lightmap texture in relation to the surface texture

Definition at line 912 of file lightmap.c.

References curTile, dMapTile_t::faces, i, extents_s::stmaxs, and extents_s::stmins.

Referenced by ExportLightmap().

static void ExportLightmap ( const char *  path,
const char *  name,
qboolean  day 
) [static]

Export all the faces for one particular lightmap (day or night).

Parameters:
path The path to write the files into
name The name of the map to export the lightmap for
day true to export the day lightmap data, false to export the night lightmap data

Definition at line 932 of file lightmap.c.

References byte, CalcTextureSize(), Com_Printf(), Com_sprintf(), curTile, dMapTile_t::faces, i, dMapTile_t::lightdata, dBspSurface_t::lightofs, MAX_QPATH, dMapTile_t::numfaces, scale, and WriteTGA24().

Referenced by ExportLightmaps().

void ExportLightmaps ( const char *  bspFileName  ) 

Export the day and night lightmap and direction data for the given map.

Note:
The bsp file must already be loaded.
Parameters:
bspFileName The path of the loaded bsp file.

Definition at line 965 of file lightmap.c.

References BuildFaceExtents(), Com_FilePath(), Com_Printf(), Com_SkipPath(), Com_StripExtension(), ExportLightmap(), MAX_QPATH, qfalse, and qtrue.

Referenced by main().

static void FacesWithVert ( int  vert,
int *  faces,
int *  nfaces 
) [static]

Populate faces with indexes of all dBspFace_t's referencing the specified edge.

Parameters:
[out] nfaces The number of dBspFace_t's referencing edge
[out] faces 
[in] vert 

Definition at line 633 of file lightmap.c.

References curTile, dMapTile_t::edges, dMapTile_t::faces, dBspSurface_t::firstedge, i, MAX_VERT_FACES, dBspSurface_t::numedges, dMapTile_t::numfaces, SURF_PHONG, texinfo_s::surfaceFlags, dMapTile_t::surfedges, Sys_Error(), dBspSurface_t::texinfo, dMapTile_t::texinfo, and dBspEdge_t::v.

Referenced by BuildVertexNormals().

void FinalLightFace ( unsigned int  facenum  ) 
static void GatherSampleLight ( vec3_t  pos,
const vec3_t  normal,
float *  sample,
float *  direction,
float  scale,
int *  headhints 
) [static]
Parameters:
[out] sample The sample color
[in] normal The light direction (normal vector)
[in] pos The point in the world that receives the light
[in] scale is the normalizer for multisampling
[in,out] headhints An array of theads for each light to optimize the tracing

Definition at line 541 of file lightmap.c.

References light_t::color, config, DotProduct, emit_point, emit_spotlight, emit_surface, GatherSampleSunlight(), light_t::origin, Sys_Error(), TR_TestLineSingleTile(), VectorMA(), VectorMix(), VectorNormalize(), and VectorSubtract.

Referenced by BuildFacelights().

static void GatherSampleSunlight ( const vec3_t  pos,
const vec3_t  normal,
float *  sample,
float *  direction,
float  scale,
int *  headhint 
) [static]

A follow-up to GatherSampleLight, simply trace along the sun normal, adding sunlight.

Definition at line 504 of file lightmap.c.

References DotProduct, sun_color, sun_intensity, sun_normal, TR_TestLineSingleTile(), VectorMA(), and VectorMix().

Referenced by GatherSampleLight().

static void NudgeSamplePosition ( const vec3_t  in,
const vec3_t  normal,
const vec3_t  center,
vec3_t  out 
) [inline, static]

Move the incoming sample position towards the surface center and along the surface normal to reduce false-positive traces.

Definition at line 611 of file lightmap.c.

References SAMPLE_NUDGE, VectorCopy, VectorMA(), VectorNormalize(), and VectorSubtract.

Referenced by BuildFacelights().

static void SampleNormal ( const lightinfo_t l,
const vec3_t  pos,
vec3_t  normal 
) [static]

For Phong-shaded samples, interpolate the vertex normals for the surface in question, weighting them according to their proximity to the sample position.

Definition at line 706 of file lightmap.c.

References curTile, dMapTile_t::edges, lightinfo_t::face, dBspSurface_t::firstedge, i, MAX_VERT_FACES, dBspNormal_t::normal, dMapTile_t::normals, dBspSurface_t::numedges, dBspVertex_t::point, dMapTile_t::surfedges, dBspEdge_t::v, VectorCopy, VectorLength(), VectorSubtract, and dMapTile_t::vertexes.

Referenced by BuildFacelights().

static qboolean TR_TestLineSingleTile ( const vec3_t  start,
const vec3_t  stop,
int *  headhint 
) [static]

Checks traces against a single-tile map, optimized for ufo2map. This trace is only for visible levels.

Parameters:
[in] start The position to start the trace.
[in] stop The position where the trace ends.
See also:
TR_TestLine
GatherSampleLight
Returns:
qfalse if not blocked

Definition at line 467 of file lightmap.c.

References curTile, i, level, LEVEL_LASTLIGHTBLOCKING, mapTiles, dMapTile_t::numtheads, mapTiles_t::numTiles, qfalse, qtrue, dMapTile_t::thead, dMapTile_t::theadlevel, and TR_TestLine_r().

Referenced by GatherSampleLight(), and GatherSampleSunlight().

static void WriteTGA24 ( const char *  filename,
const byte data,
int  width,
int  height,
int  offset 
) [static]

Definition at line 870 of file lightmap.c.

References byte, FILE_WRITE, FS_CloseFile(), FS_OpenFile(), FS_Write(), i, Mem_Alloc, Mem_Free, and Sys_Error().

Referenced by ExportLightmap().


Variable Documentation

extents_t face_extents[MAX_MAP_FACES] [static]

Definition at line 61 of file lightmap.c.

vec3_t face_offset[MAX_MAP_FACES]

for rotating bmodels

Definition at line 34 of file lightmap.c.

Referenced by BuildFacelights(), and BuildPatches().

facelight_t facelight[LIGHTMAP_MAX][MAX_MAP_FACES] [static]

Definition at line 262 of file lightmap.c.

light_t* lights[LIGHTMAP_MAX] [static]

Definition at line 283 of file lightmap.c.

const vec3_t luminosity = {0.2125, 0.7154, 0.0721} [static]

Definition at line 982 of file lightmap.c.

Referenced by FinalLightFace(), and R_FilterTexture().

int numlights[LIGHTMAP_MAX] [static]

Definition at line 284 of file lightmap.c.

Referenced by BuildFacelights(), and BuildLights().

const float sampleofs[MAX_SAMPLES][2] [static]
Initial value:
 {
    {0.0, 0.0}, {-0.125, -0.125}, {0.125, -0.125}, {0.125, 0.125}, {-0.125, 0.125}
}

Definition at line 736 of file lightmap.c.

Referenced by BuildFacelights().


Generated by  doxygen 1.6.2