rtexture_t *r_texture_notexture;
rtexture_t *r_texture_whitecube;
rtexture_t *r_texture_normalizationcube;
+rtexture_t *r_texture_detailtextures[NUM_DETAILTEXTURES];
+rtexture_t *r_texture_distorttexture[64];
void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
{
}
}
-void gl_main_start(void)
+static void R_BuildDetailTextures (void)
{
- int x, y, side;
- vec3_t v;
- vec_t s, t, intensity;
- qbyte pix[16][16][4];
-#define NORMSIZE 64
- qbyte data[6*NORMSIZE*NORMSIZE*4];
- r_main_texturepool = R_AllocTexturePool();
- r_bloom_texture_screen = NULL;
- r_bloom_texture_bloom = NULL;
+ int i, x, y, light;
+ float vc[3], vx[3], vy[3], vn[3], lightdir[3];
+#define DETAILRESOLUTION 256
+ qbyte data[DETAILRESOLUTION][DETAILRESOLUTION][4], noise[DETAILRESOLUTION][DETAILRESOLUTION];
+ lightdir[0] = 0.5;
+ lightdir[1] = 1;
+ lightdir[2] = -0.25;
+ VectorNormalize(lightdir);
+ for (i = 0;i < NUM_DETAILTEXTURES;i++)
+ {
+ fractalnoise(&noise[0][0], DETAILRESOLUTION, DETAILRESOLUTION >> 4);
+ for (y = 0;y < DETAILRESOLUTION;y++)
+ {
+ for (x = 0;x < DETAILRESOLUTION;x++)
+ {
+ vc[0] = x;
+ vc[1] = y;
+ vc[2] = noise[y][x] * (1.0f / 32.0f);
+ vx[0] = x + 1;
+ vx[1] = y;
+ vx[2] = noise[y][(x + 1) % DETAILRESOLUTION] * (1.0f / 32.0f);
+ vy[0] = x;
+ vy[1] = y + 1;
+ vy[2] = noise[(y + 1) % DETAILRESOLUTION][x] * (1.0f / 32.0f);
+ VectorSubtract(vx, vc, vx);
+ VectorSubtract(vy, vc, vy);
+ CrossProduct(vx, vy, vn);
+ VectorNormalize(vn);
+ light = 128 - DotProduct(vn, lightdir) * 128;
+ light = bound(0, light, 255);
+ data[y][x][0] = data[y][x][1] = data[y][x][2] = light;
+ data[y][x][3] = 255;
+ }
+ }
+ r_texture_detailtextures[i] = R_LoadTexture2D(r_main_texturepool, va("detailtexture%i", i), DETAILRESOLUTION, DETAILRESOLUTION, &data[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP | TEXF_PRECACHE, NULL);
+ }
+}
+
+static qbyte R_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph)
+{
+ int m = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) +
+ ((2 * (y0 - y1) + y2 - y3) * morph * morph) +
+ ((y2 - y0) * morph) +
+ (y1));
+ return (qbyte)bound(0, m, 255);
+}
+
+static void R_BuildDistortTexture (void)
+{
+ int x, y, i, j;
+#define DISTORTRESOLUTION 32
+ qbyte data[5][DISTORTRESOLUTION][DISTORTRESOLUTION][2];
+
+ for (i=0; i<4; i++)
+ {
+ for (y=0; y<DISTORTRESOLUTION; y++)
+ {
+ for (x=0; x<DISTORTRESOLUTION; x++)
+ {
+ data[i][y][x][0] = rand () & 255;
+ data[i][y][x][1] = rand () & 255;
+ }
+ }
+ }
+
+ for (i=0; i<4; i++)
+ {
+ for (j=0; j<16; j++)
+ {
+ r_texture_distorttexture[i*16+j] = NULL;
+ if (gl_textureshader)
+ {
+ for (y=0; y<DISTORTRESOLUTION; y++)
+ {
+ for (x=0; x<DISTORTRESOLUTION; x++)
+ {
+ data[4][y][x][0] = R_MorphDistortTexture (data[(i-1)&3][y][x][0], data[i][y][x][0], data[(i+1)&3][y][x][0], data[(i+2)&3][y][x][0], 0.0625*j);
+ data[4][y][x][1] = R_MorphDistortTexture (data[(i-1)&3][y][x][1], data[i][y][x][1], data[(i+1)&3][y][x][1], data[(i+2)&3][y][x][1], 0.0625*j);
+ }
+ }
+ r_texture_distorttexture[i*16+j] = R_LoadTexture2D(r_main_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
+ }
+ }
+ }
+}
+
+static void R_BuildBlankTextures(void)
+{
+ qbyte data[4];
data[0] = 128; // normal X
data[1] = 128; // normal Y
data[2] = 255; // normal Z
data[2] = 0;
data[3] = 255;
r_texture_black = R_LoadTexture2D(r_main_texturepool, "blankblack", 1, 1, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
+}
+
+static void R_BuildNoTexture(void)
+{
+ int x, y;
+ qbyte pix[16][16][4];
// this makes a light grey/dark grey checkerboard texture
for (y = 0;y < 16;y++)
{
}
}
r_texture_notexture = R_LoadTexture2D(r_main_texturepool, "notexture", 16, 16, &pix[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP, NULL);
- if (gl_texturecubemap)
+}
+
+static void R_BuildWhiteCube(void)
+{
+ qbyte data[6*1*1*4];
+ data[ 0] = 255;data[ 1] = 255;data[ 2] = 255;data[ 3] = 255;
+ data[ 4] = 255;data[ 5] = 255;data[ 6] = 255;data[ 7] = 255;
+ data[ 8] = 255;data[ 9] = 255;data[10] = 255;data[11] = 255;
+ data[12] = 255;data[13] = 255;data[14] = 255;data[15] = 255;
+ data[16] = 255;data[17] = 255;data[18] = 255;data[19] = 255;
+ data[20] = 255;data[21] = 255;data[22] = 255;data[23] = 255;
+ r_texture_whitecube = R_LoadTextureCubeMap(r_main_texturepool, "whitecube", 1, data, TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL);
+}
+
+static void R_BuildNormalizationCube(void)
+{
+ int x, y, side;
+ vec3_t v;
+ vec_t s, t, intensity;
+#define NORMSIZE 64
+ qbyte data[6][NORMSIZE][NORMSIZE][4];
+ for (side = 0;side < 6;side++)
{
- data[ 0] = 255;data[ 1] = 255;data[ 2] = 255;data[ 3] = 255;
- data[ 4] = 255;data[ 5] = 255;data[ 6] = 255;data[ 7] = 255;
- data[ 8] = 255;data[ 9] = 255;data[10] = 255;data[11] = 255;
- data[12] = 255;data[13] = 255;data[14] = 255;data[15] = 255;
- data[16] = 255;data[17] = 255;data[18] = 255;data[19] = 255;
- data[20] = 255;data[21] = 255;data[22] = 255;data[23] = 255;
- r_texture_whitecube = R_LoadTextureCubeMap(r_main_texturepool, "whitecube", 1, data, TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL);
- for (side = 0;side < 6;side++)
+ for (y = 0;y < NORMSIZE;y++)
{
- for (y = 0;y < NORMSIZE;y++)
+ for (x = 0;x < NORMSIZE;x++)
{
- for (x = 0;x < NORMSIZE;x++)
+ s = (x + 0.5f) * (2.0f / NORMSIZE) - 1.0f;
+ t = (y + 0.5f) * (2.0f / NORMSIZE) - 1.0f;
+ switch(side)
{
- s = (x + 0.5f) * (2.0f / NORMSIZE) - 1.0f;
- t = (y + 0.5f) * (2.0f / NORMSIZE) - 1.0f;
- switch(side)
- {
- case 0:
- v[0] = 1;
- v[1] = -t;
- v[2] = -s;
- break;
- case 1:
- v[0] = -1;
- v[1] = -t;
- v[2] = s;
- break;
- case 2:
- v[0] = s;
- v[1] = 1;
- v[2] = t;
- break;
- case 3:
- v[0] = s;
- v[1] = -1;
- v[2] = -t;
- break;
- case 4:
- v[0] = s;
- v[1] = -t;
- v[2] = 1;
- break;
- case 5:
- v[0] = -s;
- v[1] = -t;
- v[2] = -1;
- break;
- }
- intensity = 127.0f / sqrt(DotProduct(v, v));
- data[((side*NORMSIZE+y)*NORMSIZE+x)*4+0] = 128.0f + intensity * v[0];
- data[((side*NORMSIZE+y)*NORMSIZE+x)*4+1] = 128.0f + intensity * v[1];
- data[((side*NORMSIZE+y)*NORMSIZE+x)*4+2] = 128.0f + intensity * v[2];
- data[((side*NORMSIZE+y)*NORMSIZE+x)*4+3] = 255;
+ case 0:
+ v[0] = 1;
+ v[1] = -t;
+ v[2] = -s;
+ break;
+ case 1:
+ v[0] = -1;
+ v[1] = -t;
+ v[2] = s;
+ break;
+ case 2:
+ v[0] = s;
+ v[1] = 1;
+ v[2] = t;
+ break;
+ case 3:
+ v[0] = s;
+ v[1] = -1;
+ v[2] = -t;
+ break;
+ case 4:
+ v[0] = s;
+ v[1] = -t;
+ v[2] = 1;
+ break;
+ case 5:
+ v[0] = -s;
+ v[1] = -t;
+ v[2] = -1;
+ break;
}
+ intensity = 127.0f / sqrt(DotProduct(v, v));
+ data[side][y][x][0] = 128.0f + intensity * v[0];
+ data[side][y][x][1] = 128.0f + intensity * v[1];
+ data[side][y][x][2] = 128.0f + intensity * v[2];
+ data[side][y][x][3] = 255;
}
}
- r_texture_normalizationcube = R_LoadTextureCubeMap(r_main_texturepool, "normalcube", NORMSIZE, data, TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL);
+ }
+ r_texture_normalizationcube = R_LoadTextureCubeMap(r_main_texturepool, "normalcube", NORMSIZE, &data[0][0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL);
+}
+
+void gl_main_start(void)
+{
+ r_main_texturepool = R_AllocTexturePool();
+ r_bloom_texture_screen = NULL;
+ r_bloom_texture_bloom = NULL;
+ R_BuildBlankTextures();
+ R_BuildNoTexture();
+ R_BuildDetailTextures();
+ R_BuildDistortTexture();
+ if (gl_texturecubemap)
+ {
+ R_BuildWhiteCube();
+ R_BuildNormalizationCube();
}
}
// NVIDIA Geforce3 distortion texture shader on water
float args[4] = {0.05f,0,0,0.04f};
memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
+ m.tex[0] = R_GetTexture(r_texture_distorttexture[(int)(r_refdef.time * 16)&63]);
m.tex[1] = R_GetTexture(texture->skin.base);
m.texcombinergb[0] = GL_REPLACE;
m.texcombinergb[1] = GL_REPLACE;
#include "wad.h"
-qbyte mod_q1bsp_novis[(MAX_MAP_LEAFS + 7)/ 8];
-
//cvar_t r_subdivide_size = {CVAR_SAVE, "r_subdivide_size", "128"};
cvar_t halflifebsp = {0, "halflifebsp", "0"};
cvar_t r_novis = {0, "r_novis", "0"};
cvar_t mod_q3bsp_optimizedtraceline = {0, "mod_q3bsp_optimizedtraceline", "1"};
cvar_t mod_q3bsp_debugtracebrush = {0, "mod_q3bsp_debugtracebrush", "0"};
-static void Mod_Q1BSP_Collision_Init (void);
void Mod_BrushInit(void)
{
// Cvar_RegisterVariable(&r_subdivide_size);
Cvar_RegisterVariable(&mod_q3bsp_curves_collisions);
Cvar_RegisterVariable(&mod_q3bsp_optimizedtraceline);
Cvar_RegisterVariable(&mod_q3bsp_debugtracebrush);
- memset(mod_q1bsp_novis, 0xff, sizeof(mod_q1bsp_novis));
- Mod_Q1BSP_Collision_Init();
}
static mleaf_t *Mod_Q1BSP_PointInLeaf(model_t *model, const vec3_t p)
#endif
}
-static hull_t box_hull;
-static dclipnode_t box_clipnodes[6];
-static mplane_t box_planes[6];
-
-static void Mod_Q1BSP_Collision_Init (void)
-{
- int i;
- int side;
-
- //Set up the planes and clipnodes so that the six floats of a bounding box
- //can just be stored out and get a proper hull_t structure.
-
- box_hull.clipnodes = box_clipnodes;
- box_hull.planes = box_planes;
- box_hull.firstclipnode = 0;
- box_hull.lastclipnode = 5;
-
- for (i = 0;i < 6;i++)
- {
- box_clipnodes[i].planenum = i;
-
- side = i&1;
-
- box_clipnodes[i].children[side] = CONTENTS_EMPTY;
- if (i != 5)
- box_clipnodes[i].children[side^1] = i + 1;
- else
- box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
-
- box_planes[i].type = i>>1;
- box_planes[i].normal[i>>1] = 1;
- }
-}
-
void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int boxsupercontents)
{
#if 1
Collision_TraceLineBrushFloat(trace, start, end, &cbox, &cbox);
#else
RecursiveHullCheckTraceInfo_t rhc;
+ static hull_t box_hull;
+ static dclipnode_t box_clipnodes[6];
+ static mplane_t box_planes[6];
// fill in a default trace
memset(&rhc, 0, sizeof(rhc));
memset(trace, 0, sizeof(trace_t));
#if COLLISIONPARANOID >= 3
Con_Printf("box_planes %f:%f %f:%f %f:%f\ncbox %f %f %f:%f %f %f\nbox %f %f %f:%f %f %f\n", box_planes[0].dist, box_planes[1].dist, box_planes[2].dist, box_planes[3].dist, box_planes[4].dist, box_planes[5].dist, cmins[0], cmins[1], cmins[2], cmaxs[0], cmaxs[1], cmaxs[2], mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
#endif
+
+ if (box_hull.clipnodes == NULL)
+ {
+ int i, side;
+
+ //Set up the planes and clipnodes so that the six floats of a bounding box
+ //can just be stored out and get a proper hull_t structure.
+
+ box_hull.clipnodes = box_clipnodes;
+ box_hull.planes = box_planes;
+ box_hull.firstclipnode = 0;
+ box_hull.lastclipnode = 5;
+
+ for (i = 0;i < 6;i++)
+ {
+ box_clipnodes[i].planenum = i;
+
+ side = i&1;
+
+ box_clipnodes[i].children[side] = CONTENTS_EMPTY;
+ if (i != 5)
+ box_clipnodes[i].children[side^1] = i + 1;
+ else
+ box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
+
+ box_planes[i].type = i>>1;
+ box_planes[i].normal[i>>1] = 1;
+ }
+ }
+
// trace a line through the generated clipping hull
//rhc.boxsupercontents = boxsupercontents;
rhc.hull = &box_hull;
#define MAX_MOD_KNOWN (MAX_MODELS + 256)
static model_t mod_known[MAX_MOD_KNOWN];
-rtexturepool_t *mod_shared_texturepool;
-rtexture_t *r_texture_notexture;
-rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
-rtexture_t *mod_shared_distorttexture[64];
-
-void Mod_BuildDetailTextures (void)
-{
- int i, x, y, light;
- float vc[3], vx[3], vy[3], vn[3], lightdir[3];
-#define DETAILRESOLUTION 256
- qbyte data[DETAILRESOLUTION][DETAILRESOLUTION][4], noise[DETAILRESOLUTION][DETAILRESOLUTION];
- lightdir[0] = 0.5;
- lightdir[1] = 1;
- lightdir[2] = -0.25;
- VectorNormalize(lightdir);
- for (i = 0;i < NUM_DETAILTEXTURES;i++)
- {
- fractalnoise(&noise[0][0], DETAILRESOLUTION, DETAILRESOLUTION >> 4);
- for (y = 0;y < DETAILRESOLUTION;y++)
- {
- for (x = 0;x < DETAILRESOLUTION;x++)
- {
- vc[0] = x;
- vc[1] = y;
- vc[2] = noise[y][x] * (1.0f / 32.0f);
- vx[0] = x + 1;
- vx[1] = y;
- vx[2] = noise[y][(x + 1) % DETAILRESOLUTION] * (1.0f / 32.0f);
- vy[0] = x;
- vy[1] = y + 1;
- vy[2] = noise[(y + 1) % DETAILRESOLUTION][x] * (1.0f / 32.0f);
- VectorSubtract(vx, vc, vx);
- VectorSubtract(vy, vc, vy);
- CrossProduct(vx, vy, vn);
- VectorNormalize(vn);
- light = 128 - DotProduct(vn, lightdir) * 128;
- light = bound(0, light, 255);
- data[y][x][0] = data[y][x][1] = data[y][x][2] = light;
- data[y][x][3] = 255;
- }
- }
- mod_shared_detailtextures[i] = R_LoadTexture2D(mod_shared_texturepool, va("detailtexture%i", i), DETAILRESOLUTION, DETAILRESOLUTION, &data[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP | TEXF_PRECACHE, NULL);
- }
-}
-
-qbyte Mod_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph)
-{
- int value = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) +
- ((2 * (y0 - y1) + y2 - y3) * morph * morph) +
- ((y2 - y0) * morph) +
- (y1));
-
- if (value > 255)
- value = 255;
- if (value < 0)
- value = 0;
-
- return (qbyte)value;
-}
-
-void Mod_BuildDistortTexture (void)
-{
- int x, y, i, j;
-#define DISTORTRESOLUTION 32
- qbyte data[5][DISTORTRESOLUTION][DISTORTRESOLUTION][2];
-
- for (i=0; i<4; i++)
- {
- for (y=0; y<DISTORTRESOLUTION; y++)
- {
- for (x=0; x<DISTORTRESOLUTION; x++)
- {
- data[i][y][x][0] = rand () & 255;
- data[i][y][x][1] = rand () & 255;
- }
- }
- }
-
-
- for (i=0; i<4; i++)
- {
- for (j=0; j<16; j++)
- {
- mod_shared_distorttexture[i*16+j] = NULL;
- if (gl_textureshader)
- {
- for (y=0; y<DISTORTRESOLUTION; y++)
- {
- for (x=0; x<DISTORTRESOLUTION; x++)
- {
- data[4][y][x][0] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][0], data[i][y][x][0], data[(i+1)&3][y][x][0], data[(i+2)&3][y][x][0], 0.0625*j);
- data[4][y][x][1] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][1], data[i][y][x][1], data[(i+1)&3][y][x][1], data[(i+2)&3][y][x][1], 0.0625*j);
- }
- }
- mod_shared_distorttexture[i*16+j] = R_LoadTexture2D(mod_shared_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
- }
- }
- }
-
- return;
-}
-
-void Mod_SetupNoTexture(void)
-{
-}
-
static void mod_start(void)
{
int i;
if (mod_known[i].name[0])
Mod_UnloadModel(&mod_known[i]);
Mod_LoadModels();
-
- mod_shared_texturepool = R_AllocTexturePool();
- Mod_SetupNoTexture();
- Mod_BuildDetailTextures();
- Mod_BuildDistortTexture();
}
static void mod_shutdown(void)
for (i = 0;i < MAX_MOD_KNOWN;i++)
if (mod_known[i].name[0])
Mod_UnloadModel(&mod_known[i]);
-
- R_FreeTexturePool(&mod_shared_texturepool);
}
static void mod_newmap(void)
{
char name[MAX_QPATH];
qboolean isworldmodel;
+ qboolean used;
strcpy(name, mod->name);
isworldmodel = mod->isworldmodel;
+ used = mod->used;
Mod_FreeModel(mod);
strcpy(mod->name, name);
mod->isworldmodel = isworldmodel;
+ mod->used = used;
mod->loaded = false;
}
if (!image_loadskin(&s, basename))
return false;
if (usedetailtexture)
- skinframe->detail = mod_shared_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES];
+ skinframe->detail = r_texture_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES];
skinframe->base = R_LoadTexture2D (loadmodel->texturepool, basename, s.basepixels_width, s.basepixels_height, s.basepixels, TEXTYPE_RGBA, textureflags, NULL);
if (s.nmappixels != NULL)
skinframe->nmap = R_LoadTexture2D (loadmodel->texturepool, va("%s_nmap", basename), s.nmappixels_width, s.nmappixels_height, s.nmappixels, TEXTYPE_RGBA, textureflags, NULL);
if (!skindata)
return false;
if (usedetailtexture)
- skinframe->detail = mod_shared_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES];
+ skinframe->detail = r_texture_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES];
if (r_shadow_bumpscale_basetexture.value > 0)
{
temp1 = Mem_Alloc(loadmodel->mempool, width * height * 8);
//============================================================================
-// this can be used for anything without a valid texture
-extern rtexture_t *r_texture_notexture;
-#define NUM_DETAILTEXTURES 1
-extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
-// every texture must be in a pool...
-extern rtexturepool_t *mod_shared_texturepool;
-
-extern rtexture_t *mod_shared_distorttexture[64];
-
// model loading
extern model_t *loadmodel;
extern qbyte *mod_base;
extern rtexture_t *r_texture_notexture;
extern rtexture_t *r_texture_whitecube;
extern rtexture_t *r_texture_normalizationcube;
+#define NUM_DETAILTEXTURES 1
+extern rtexture_t *r_texture_detailtextures[NUM_DETAILTEXTURES];
+extern rtexture_t *r_texture_distorttexture[64];
void R_TimeReport(char *name);
void R_TimeReport_Start(void);