light: define a plane_t structure and use for lightinfo_t
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
fda3b230f9
commit
63393eee8e
|
|
@ -137,9 +137,14 @@ Solve3(const pmatrix3_t *matrix, const vec3_t rhs, vec3_t out)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pmatrix3_t transform;
|
pmatrix3_t transform;
|
||||||
const texinfo_t *texinfo;
|
const texinfo_t *texinfo;
|
||||||
vec_t facedist;
|
vec_t planedist;
|
||||||
} texorg_t;
|
} texorg_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
vec3_t normal;
|
||||||
|
vec_t dist;
|
||||||
|
} plane_t;
|
||||||
|
|
||||||
/* Allow space for 4x4 oversampling */
|
/* Allow space for 4x4 oversampling */
|
||||||
#define SINGLEMAP (18*18*4*4)
|
#define SINGLEMAP (18*18*4*4)
|
||||||
|
|
||||||
|
|
@ -149,8 +154,7 @@ typedef struct {
|
||||||
vec_t exactmid[2];
|
vec_t exactmid[2];
|
||||||
int texmins[2], texsize[2];
|
int texmins[2], texsize[2];
|
||||||
|
|
||||||
vec_t facedist;
|
plane_t plane;
|
||||||
vec3_t facenormal;
|
|
||||||
int numsurfpt;
|
int numsurfpt;
|
||||||
vec3_t surfpt[SINGLEMAP];
|
vec3_t surfpt[SINGLEMAP];
|
||||||
|
|
||||||
|
|
@ -200,7 +204,7 @@ TexCoordToWorld(vec_t s, vec_t t, const texorg_t *texorg, vec3_t world)
|
||||||
|
|
||||||
rhs[0] = s - texorg->texinfo->vecs[0][3];
|
rhs[0] = s - texorg->texinfo->vecs[0][3];
|
||||||
rhs[1] = t - texorg->texinfo->vecs[1][3];
|
rhs[1] = t - texorg->texinfo->vecs[1][3];
|
||||||
rhs[2] = texorg->facedist + 1; /* one "unit" in front of surface */
|
rhs[2] = texorg->planedist + 1; /* one "unit" in front of surface */
|
||||||
|
|
||||||
Solve3(&texorg->transform, rhs, world);
|
Solve3(&texorg->transform, rhs, world);
|
||||||
}
|
}
|
||||||
|
|
@ -464,7 +468,7 @@ SingleLightFace(const entity_t *light, lightinfo_t *l, const vec3_t colors)
|
||||||
vec_t newlightmap[SINGLEMAP];
|
vec_t newlightmap[SINGLEMAP];
|
||||||
vec3_t newcolormap[SINGLEMAP];
|
vec3_t newcolormap[SINGLEMAP];
|
||||||
|
|
||||||
dist = DotProduct(light->origin, l->facenormal) - l->facedist;
|
dist = DotProduct(light->origin, l->plane.normal) - l->plane.dist;
|
||||||
|
|
||||||
/* don't bother with lights behind the surface */
|
/* don't bother with lights behind the surface */
|
||||||
if (dist < 0)
|
if (dist < 0)
|
||||||
|
|
@ -515,7 +519,7 @@ SingleLightFace(const entity_t *light, lightinfo_t *l, const vec3_t colors)
|
||||||
|
|
||||||
/* Check spotlight cone */
|
/* Check spotlight cone */
|
||||||
VectorScale(ray, 1.0 / dist, ray);
|
VectorScale(ray, 1.0 / dist, ray);
|
||||||
angle = DotProduct(ray, l->facenormal);
|
angle = DotProduct(ray, l->plane.normal);
|
||||||
spotscale = 1;
|
spotscale = 1;
|
||||||
if (light->spotlight) {
|
if (light->spotlight) {
|
||||||
vec_t falloff = DotProduct(light->spotvec, ray);
|
vec_t falloff = DotProduct(light->spotvec, ray);
|
||||||
|
|
@ -580,7 +584,7 @@ SkyLightFace(lightinfo_t *l, const vec3_t colors)
|
||||||
vec3_t *colormap;
|
vec3_t *colormap;
|
||||||
|
|
||||||
/* Don't bother if surface facing away from sun */
|
/* Don't bother if surface facing away from sun */
|
||||||
if (DotProduct(sunvec, l->facenormal) < -ANGLE_EPSILON)
|
if (DotProduct(sunvec, l->plane.normal) < -ANGLE_EPSILON)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* if sunlight is set, use a style 0 light map */
|
/* if sunlight is set, use a style 0 light map */
|
||||||
|
|
@ -599,7 +603,7 @@ SkyLightFace(lightinfo_t *l, const vec3_t colors)
|
||||||
/* Check each point... */
|
/* Check each point... */
|
||||||
VectorCopy(sunvec, incoming);
|
VectorCopy(sunvec, incoming);
|
||||||
VectorNormalize(incoming);
|
VectorNormalize(incoming);
|
||||||
angle = DotProduct(incoming, l->facenormal);
|
angle = DotProduct(incoming, l->plane.normal);
|
||||||
angle = (1.0 - scalecos) + scalecos * angle;
|
angle = (1.0 - scalecos) + scalecos * angle;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -610,7 +614,7 @@ SkyLightFace(lightinfo_t *l, const vec3_t colors)
|
||||||
vec3_t sun_vectors[5];
|
vec3_t sun_vectors[5];
|
||||||
|
|
||||||
// Try to hit parallel surfaces?
|
// Try to hit parallel surfaces?
|
||||||
oldangle = DotProduct(incoming, l->facenormal);
|
oldangle = DotProduct(incoming, l->plane.normal);
|
||||||
if (oldangle < ANGLE_EPSILON) {
|
if (oldangle < ANGLE_EPSILON) {
|
||||||
printf("real small angle! (%f)\n", oldangle);
|
printf("real small angle! (%f)\n", oldangle);
|
||||||
angle = (1.0 - scalecos) + scalecos * ANGLE_EPSILON;
|
angle = (1.0 - scalecos) + scalecos * ANGLE_EPSILON;
|
||||||
|
|
@ -826,6 +830,7 @@ LightFace(int surfnum, const modelinfo_t *modelinfo)
|
||||||
{
|
{
|
||||||
const entity_t *entity;
|
const entity_t *entity;
|
||||||
dface_t *face;
|
dface_t *face;
|
||||||
|
plane_t *plane;
|
||||||
lightinfo_t l;
|
lightinfo_t l;
|
||||||
int s, t;
|
int s, t;
|
||||||
int i, j, k, c;
|
int i, j, k, c;
|
||||||
|
|
@ -842,7 +847,7 @@ LightFace(int surfnum, const modelinfo_t *modelinfo)
|
||||||
vec3_t colors = { 0, 0, 0 };
|
vec3_t colors = { 0, 0, 0 };
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
vec3_t point;
|
vec3_t planepoint;
|
||||||
|
|
||||||
texorg_t texorg;
|
texorg_t texorg;
|
||||||
|
|
||||||
|
|
@ -859,21 +864,23 @@ LightFace(int surfnum, const modelinfo_t *modelinfo)
|
||||||
memset(&l, 0, sizeof(l));
|
memset(&l, 0, sizeof(l));
|
||||||
l.modelinfo = modelinfo;
|
l.modelinfo = modelinfo;
|
||||||
|
|
||||||
/* rotate plane */
|
/* Offset the plane according to the model offset */
|
||||||
VectorCopy(dplanes[face->planenum].normal, l.facenormal);
|
plane = &l.plane;
|
||||||
l.facedist = dplanes[face->planenum].dist;
|
VectorCopy(dplanes[face->planenum].normal, plane->normal);
|
||||||
VectorScale(l.facenormal, l.facedist, point);
|
plane->dist = dplanes[face->planenum].dist;
|
||||||
VectorAdd(point, modelinfo->offset, point);
|
VectorScale(plane->normal, plane->dist, planepoint);
|
||||||
l.facedist = DotProduct(point, l.facenormal);
|
VectorAdd(planepoint, modelinfo->offset, planepoint);
|
||||||
|
plane->dist = DotProduct(plane->normal, planepoint);
|
||||||
|
|
||||||
|
/* flip if needed */
|
||||||
if (face->side) {
|
if (face->side) {
|
||||||
VectorSubtract(vec3_origin, l.facenormal, l.facenormal);
|
VectorSubtract(vec3_origin, plane->normal, plane->normal);
|
||||||
l.facedist = -l.facedist;
|
plane->dist = -plane->dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateFaceTransform(face, &texorg.transform);
|
CreateFaceTransform(face, &texorg.transform);
|
||||||
texorg.texinfo = &texinfo[face->texinfo];
|
texorg.texinfo = &texinfo[face->texinfo];
|
||||||
texorg.facedist = l.facedist;
|
texorg.planedist = plane->dist;
|
||||||
|
|
||||||
CalcFaceExtents(face, modelinfo->offset, &l);
|
CalcFaceExtents(face, modelinfo->offset, &l);
|
||||||
CalcPoints(modelinfo->model, &texorg, &l);
|
CalcPoints(modelinfo->model, &texorg, &l);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue