-rtexturepool_t *mod_shared_texturepool;
-rtexture_t *r_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;
-}
-
-texture_t r_surf_notexture;
-
-void Mod_SetupNoTexture(void)
-{
- int x, y;
- qbyte pix[16][16][4];
-
- // this makes a light grey/dark grey checkerboard texture
- for (y = 0;y < 16;y++)
- {
- for (x = 0;x < 16;x++)
- {
- if ((y < 8) ^ (x < 8))
- {
- pix[y][x][0] = 128;
- pix[y][x][1] = 128;
- pix[y][x][2] = 128;
- pix[y][x][3] = 255;
- }
- else
- {
- pix[y][x][0] = 64;
- pix[y][x][1] = 64;
- pix[y][x][2] = 64;
- pix[y][x][3] = 255;
- }
- }
- }
-
- r_notexture = R_LoadTexture2D(mod_shared_texturepool, "notexture", 16, 16, &pix[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP, NULL);
-}
-