remove proojectedmip stuff for now

This commit is contained in:
Eric Wasylishen 2015-05-15 20:59:45 -06:00
parent a640ff4cb1
commit b4f9f23051
3 changed files with 1 additions and 340 deletions

View File

@ -60,8 +60,6 @@ typedef struct entity_s {
float spotfalloff;
float spotangle2;
float spotfalloff2;
miptex_t *projectedmip; /*projected texture*/
float projectionmatrix[16]; /*matrix used to project the specified texture. already contains origin.*/
lightsample_t light;
light_formula_t formula;

View File

@ -603,233 +603,6 @@ JitterEntities()
}
}
void Matrix4x4_CM_Projection_Inf(float *proj, float fovx, float fovy, float neard)
{
float xmin, xmax, ymin, ymax;
float nudge = 1;
//proj
ymax = neard * tan( fovy * M_PI / 360.0 );
ymin = -ymax;
if (fovx == fovy)
{
xmax = ymax;
xmin = ymin;
}
else
{
xmax = neard * tan( fovx * M_PI / 360.0 );
xmin = -xmax;
}
proj[0] = (2*neard) / (xmax - xmin);
proj[4] = 0;
proj[8] = (xmax + xmin) / (xmax - xmin);
proj[12] = 0;
proj[1] = 0;
proj[5] = (2*neard) / (ymax - ymin);
proj[9] = (ymax + ymin) / (ymax - ymin);
proj[13] = 0;
proj[2] = 0;
proj[6] = 0;
proj[10] = -1 * ((float)(1<<21)/(1<<22));
proj[14] = -2*neard * nudge;
proj[3] = 0;
proj[7] = 0;
proj[11] = -1;
proj[15] = 0;
}
float *Matrix4x4_CM_NewRotation(float ret[16], float a, float x, float y, float z)
{
float c = cos(a* M_PI / 180.0);
float s = sin(a* M_PI / 180.0);
ret[0] = x*x*(1-c)+c;
ret[4] = x*y*(1-c)-z*s;
ret[8] = x*z*(1-c)+y*s;
ret[12] = 0;
ret[1] = y*x*(1-c)+z*s;
ret[5] = y*y*(1-c)+c;
ret[9] = y*z*(1-c)-x*s;
ret[13] = 0;
ret[2] = x*z*(1-c)-y*s;
ret[6] = y*z*(1-c)+x*s;
ret[10] = z*z*(1-c)+c;
ret[14] = 0;
ret[3] = 0;
ret[7] = 0;
ret[11] = 0;
ret[15] = 1;
return ret;
}
float *Matrix4x4_CM_NewTranslation(float ret[16], float x, float y, float z)
{
ret[0] = 1;
ret[4] = 0;
ret[8] = 0;
ret[12] = x;
ret[1] = 0;
ret[5] = 1;
ret[9] = 0;
ret[13] = y;
ret[2] = 0;
ret[6] = 0;
ret[10] = 1;
ret[14] = z;
ret[3] = 0;
ret[7] = 0;
ret[11] = 0;
ret[15] = 1;
return ret;
}
void Matrix4_Multiply(const float *a, const float *b, float *out)
{
out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
out[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
out[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
out[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
out[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
out[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
out[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
out[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
out[14] = a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15];
out[15] = a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15];
}
void Matrix4x4_CM_ModelViewMatrix(float *modelview, const vec3_t viewangles, const vec3_t vieworg)
{
float t2[16];
float tempmat[16];
//load identity.
memset(modelview, 0, sizeof(*modelview)*16);
#if FULLYGL
modelview[0] = 1;
modelview[5] = 1;
modelview[10] = 1;
modelview[15] = 1;
Matrix4_Multiply(modelview, Matrix4_CM_NewRotation(-90, 1, 0, 0), tempmat); // put Z going up
Matrix4_Multiply(tempmat, Matrix4_CM_NewRotation(90, 0, 0, 1), modelview); // put Z going up
#else
//use this lame wierd and crazy identity matrix..
modelview[2] = -1;
modelview[4] = -1;
modelview[9] = 1;
modelview[15] = 1;
#endif
//figure out the current modelview matrix
//I would if some of these, but then I'd still need a couple of copys
Matrix4_Multiply(modelview, Matrix4x4_CM_NewRotation(t2, -viewangles[2], 1, 0, 0), tempmat);
Matrix4_Multiply(tempmat, Matrix4x4_CM_NewRotation(t2, -viewangles[0], 0, 1, 0), modelview);
Matrix4_Multiply(modelview, Matrix4x4_CM_NewRotation(t2, -viewangles[1], 0, 0, 1), tempmat);
Matrix4_Multiply(tempmat, Matrix4x4_CM_NewTranslation(t2, -vieworg[0], -vieworg[1], -vieworg[2]), modelview); // put Z going up
}
void Matrix4x4_CM_MakeModelViewProj (const vec3_t viewangles, const vec3_t vieworg, float fovx, float fovy, float *modelviewproj)
{
float modelview[16];
float proj[16];
Matrix4x4_CM_ModelViewMatrix(modelview, viewangles, vieworg);
Matrix4x4_CM_Projection_Inf(proj, fovx, fovy, 4);
Matrix4_Multiply(proj, modelview, modelviewproj);
}
float CalcFov (float fov_x, float width, float height)
{
float a;
float x;
if (fov_x < 1 || fov_x > 179)
Error ("Bad fov: %f", fov_x);
x = fov_x/360*M_PI;
x = tan(x);
x = width/x;
a = atan (height/x);
a = a*360/M_PI;
return a;
}
#if 0
/*
scans the world's textures for window*
*/
static void SetupProjections(const bsp2_t *bsp)
{
dmiptexlump_t *miplump = bsp->dtexdata.header;
miptex_t *miptex;
texinfo_t *texinfo;
int texnum;
int surfnum;
/*outer loop finds the textures*/
for (texnum = 0; texnum< miplump->nummiptex; texnum++)
{
miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[texnum]);
if (strncmp(miptex->name, "window", 6))
continue;
/*inner loop finds surfaces with that texture*/
for (surfnum = 0; surfnum < bsp->numfaces; surfnum++)
{
entity_t *light;
bsp2_dface_t *fa = bsp->dfaces + surfnum;
texinfo = bsp->texinfo + fa->texinfo;
if (texinfo->miptex == texnum)
{
/*okay, this is a window*/
vec3_t midpoint = {0,0,0};
vec3_t ang;
int i;
for (i = 0; i < fa->numedges; i++)
{
int32_t edgenum = bsp->dsurfedges[fa->firstedge + i];
uint32_t vnum = bsp->dedges[edgenum<0?-edgenum:edgenum].v[edgenum<0];
VectorAdd(midpoint, bsp->dvertexes[vnum].point, midpoint);
}
VectorScale(midpoint, 1.0/fa->numedges, midpoint);
light = malloc(sizeof(*light));
memset(light, 0, sizeof(*light));
light->generated = true;
light->light.light = 600;
Entities_Insert(light);
VectorCopy(midpoint, light->origin);
light->projectedmip = miptex;
ang[0] = 20;
ang[1] = 0;
ang[2] = 0;
if (miptex->width > miptex->height)
Matrix4x4_CM_MakeModelViewProj (ang, light->origin, 90, CalcFov(90, miptex->width, miptex->height), light->projectionmatrix);
else
Matrix4x4_CM_MakeModelViewProj (ang, light->origin, CalcFov(90, miptex->height, miptex->width), 90, light->projectionmatrix);
CheckEntityFields(light);
}
}
}
}
#endif
/*
* ==================
* LoadEntities
@ -974,21 +747,6 @@ LoadEntities(const bsp2_t *bsp)
dirty = true;
}
}
else if (!strcmp(key, "_project"))
{
#if 0
scan_vec3(sunlight2.color, com_token, key);
light->projectedmip = miptex;
ang[0] = 20;
ang[1] = 0;
ang[2] = 0;
if (miptex->width > miptex->height)
Matrix4x4_CM_MakeModelViewProj (ang, light->origin, 90, CalcFov(90, miptex->width, miptex->height), light->projectionmatrix);
else
Matrix4x4_CM_MakeModelViewProj (ang, light->origin, CalcFov(90, miptex->height, miptex->width), 90, light->projectionmatrix);
#endif
}
else if (!strcmp(key, "_sunlight_penumbra")) {
sun_deviance = atof(com_token);
}
@ -1118,9 +876,6 @@ LoadEntities(const bsp2_t *bsp)
SetupSpotlights();
SetupSuns();
SetupSkyDome();
#if 0
SetupProjections(bsp);
#endif
}
const char *

View File

@ -826,89 +826,6 @@ Dirt_GetScaleFactor(vec_t occlusion, const entity_t *entity, const modelinfo_t *
return 1.0f - outDirt;
}
static byte thepalette[768] =
{
0,0,0,15,15,15,31,31,31,47,47,47,63,63,63,75,75,75,91,91,91,107,107,107,123,123,123,139,139,139,155,155,155,171,171,171,187,187,187,203,203,203,219,219,219,235,235,235,15,11,7,23,15,11,31,23,11,39,27,15,47,35,19,55,43,23,63,47,23,75,55,27,83,59,27,91,67,31,99,75,31,107,83,31,115,87,31,123,95,35,131,103,35,143,111,35,11,11,15,19,19,27,27,27,39,39,39,51,47,47,63,55,55,75,63,63,87,71,71,103,79,79,115,91,91,127,99,99,
139,107,107,151,115,115,163,123,123,175,131,131,187,139,139,203,0,0,0,7,7,0,11,11,0,19,19,0,27,27,0,35,35,0,43,43,7,47,47,7,55,55,7,63,63,7,71,71,7,75,75,11,83,83,11,91,91,11,99,99,11,107,107,15,7,0,0,15,0,0,23,0,0,31,0,0,39,0,0,47,0,0,55,0,0,63,0,0,71,0,0,79,0,0,87,0,0,95,0,0,103,0,0,111,0,0,119,0,0,127,0,0,19,19,0,27,27,0,35,35,0,47,43,0,55,47,0,67,
55,0,75,59,7,87,67,7,95,71,7,107,75,11,119,83,15,131,87,19,139,91,19,151,95,27,163,99,31,175,103,35,35,19,7,47,23,11,59,31,15,75,35,19,87,43,23,99,47,31,115,55,35,127,59,43,143,67,51,159,79,51,175,99,47,191,119,47,207,143,43,223,171,39,239,203,31,255,243,27,11,7,0,27,19,0,43,35,15,55,43,19,71,51,27,83,55,35,99,63,43,111,71,51,127,83,63,139,95,71,155,107,83,167,123,95,183,135,107,195,147,123,211,163,139,227,179,151,
171,139,163,159,127,151,147,115,135,139,103,123,127,91,111,119,83,99,107,75,87,95,63,75,87,55,67,75,47,55,67,39,47,55,31,35,43,23,27,35,19,19,23,11,11,15,7,7,187,115,159,175,107,143,163,95,131,151,87,119,139,79,107,127,75,95,115,67,83,107,59,75,95,51,63,83,43,55,71,35,43,59,31,35,47,23,27,35,19,19,23,11,11,15,7,7,219,195,187,203,179,167,191,163,155,175,151,139,163,135,123,151,123,111,135,111,95,123,99,83,107,87,71,95,75,59,83,63,
51,67,51,39,55,43,31,39,31,23,27,19,15,15,11,7,111,131,123,103,123,111,95,115,103,87,107,95,79,99,87,71,91,79,63,83,71,55,75,63,47,67,55,43,59,47,35,51,39,31,43,31,23,35,23,15,27,19,11,19,11,7,11,7,255,243,27,239,223,23,219,203,19,203,183,15,187,167,15,171,151,11,155,131,7,139,115,7,123,99,7,107,83,0,91,71,0,75,55,0,59,43,0,43,31,0,27,15,0,11,7,0,0,0,255,11,11,239,19,19,223,27,27,207,35,35,191,43,
43,175,47,47,159,47,47,143,47,47,127,47,47,111,47,47,95,43,43,79,35,35,63,27,27,47,19,19,31,11,11,15,43,0,0,59,0,0,75,7,0,95,7,0,111,15,0,127,23,7,147,31,7,163,39,11,183,51,15,195,75,27,207,99,43,219,127,59,227,151,79,231,171,95,239,191,119,247,211,139,167,123,59,183,155,55,199,195,55,231,227,87,127,191,255,171,231,255,215,255,255,103,0,0,139,0,0,179,0,0,215,0,0,255,0,0,255,243,147,255,247,199,255,255,255,159,91,83
};
static void Matrix4x4_CM_Transform4(const float *matrix, const float *vector, float *product)
{
product[0] = matrix[0]*vector[0] + matrix[4]*vector[1] + matrix[8]*vector[2] + matrix[12]*vector[3];
product[1] = matrix[1]*vector[0] + matrix[5]*vector[1] + matrix[9]*vector[2] + matrix[13]*vector[3];
product[2] = matrix[2]*vector[0] + matrix[6]*vector[1] + matrix[10]*vector[2] + matrix[14]*vector[3];
product[3] = matrix[3]*vector[0] + matrix[7]*vector[1] + matrix[11]*vector[2] + matrix[15]*vector[3];
}
static qboolean Matrix4x4_CM_Project (const vec3_t in, vec3_t out, const float *modelviewproj)
{
qboolean result = true;
float v[4], tempv[4];
tempv[0] = in[0];
tempv[1] = in[1];
tempv[2] = in[2];
tempv[3] = 1;
Matrix4x4_CM_Transform4(modelviewproj, tempv, v);
v[0] /= v[3];
v[1] /= v[3];
if (v[2] < 0)
result = false; //too close to the view
v[2] /= v[3];
out[0] = (1+v[0])/2;
out[1] = (1+v[1])/2;
out[2] = (1+v[2])/2;
if (out[2] > 1)
result = false; //beyond far clip plane
return result;
}
static void LightFace_SampleMipTex(miptex_t *tex, const float *projectionmatrix, const vec3_t point, float *result)
{
//okay, yes, this is weird, yes we're using a vec3_t for a coord...
//this is because we're treating it like a cubemap. why? no idea.
float sfrac, tfrac, weight[4];
int sbase, tbase;
byte *data = (byte*)tex + tex->offsets[0], pi[4];
vec3_t coord;
if (!Matrix4x4_CM_Project(point, coord, projectionmatrix) || coord[0] <= 0 || coord[0] >= 1 || coord[1] <= 0 || coord[1] >= 1)
VectorSet(result, 0, 0, 0);
else
{
sfrac = (coord[0]) * tex->width;
sbase = sfrac;
sfrac -= sbase;
tfrac = (1-coord[1]) * tex->height;
tbase = tfrac;
tfrac -= tbase;
pi[0] = data[((sbase+0)%tex->width) + (tex->width*((tbase+0)%tex->height))]; weight[0] = (1-sfrac)*(1-tfrac);
pi[1] = data[((sbase+1)%tex->width) + (tex->width*((tbase+0)%tex->height))]; weight[1] = (sfrac)*(1-tfrac);
pi[2] = data[((sbase+0)%tex->width) + (tex->width*((tbase+1)%tex->height))]; weight[2] = (1-sfrac)*(tfrac);
pi[3] = data[((sbase+1)%tex->width) + (tex->width*((tbase+1)%tex->height))]; weight[3] = (sfrac)*(tfrac);
VectorSet(result, 0, 0, 0);
result[0] = weight[0] * thepalette[pi[0]*3+0];
result[1] = weight[0] * thepalette[pi[0]*3+1];
result[2] = weight[0] * thepalette[pi[0]*3+2];
result[0] += weight[1] * thepalette[pi[1]*3+0];
result[1] += weight[1] * thepalette[pi[1]*3+1];
result[2] += weight[1] * thepalette[pi[1]*3+2];
result[0] += weight[2] * thepalette[pi[2]*3+0];
result[1] += weight[2] * thepalette[pi[2]*3+1];
result[2] += weight[2] * thepalette[pi[2]*3+2];
result[0] += weight[3] * thepalette[pi[3]*3+0];
result[1] += weight[3] * thepalette[pi[3]*3+1];
result[2] += weight[3] * thepalette[pi[3]*3+2];
VectorScale(result, 2, result);
}
}
/*
* ================
@ -980,16 +897,7 @@ LightFace_Entity(const entity_t *entity, const lightsample_t *light,
add = GetLightValue(light, entity, dist) * angle * spotscale;
add *= Dirt_GetScaleFactor(lightsurf->occlusion[i], entity, modelinfo);
if (entity->projectedmip)
{
vec3_t col;
VectorCopy(light->color, col);
VectorScale(ray, 255, col);
LightFace_SampleMipTex(entity->projectedmip, entity->projectionmatrix, surfpoint, col);
Light_Add(sample, add, col, ray);
}
else
Light_Add(sample, add, light->color, ray);
Light_Add(sample, add, light->color, ray);
/* Check if we really hit, ignore tiny lights */
/* ericw -- never ignore generated lights, which can be tiny and need