2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
gl_warp.c - sky and water polygons
|
|
|
|
Copyright (C) 2010 Uncle Mike
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2019-02-23 19:49:46 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
#include "gl_local.h"
|
|
|
|
#include "wadfile.h"
|
2023-06-25 12:17:46 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
#define SKYCLOUDS_QUALITY 12
|
|
|
|
#define MAX_CLIP_VERTS 128 // skybox clip vertices
|
|
|
|
#define TURBSCALE ( 256.0f / ( M_PI2 ))
|
|
|
|
|
2023-06-25 12:17:46 +02:00
|
|
|
static const char* r_skyBoxSuffix[SKYBOX_MAX_SIDES] = { "rt", "bk", "lf", "ft", "up", "dn" };
|
|
|
|
static const int r_skyTexOrder[SKYBOX_MAX_SIDES] = { 0, 2, 1, 3, 4, 5 };
|
|
|
|
|
|
|
|
static const vec3_t skyclip[SKYBOX_MAX_SIDES] =
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
{ 1, 1, 0 },
|
|
|
|
{ 1, -1, 0 },
|
|
|
|
{ 0, -1, 1 },
|
|
|
|
{ 0, 1, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ -1, 0, 1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// 1 = s, 2 = t, 3 = 2048
|
2023-06-25 12:17:46 +02:00
|
|
|
static const int st_to_vec[SKYBOX_MAX_SIDES][3] =
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
{ 3, -1, 2 },
|
|
|
|
{ -3, 1, 2 },
|
|
|
|
{ 1, 3, 2 },
|
|
|
|
{ -1, -3, 2 },
|
|
|
|
{ -2, -1, 3 }, // 0 degrees yaw, look straight up
|
|
|
|
{ 2, -1, -3 } // look straight down
|
|
|
|
};
|
|
|
|
|
|
|
|
// s = [0]/[2], t = [1]/[2]
|
2023-06-25 12:17:46 +02:00
|
|
|
static const int vec_to_st[SKYBOX_MAX_SIDES][3] =
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
{ -2, 3, 1 },
|
|
|
|
{ 2, 3, -1 },
|
|
|
|
{ 1, 3, 2 },
|
|
|
|
{ -1, 3, -2 },
|
|
|
|
{ -2, -1, 3 },
|
|
|
|
{ -2, 1, -3 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// speed up sin calculations
|
2023-06-25 12:17:46 +02:00
|
|
|
static float r_turbsin[] =
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2023-06-25 12:17:46 +02:00
|
|
|
#include "warpsin.h"
|
2018-04-13 18:23:45 +02:00
|
|
|
};
|
|
|
|
|
2023-10-30 04:25:28 +01:00
|
|
|
#define RIPPLES_CACHEWIDTH_BITS 7
|
|
|
|
#define RIPPLES_CACHEWIDTH ( 1 << RIPPLES_CACHEWIDTH_BITS )
|
|
|
|
#define RIPPLES_CACHEWIDTH_MASK (( RIPPLES_CACHEWIDTH ) - 1 )
|
|
|
|
#define RIPPLES_TEXSIZE ( RIPPLES_CACHEWIDTH * RIPPLES_CACHEWIDTH )
|
|
|
|
#define RIPPLES_TEXSIZE_MASK ( RIPPLES_TEXSIZE - 1 )
|
|
|
|
|
|
|
|
STATIC_ASSERT( RIPPLES_TEXSIZE == 0x4000, "fix the algorithm to work with custom resolution" );
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
double time;
|
|
|
|
double oldtime;
|
|
|
|
|
|
|
|
short *curbuf, *oldbuf;
|
|
|
|
short buf[2][RIPPLES_TEXSIZE];
|
|
|
|
qboolean update;
|
|
|
|
|
|
|
|
uint32_t texture[RIPPLES_TEXSIZE];
|
|
|
|
int gl_texturenum;
|
|
|
|
int rippletexturenum;
|
2023-10-31 02:27:34 +01:00
|
|
|
float texturescale; // not all textures are 128x128, scale the texcoords down
|
2023-10-30 04:25:28 +01:00
|
|
|
} g_ripple;
|
|
|
|
|
2022-08-31 01:42:17 +02:00
|
|
|
static qboolean CheckSkybox( const char *name, char out[6][MAX_STRING] )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
const char *skybox_ext[3] = { "dds", "tga", "bmp" };
|
|
|
|
int i, j, num_checked_sides;
|
2022-12-18 18:55:53 +01:00
|
|
|
char sidename[MAX_VA_STRING];
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
// search for skybox images
|
2018-04-13 18:23:45 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2021-01-03 02:28:45 +01:00
|
|
|
{
|
2022-08-31 01:42:17 +02:00
|
|
|
// check HL-style skyboxes
|
2018-04-13 18:23:45 +02:00
|
|
|
num_checked_sides = 0;
|
2023-05-19 03:35:54 +02:00
|
|
|
for( j = 0; j < SKYBOX_MAX_SIDES; j++ )
|
2019-07-19 19:23:08 +02:00
|
|
|
{
|
2018-04-13 18:23:45 +02:00
|
|
|
// build side name
|
2022-12-18 18:55:53 +01:00
|
|
|
Q_snprintf( sidename, sizeof( sidename ), "%s%s.%s", name, r_skyBoxSuffix[j], skybox_ext[i] );
|
2022-07-01 18:37:21 +02:00
|
|
|
if( gEngfuncs.fsapi->FileExists( sidename, false ))
|
2022-08-31 01:42:17 +02:00
|
|
|
{
|
|
|
|
Q_strncpy( out[j], sidename, sizeof( out[j] ));
|
2018-04-13 18:23:45 +02:00
|
|
|
num_checked_sides++;
|
2022-08-31 01:42:17 +02:00
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( num_checked_sides == 6 )
|
2022-08-31 01:42:17 +02:00
|
|
|
return true; // image exists
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-08-31 01:42:17 +02:00
|
|
|
// check Q1-style skyboxes
|
|
|
|
num_checked_sides = 0;
|
2023-05-19 03:35:54 +02:00
|
|
|
for( j = 0; j < SKYBOX_MAX_SIDES; j++ )
|
2019-07-19 19:23:08 +02:00
|
|
|
{
|
2018-04-13 18:23:45 +02:00
|
|
|
// build side name
|
2022-12-18 18:55:53 +01:00
|
|
|
Q_snprintf( sidename, sizeof( sidename ), "%s_%s.%s", name, r_skyBoxSuffix[j], skybox_ext[i] );
|
2022-07-01 18:37:21 +02:00
|
|
|
if( gEngfuncs.fsapi->FileExists( sidename, false ))
|
2022-08-31 01:42:17 +02:00
|
|
|
{
|
|
|
|
Q_strncpy( out[j], sidename, sizeof( out[j] ));
|
2018-04-13 18:23:45 +02:00
|
|
|
num_checked_sides++;
|
2022-08-31 01:42:17 +02:00
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( num_checked_sides == 6 )
|
2022-08-31 01:42:17 +02:00
|
|
|
return true; // images exists
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2022-08-31 01:42:17 +02:00
|
|
|
return false;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2023-06-25 12:17:46 +02:00
|
|
|
static void DrawSkyPolygon( int nump, vec3_t vecs )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
int i, j, axis;
|
|
|
|
float s, t, dv, *vp;
|
|
|
|
vec3_t v, av;
|
|
|
|
|
|
|
|
// decide which face it maps to
|
|
|
|
VectorClear( v );
|
|
|
|
|
|
|
|
for( i = 0, vp = vecs; i < nump; i++, vp += 3 )
|
|
|
|
VectorAdd( vp, v, v );
|
|
|
|
|
|
|
|
av[0] = fabs( v[0] );
|
|
|
|
av[1] = fabs( v[1] );
|
|
|
|
av[2] = fabs( v[2] );
|
|
|
|
|
|
|
|
if( av[0] > av[1] && av[0] > av[2] )
|
|
|
|
axis = (v[0] < 0) ? 1 : 0;
|
|
|
|
else if( av[1] > av[2] && av[1] > av[0] )
|
|
|
|
axis = (v[1] < 0) ? 3 : 2;
|
|
|
|
else axis = (v[2] < 0) ? 5 : 4;
|
|
|
|
|
|
|
|
// project new texture coords
|
|
|
|
for( i = 0; i < nump; i++, vecs += 3 )
|
|
|
|
{
|
|
|
|
j = vec_to_st[axis][2];
|
|
|
|
dv = (j > 0) ? vecs[j-1] : -vecs[-j-1];
|
|
|
|
|
|
|
|
if( dv == 0.0f ) continue;
|
|
|
|
|
|
|
|
j = vec_to_st[axis][0];
|
|
|
|
s = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv;
|
|
|
|
|
|
|
|
j = vec_to_st[axis][1];
|
|
|
|
t = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv;
|
|
|
|
|
|
|
|
if( s < RI.skyMins[0][axis] ) RI.skyMins[0][axis] = s;
|
|
|
|
if( t < RI.skyMins[1][axis] ) RI.skyMins[1][axis] = t;
|
|
|
|
if( s > RI.skyMaxs[0][axis] ) RI.skyMaxs[0][axis] = s;
|
|
|
|
if( t > RI.skyMaxs[1][axis] ) RI.skyMaxs[1][axis] = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
ClipSkyPolygon
|
|
|
|
==============
|
|
|
|
*/
|
2023-06-25 12:17:46 +02:00
|
|
|
static void ClipSkyPolygon( int nump, vec3_t vecs, int stage )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
const float *norm;
|
|
|
|
float *v, d, e;
|
|
|
|
qboolean front, back;
|
|
|
|
float dists[MAX_CLIP_VERTS + 1];
|
|
|
|
int sides[MAX_CLIP_VERTS + 1];
|
|
|
|
vec3_t newv[2][MAX_CLIP_VERTS + 1];
|
|
|
|
int newc[2];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if( nump > MAX_CLIP_VERTS )
|
2019-03-06 14:23:33 +01:00
|
|
|
gEngfuncs.Host_Error( "ClipSkyPolygon: MAX_CLIP_VERTS\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
loc1:
|
|
|
|
if( stage == 6 )
|
2021-01-03 02:28:45 +01:00
|
|
|
{
|
2018-04-13 18:23:45 +02:00
|
|
|
// fully clipped, so draw it
|
|
|
|
DrawSkyPolygon( nump, vecs );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
front = back = false;
|
|
|
|
norm = skyclip[stage];
|
|
|
|
for( i = 0, v = vecs; i < nump; i++, v += 3 )
|
|
|
|
{
|
|
|
|
d = DotProduct( v, norm );
|
|
|
|
if( d > ON_EPSILON )
|
|
|
|
{
|
|
|
|
front = true;
|
|
|
|
sides[i] = SIDE_FRONT;
|
|
|
|
}
|
|
|
|
else if( d < -ON_EPSILON )
|
|
|
|
{
|
|
|
|
back = true;
|
|
|
|
sides[i] = SIDE_BACK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sides[i] = SIDE_ON;
|
|
|
|
}
|
|
|
|
dists[i] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !front || !back )
|
2021-01-03 02:28:45 +01:00
|
|
|
{
|
2018-04-13 18:23:45 +02:00
|
|
|
// not clipped
|
|
|
|
stage++;
|
|
|
|
goto loc1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// clip it
|
|
|
|
sides[i] = sides[0];
|
|
|
|
dists[i] = dists[0];
|
|
|
|
VectorCopy( vecs, ( vecs + ( i * 3 )));
|
|
|
|
newc[0] = newc[1] = 0;
|
|
|
|
|
|
|
|
for( i = 0, v = vecs; i < nump; i++, v += 3 )
|
|
|
|
{
|
|
|
|
switch( sides[i] )
|
|
|
|
{
|
|
|
|
case SIDE_FRONT:
|
|
|
|
VectorCopy( v, newv[0][newc[0]] );
|
|
|
|
newc[0]++;
|
|
|
|
break;
|
|
|
|
case SIDE_BACK:
|
|
|
|
VectorCopy( v, newv[1][newc[1]] );
|
|
|
|
newc[1]++;
|
|
|
|
break;
|
|
|
|
case SIDE_ON:
|
|
|
|
VectorCopy( v, newv[0][newc[0]] );
|
|
|
|
newc[0]++;
|
|
|
|
VectorCopy( v, newv[1][newc[1]] );
|
|
|
|
newc[1]++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sides[i] == SIDE_ON || sides[i+1] == SIDE_ON || sides[i+1] == sides[i] )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d = dists[i] / ( dists[i] - dists[i+1] );
|
|
|
|
for( j = 0; j < 3; j++ )
|
|
|
|
{
|
|
|
|
e = v[j] + d * ( v[j+3] - v[j] );
|
|
|
|
newv[0][newc[0]][j] = e;
|
|
|
|
newv[1][newc[1]][j] = e;
|
|
|
|
}
|
|
|
|
newc[0]++;
|
|
|
|
newc[1]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// continue
|
|
|
|
ClipSkyPolygon( newc[0], newv[0][0], stage + 1 );
|
|
|
|
ClipSkyPolygon( newc[1], newv[1][0], stage + 1 );
|
|
|
|
}
|
|
|
|
|
2023-06-25 12:17:46 +02:00
|
|
|
static void MakeSkyVec( float s, float t, int axis )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
int j, k, farclip;
|
|
|
|
vec3_t v, b;
|
|
|
|
|
|
|
|
farclip = RI.farClip;
|
|
|
|
|
|
|
|
b[0] = s * (farclip >> 1);
|
|
|
|
b[1] = t * (farclip >> 1);
|
|
|
|
b[2] = (farclip >> 1);
|
|
|
|
|
|
|
|
for( j = 0; j < 3; j++ )
|
|
|
|
{
|
|
|
|
k = st_to_vec[axis][j];
|
|
|
|
v[j] = (k < 0) ? -b[-k-1] : b[k-1];
|
|
|
|
v[j] += RI.cullorigin[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
// avoid bilerp seam
|
|
|
|
s = (s + 1.0f) * 0.5f;
|
|
|
|
t = (t + 1.0f) * 0.5f;
|
|
|
|
|
2023-06-25 12:17:46 +02:00
|
|
|
s = bound( 1.0f / 512.0f, s, 511.0f / 512.0f );
|
|
|
|
t = bound( 1.0f / 512.0f, t, 511.0f / 512.0f );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
t = 1.0f - t;
|
|
|
|
|
|
|
|
pglTexCoord2f( s, t );
|
|
|
|
pglVertex3fv( v );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_ClearSkyBox
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void R_ClearSkyBox( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2023-05-19 03:35:54 +02:00
|
|
|
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
RI.skyMins[0][i] = RI.skyMins[1][i] = 9999999.0f;
|
|
|
|
RI.skyMaxs[0][i] = RI.skyMaxs[1][i] = -9999999.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
R_AddSkyBoxSurface
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void R_AddSkyBoxSurface( msurface_t *fa )
|
|
|
|
{
|
|
|
|
vec3_t verts[MAX_CLIP_VERTS];
|
|
|
|
glpoly_t *p;
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
if( ENGINE_GET_PARM( PARM_SKY_SPHERE ) && fa->polys && !tr.fCustomSkybox )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
glpoly_t *p = fa->polys;
|
|
|
|
|
|
|
|
// draw the sky poly
|
|
|
|
pglBegin( GL_POLYGON );
|
|
|
|
for( i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE )
|
|
|
|
{
|
|
|
|
pglTexCoord2f( v[3], v[4] );
|
|
|
|
pglVertex3fv( v );
|
|
|
|
}
|
|
|
|
pglEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate vertex values for sky box
|
|
|
|
for( p = fa->polys; p; p = p->next )
|
|
|
|
{
|
|
|
|
for( i = 0; i < p->numverts; i++ )
|
|
|
|
VectorSubtract( p->verts[i], RI.cullorigin, verts[i] );
|
|
|
|
ClipSkyPolygon( p->numverts, verts[0], 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_UnloadSkybox
|
|
|
|
|
|
|
|
Unload previous skybox
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void R_UnloadSkybox( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// release old skybox
|
2023-05-19 03:35:54 +02:00
|
|
|
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( !tr.skyboxTextures[i] ) continue;
|
|
|
|
GL_FreeTexture( tr.skyboxTextures[i] );
|
|
|
|
}
|
|
|
|
|
2023-05-19 03:35:54 +02:00
|
|
|
tr.skyboxbasenum = SKYBOX_BASE_NUM; // set skybox base (to let some mods load hi-res skyboxes)
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
memset( tr.skyboxTextures, 0, sizeof( tr.skyboxTextures ));
|
2019-02-27 00:23:03 +01:00
|
|
|
tr.fCustomSkybox = false;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_DrawSkybox
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void R_DrawSkyBox( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
RI.isSkyVisible = true;
|
|
|
|
|
|
|
|
// don't fogging skybox (this fix old Half-Life bug)
|
|
|
|
if( !RI.fogSkybox ) R_AllowFog( false );
|
|
|
|
|
2018-11-27 14:11:26 +01:00
|
|
|
if( RI.fogEnabled )
|
|
|
|
pglFogf( GL_FOG_DENSITY, RI.fogDensity * 0.5f );
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
pglDisable( GL_BLEND );
|
|
|
|
pglDisable( GL_ALPHA_TEST );
|
|
|
|
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
|
|
|
|
|
2023-05-19 03:35:54 +02:00
|
|
|
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( RI.skyMins[0][i] >= RI.skyMaxs[0][i] || RI.skyMins[1][i] >= RI.skyMaxs[1][i] )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( tr.skyboxTextures[r_skyTexOrder[i]] )
|
2018-04-17 02:55:36 +02:00
|
|
|
GL_Bind( XASH_TEXTURE0, tr.skyboxTextures[r_skyTexOrder[i]] );
|
2018-04-19 22:47:41 +02:00
|
|
|
else GL_Bind( XASH_TEXTURE0, tr.grayTexture ); // stub
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
pglBegin( GL_QUADS );
|
|
|
|
MakeSkyVec( RI.skyMins[0][i], RI.skyMins[1][i], i );
|
|
|
|
MakeSkyVec( RI.skyMins[0][i], RI.skyMaxs[1][i], i );
|
|
|
|
MakeSkyVec( RI.skyMaxs[0][i], RI.skyMaxs[1][i], i );
|
|
|
|
MakeSkyVec( RI.skyMaxs[0][i], RI.skyMins[1][i], i );
|
|
|
|
pglEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !RI.fogSkybox )
|
|
|
|
R_AllowFog( true );
|
2018-11-27 14:11:26 +01:00
|
|
|
|
|
|
|
if( RI.fogEnabled )
|
|
|
|
pglFogf( GL_FOG_DENSITY, RI.fogDensity );
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
R_LoadIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_SetupSky
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_SetupSky( const char *skyboxname )
|
|
|
|
{
|
2019-02-27 00:23:03 +01:00
|
|
|
char loadname[MAX_STRING];
|
2022-08-31 01:42:17 +02:00
|
|
|
char sidenames[6][MAX_STRING];
|
|
|
|
int i, len;
|
|
|
|
qboolean result;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( !COM_CheckString( skyboxname ))
|
|
|
|
{
|
|
|
|
R_UnloadSkybox();
|
|
|
|
return; // clear old skybox
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_snprintf( loadname, sizeof( loadname ), "gfx/env/%s", skyboxname );
|
|
|
|
COM_StripExtension( loadname );
|
|
|
|
|
|
|
|
// kill the underline suffix to find them manually later
|
2020-11-29 01:39:10 +01:00
|
|
|
len = Q_strlen( loadname );
|
|
|
|
|
|
|
|
if( loadname[len - 1] == '_' )
|
|
|
|
loadname[len - 1] = '\0';
|
2022-08-31 01:42:17 +02:00
|
|
|
result = CheckSkybox( loadname, sidenames );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// to prevent infinite recursion if default skybox was missed
|
2022-08-31 01:42:17 +02:00
|
|
|
if( !result && Q_stricmp( loadname, DEFAULT_SKYBOX_PATH ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-03-06 14:23:33 +01:00
|
|
|
gEngfuncs.Con_Reportf( S_WARN "missed or incomplete skybox '%s'\n", skyboxname );
|
2018-04-13 18:23:45 +02:00
|
|
|
R_SetupSky( "desert" ); // force to default
|
2021-01-03 02:28:45 +01:00
|
|
|
return;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// release old skybox
|
|
|
|
R_UnloadSkybox();
|
2019-02-27 00:23:03 +01:00
|
|
|
gEngfuncs.Con_DPrintf( "SKY: " );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-05-19 03:35:54 +02:00
|
|
|
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-08-31 01:42:17 +02:00
|
|
|
tr.skyboxTextures[i] = GL_LoadTexture( sidenames[i], NULL, 0, TF_CLAMP|TF_SKY );
|
|
|
|
|
|
|
|
if( !tr.skyboxTextures[i] )
|
|
|
|
break;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2019-02-27 00:23:03 +01:00
|
|
|
gEngfuncs.Con_DPrintf( "%s%s%s", skyboxname, r_skyBoxSuffix[i], i != 5 ? ", " : ". " );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 6 )
|
|
|
|
{
|
2019-02-27 00:23:03 +01:00
|
|
|
tr.fCustomSkybox = true;
|
|
|
|
gEngfuncs.Con_DPrintf( "done\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
return; // loaded
|
|
|
|
}
|
|
|
|
|
2019-02-27 00:23:03 +01:00
|
|
|
gEngfuncs.Con_DPrintf( "^2failed\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
R_UnloadSkybox();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
//
|
|
|
|
// RENDER CLOUDS
|
|
|
|
//
|
|
|
|
//==============================================================================
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_CloudVertex
|
|
|
|
==============
|
|
|
|
*/
|
2023-06-25 12:17:46 +02:00
|
|
|
static void R_CloudVertex( float s, float t, int axis, vec3_t v )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
int j, k, farclip;
|
|
|
|
vec3_t b;
|
|
|
|
|
|
|
|
farclip = RI.farClip;
|
|
|
|
|
|
|
|
b[0] = s * (farclip >> 1);
|
|
|
|
b[1] = t * (farclip >> 1);
|
|
|
|
b[2] = (farclip >> 1);
|
|
|
|
|
|
|
|
for( j = 0; j < 3; j++ )
|
|
|
|
{
|
|
|
|
k = st_to_vec[axis][j];
|
|
|
|
v[j] = (k < 0) ? -b[-k-1] : b[k-1];
|
|
|
|
v[j] += RI.cullorigin[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_CloudTexCoord
|
|
|
|
=============
|
|
|
|
*/
|
2023-06-25 12:17:46 +02:00
|
|
|
static void R_CloudTexCoord( vec3_t v, float speed, float *s, float *t )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
float length, speedscale;
|
|
|
|
vec3_t dir;
|
|
|
|
|
2019-02-24 16:45:27 +01:00
|
|
|
speedscale = gpGlobals->time * speed;
|
2018-04-13 18:23:45 +02:00
|
|
|
speedscale -= (int)speedscale & ~127;
|
|
|
|
|
|
|
|
VectorSubtract( v, RI.vieworg, dir );
|
|
|
|
dir[2] *= 3.0f; // flatten the sphere
|
|
|
|
|
|
|
|
length = VectorLength( dir );
|
|
|
|
length = 6.0f * 63.0f / length;
|
|
|
|
|
|
|
|
*s = ( speedscale + dir[0] * length ) * (1.0f / 128.0f);
|
|
|
|
*t = ( speedscale + dir[1] * length ) * (1.0f / 128.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_CloudDrawPoly
|
|
|
|
===============
|
|
|
|
*/
|
2023-06-25 12:17:46 +02:00
|
|
|
static void R_CloudDrawPoly( glpoly_t *p )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
float s, t;
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GL_SetRenderMode( kRenderNormal );
|
2018-04-17 02:55:36 +02:00
|
|
|
GL_Bind( XASH_TEXTURE0, tr.solidskyTexture );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
pglBegin( GL_QUADS );
|
|
|
|
for( i = 0, v = p->verts[0]; i < 4; i++, v += VERTEXSIZE )
|
|
|
|
{
|
|
|
|
R_CloudTexCoord( v, 8.0f, &s, &t );
|
|
|
|
pglTexCoord2f( s, t );
|
|
|
|
pglVertex3fv( v );
|
|
|
|
}
|
|
|
|
pglEnd();
|
|
|
|
|
|
|
|
GL_SetRenderMode( kRenderTransTexture );
|
2018-04-17 02:55:36 +02:00
|
|
|
GL_Bind( XASH_TEXTURE0, tr.alphaskyTexture );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
pglBegin( GL_QUADS );
|
|
|
|
for( i = 0, v = p->verts[0]; i < 4; i++, v += VERTEXSIZE )
|
|
|
|
{
|
|
|
|
R_CloudTexCoord( v, 16.0f, &s, &t );
|
|
|
|
pglTexCoord2f( s, t );
|
|
|
|
pglVertex3fv( v );
|
|
|
|
}
|
|
|
|
pglEnd();
|
|
|
|
|
|
|
|
pglDisable( GL_BLEND );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_CloudRenderSide
|
|
|
|
==============
|
|
|
|
*/
|
2023-06-25 12:17:46 +02:00
|
|
|
static void R_CloudRenderSide( int axis )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
vec3_t verts[4];
|
|
|
|
float di, qi, dj, qj;
|
|
|
|
vec3_t vup, vright;
|
|
|
|
vec3_t temp, temp2;
|
|
|
|
glpoly_t p[1];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
R_CloudVertex( -1.0f, -1.0f, axis, verts[0] );
|
|
|
|
R_CloudVertex( -1.0f, 1.0f, axis, verts[1] );
|
|
|
|
R_CloudVertex( 1.0f, 1.0f, axis, verts[2] );
|
|
|
|
R_CloudVertex( 1.0f, -1.0f, axis, verts[3] );
|
|
|
|
|
|
|
|
VectorSubtract( verts[2], verts[3], vup );
|
|
|
|
VectorSubtract( verts[2], verts[1], vright );
|
|
|
|
|
|
|
|
p->numverts = 4;
|
|
|
|
di = SKYCLOUDS_QUALITY;
|
2019-10-06 05:51:28 +02:00
|
|
|
qi = 1.0f / di;
|
2018-04-13 18:23:45 +02:00
|
|
|
dj = (axis < 4) ? di * 2 : di; //subdivide vertically more than horizontally on skybox sides
|
2019-10-06 05:51:28 +02:00
|
|
|
qj = 1.0f / dj;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
for( i = 0; i < di; i++ )
|
|
|
|
{
|
|
|
|
for( j = 0; j < dj; j++ )
|
|
|
|
{
|
|
|
|
if( i * qi < RI.skyMins[0][axis] / 2 + 0.5f - qi
|
|
|
|
|| i * qi > RI.skyMaxs[0][axis] / 2 + 0.5f
|
|
|
|
|| j * qj < RI.skyMins[1][axis] / 2 + 0.5f - qj
|
|
|
|
|| j * qj > RI.skyMaxs[1][axis] / 2 + 0.5f )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
VectorScale( vright, qi * i, temp );
|
|
|
|
VectorScale( vup, qj * j, temp2 );
|
|
|
|
VectorAdd( temp, temp2, temp );
|
|
|
|
VectorAdd( verts[0], temp, p->verts[0] );
|
|
|
|
|
|
|
|
VectorScale( vup, qj, temp );
|
|
|
|
VectorAdd( p->verts[0], temp, p->verts[1] );
|
|
|
|
|
|
|
|
VectorScale( vright, qi, temp );
|
|
|
|
VectorAdd( p->verts[1], temp, p->verts[2] );
|
|
|
|
|
|
|
|
VectorAdd( p->verts[0], temp, p->verts[3] );
|
|
|
|
|
|
|
|
R_CloudDrawPoly( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
R_DrawClouds
|
|
|
|
|
|
|
|
Quake-style clouds
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void R_DrawClouds( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
RI.isSkyVisible = true;
|
|
|
|
|
|
|
|
if( RI.fogEnabled )
|
|
|
|
pglFogf( GL_FOG_DENSITY, RI.fogDensity * 0.25f );
|
|
|
|
pglDepthFunc( GL_GEQUAL );
|
|
|
|
pglDepthMask( GL_FALSE );
|
|
|
|
|
2023-05-19 03:35:54 +02:00
|
|
|
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( RI.skyMins[0][i] >= RI.skyMaxs[0][i] || RI.skyMins[1][i] >= RI.skyMaxs[1][i] )
|
|
|
|
continue;
|
|
|
|
R_CloudRenderSide( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
pglDepthFunc( GL_LEQUAL );
|
|
|
|
pglDepthMask( GL_TRUE );
|
|
|
|
|
|
|
|
if( RI.fogEnabled )
|
|
|
|
pglFogf( GL_FOG_DENSITY, RI.fogDensity );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_InitSkyClouds
|
|
|
|
|
|
|
|
A sky texture is 256*128, with the right side being a masked overlay
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void R_InitSkyClouds( mip_t *mt, texture_t *tx, qboolean custom_palette )
|
|
|
|
{
|
|
|
|
rgbdata_t r_temp, *r_sky;
|
|
|
|
uint *trans, *rgba;
|
|
|
|
uint transpix;
|
|
|
|
int r, g, b;
|
|
|
|
int i, j, p;
|
|
|
|
char texname[32];
|
|
|
|
|
|
|
|
if( !glw_state.initialized )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Q_snprintf( texname, sizeof( texname ), "%s%s.mip", ( mt->offsets[0] > 0 ) ? "#" : "", tx->name );
|
|
|
|
|
|
|
|
if( mt->offsets[0] > 0 )
|
|
|
|
{
|
|
|
|
int size = (int)sizeof( mip_t ) + ((mt->width * mt->height * 85)>>6);
|
|
|
|
|
|
|
|
if( custom_palette ) size += sizeof( short ) + 768;
|
2019-03-06 15:14:25 +01:00
|
|
|
r_sky = gEngfuncs.FS_LoadImage( texname, (byte *)mt, size );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// okay, loading it from wad
|
2019-03-06 15:14:25 +01:00
|
|
|
r_sky = gEngfuncs.FS_LoadImage( texname, NULL, 0 );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure what sky image is valid
|
|
|
|
if( !r_sky || !r_sky->palette || r_sky->type != PF_INDEXED_32 || r_sky->height == 0 )
|
|
|
|
{
|
2019-03-06 14:23:33 +01:00
|
|
|
gEngfuncs.Con_Reportf( S_ERROR "R_InitSky: unable to load sky texture %s\n", tx->name );
|
2019-03-06 15:14:25 +01:00
|
|
|
if( r_sky ) gEngfuncs.FS_FreeImage( r_sky );
|
2018-04-13 18:23:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make an average value for the back to avoid
|
|
|
|
// a fringe on the top level
|
2018-06-09 00:28:35 +02:00
|
|
|
trans = Mem_Malloc( r_temppool, r_sky->height * r_sky->height * sizeof( *trans ));
|
2018-04-13 18:23:45 +02:00
|
|
|
r = g = b = 0;
|
|
|
|
|
|
|
|
for( i = 0; i < r_sky->width >> 1; i++ )
|
|
|
|
{
|
|
|
|
for( j = 0; j < r_sky->height; j++ )
|
|
|
|
{
|
|
|
|
p = r_sky->buffer[i * r_sky->width + j + r_sky->height];
|
|
|
|
rgba = (uint *)r_sky->palette + p;
|
|
|
|
trans[(i * r_sky->height) + j] = *rgba;
|
|
|
|
r += ((byte *)rgba)[0];
|
|
|
|
g += ((byte *)rgba)[1];
|
|
|
|
b += ((byte *)rgba)[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
((byte *)&transpix)[0] = r / ( r_sky->height * r_sky->height );
|
|
|
|
((byte *)&transpix)[1] = g / ( r_sky->height * r_sky->height );
|
|
|
|
((byte *)&transpix)[2] = b / ( r_sky->height * r_sky->height );
|
|
|
|
((byte *)&transpix)[3] = 0;
|
|
|
|
|
|
|
|
// build a temporary image
|
|
|
|
r_temp = *r_sky;
|
|
|
|
r_temp.width = r_sky->width >> 1;
|
|
|
|
r_temp.height = r_sky->height;
|
|
|
|
r_temp.type = PF_RGBA_32;
|
|
|
|
r_temp.flags = IMAGE_HAS_COLOR;
|
|
|
|
r_temp.size = r_temp.width * r_temp.height * 4;
|
|
|
|
r_temp.buffer = (byte *)trans;
|
|
|
|
r_temp.palette = NULL;
|
|
|
|
|
|
|
|
// load it in
|
2019-04-15 00:43:43 +02:00
|
|
|
tr.solidskyTexture = GL_LoadTextureInternal( REF_SOLIDSKY_TEXTURE, &r_temp, TF_NOMIPMAP );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
for( i = 0; i < r_sky->width >> 1; i++ )
|
|
|
|
{
|
|
|
|
for( j = 0; j < r_sky->height; j++ )
|
|
|
|
{
|
|
|
|
p = r_sky->buffer[i * r_sky->width + j];
|
|
|
|
|
|
|
|
if( p == 0 )
|
|
|
|
{
|
|
|
|
trans[(i * r_sky->height) + j] = transpix;
|
|
|
|
}
|
|
|
|
else
|
2019-07-19 19:23:08 +02:00
|
|
|
{
|
2018-04-13 18:23:45 +02:00
|
|
|
rgba = (uint *)r_sky->palette + p;
|
|
|
|
trans[(i * r_sky->height) + j] = *rgba;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r_temp.flags = IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA;
|
|
|
|
|
|
|
|
// load it in
|
2019-04-15 00:43:43 +02:00
|
|
|
tr.alphaskyTexture = GL_LoadTextureInternal( REF_ALPHASKY_TEXTURE, &r_temp, TF_NOMIPMAP );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// clean up
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.FS_FreeImage( r_sky );
|
2018-04-13 18:23:45 +02:00
|
|
|
Mem_Free( trans );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
EmitWaterPolys
|
|
|
|
|
|
|
|
Does a water warp on the pre-fragmented glpoly_t chain
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void EmitWaterPolys( msurface_t *warp, qboolean reverse )
|
|
|
|
{
|
|
|
|
float *v, nv, waveHeight;
|
|
|
|
float s, t, os, ot;
|
|
|
|
glpoly_t *p;
|
|
|
|
int i;
|
2023-10-05 02:32:37 +02:00
|
|
|
|
|
|
|
const qboolean useQuads = FBitSet( warp->flags, SURF_DRAWTURB_QUADS ) && glConfig.context == CONTEXT_TYPE_GL;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( !warp->polys ) return;
|
|
|
|
|
|
|
|
// set the current waveheight
|
2023-10-31 19:51:47 +01:00
|
|
|
if( warp->polys->verts[0][2] >= RI.vieworg[2] )
|
2018-04-13 18:23:45 +02:00
|
|
|
waveHeight = -RI.currententity->curstate.scale;
|
|
|
|
else waveHeight = RI.currententity->curstate.scale;
|
|
|
|
|
|
|
|
// reset fog color for nonlightmapped water
|
|
|
|
GL_ResetFogColor();
|
|
|
|
|
2019-11-17 16:51:39 +01:00
|
|
|
if( useQuads )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglBegin( GL_QUADS );
|
|
|
|
|
|
|
|
for( p = warp->polys; p; p = p->next )
|
|
|
|
{
|
|
|
|
if( reverse )
|
|
|
|
v = p->verts[0] + ( p->numverts - 1 ) * VERTEXSIZE;
|
|
|
|
else v = p->verts[0];
|
|
|
|
|
2019-11-17 16:51:39 +01:00
|
|
|
if( !useQuads )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglBegin( GL_POLYGON );
|
|
|
|
|
|
|
|
for( i = 0; i < p->numverts; i++ )
|
|
|
|
{
|
|
|
|
if( waveHeight )
|
|
|
|
{
|
2019-02-24 16:45:27 +01:00
|
|
|
nv = r_turbsin[(int)(gpGlobals->time * 160.0f + v[1] + v[0]) & 255] + 8.0f;
|
|
|
|
nv = (r_turbsin[(int)(v[0] * 5.0f + gpGlobals->time * 171.0f - v[1]) & 255] + 8.0f ) * 0.8f + nv;
|
2018-04-13 18:23:45 +02:00
|
|
|
nv = nv * waveHeight + v[2];
|
|
|
|
}
|
|
|
|
else nv = v[2];
|
|
|
|
|
|
|
|
os = v[3];
|
|
|
|
ot = v[4];
|
|
|
|
|
2023-10-30 04:25:28 +01:00
|
|
|
if( !r_ripple.value )
|
|
|
|
{
|
|
|
|
s = os + r_turbsin[(int)((ot * 0.125f + gpGlobals->time) * TURBSCALE) & 255];
|
|
|
|
t = ot + r_turbsin[(int)((os * 0.125f + gpGlobals->time) * TURBSCALE) & 255];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = os / g_ripple.texturescale;
|
|
|
|
t = ot / g_ripple.texturescale;
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-10-30 04:25:28 +01:00
|
|
|
s *= ( 1.0f / SUBDIVIDE_SIZE );
|
2018-04-13 18:23:45 +02:00
|
|
|
t *= ( 1.0f / SUBDIVIDE_SIZE );
|
|
|
|
|
|
|
|
pglTexCoord2f( s, t );
|
|
|
|
pglVertex3f( v[0], v[1], nv );
|
|
|
|
|
|
|
|
if( reverse )
|
|
|
|
v -= VERTEXSIZE;
|
|
|
|
else v += VERTEXSIZE;
|
|
|
|
}
|
|
|
|
|
2019-11-17 16:51:39 +01:00
|
|
|
if( !useQuads )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglEnd();
|
|
|
|
}
|
|
|
|
|
2019-11-17 16:51:39 +01:00
|
|
|
if( useQuads )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglEnd();
|
|
|
|
|
|
|
|
GL_SetupFogColorForSurfaces();
|
2019-02-18 19:25:26 +01:00
|
|
|
}
|
2023-10-30 04:25:28 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
============================================================
|
|
|
|
|
|
|
|
HALF-LIFE SOFTWARE WATER
|
|
|
|
|
|
|
|
============================================================
|
|
|
|
*/
|
|
|
|
void R_ResetRipples( void )
|
|
|
|
{
|
|
|
|
g_ripple.curbuf = g_ripple.buf[0];
|
|
|
|
g_ripple.oldbuf = g_ripple.buf[1];
|
|
|
|
g_ripple.time = g_ripple.oldtime = gpGlobals->time - 0.1;
|
|
|
|
memset( g_ripple.buf, 0, sizeof( g_ripple.buf ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_InitRipples( void )
|
|
|
|
{
|
|
|
|
rgbdata_t pic = { 0 };
|
|
|
|
|
|
|
|
pic.width = pic.height = RIPPLES_CACHEWIDTH;
|
|
|
|
pic.depth = 1;
|
|
|
|
pic.flags = IMAGE_HAS_COLOR;
|
|
|
|
pic.buffer = (byte *)g_ripple.texture;
|
|
|
|
pic.type = PF_RGBA_32;
|
|
|
|
pic.size = sizeof( g_ripple.texture );
|
|
|
|
pic.numMips = 1;
|
|
|
|
memset( pic.buffer, 0, pic.size );
|
|
|
|
|
|
|
|
g_ripple.rippletexturenum = GL_LoadTextureInternal( "*rippletex", &pic, TF_NOMIPMAP );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void R_SwapBufs( void )
|
|
|
|
{
|
|
|
|
short *tempbufp = g_ripple.curbuf;
|
|
|
|
g_ripple.curbuf = g_ripple.oldbuf;
|
|
|
|
g_ripple.oldbuf = tempbufp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void R_SpawnNewRipple( int x, int y, short val )
|
|
|
|
{
|
|
|
|
#define PIXEL( x, y ) ((( x ) & RIPPLES_CACHEWIDTH_MASK ) + ((( y ) & RIPPLES_CACHEWIDTH_MASK) << 7 ))
|
|
|
|
g_ripple.oldbuf[PIXEL( x, y )] += val;
|
|
|
|
|
|
|
|
val >>= 2;
|
|
|
|
g_ripple.oldbuf[PIXEL( x + 1, y )] += val;
|
|
|
|
g_ripple.oldbuf[PIXEL( x - 1, y )] += val;
|
|
|
|
g_ripple.oldbuf[PIXEL( x, y + 1 )] += val;
|
|
|
|
g_ripple.oldbuf[PIXEL( x, y - 1 )] += val;
|
|
|
|
#undef PIXEL
|
|
|
|
}
|
|
|
|
|
|
|
|
static void R_RunRipplesAnimation( const short *oldbuf, short *pbuf )
|
|
|
|
{
|
2023-10-31 02:24:46 +01:00
|
|
|
size_t i = 0;
|
|
|
|
const int w = RIPPLES_CACHEWIDTH;
|
|
|
|
const int m = RIPPLES_TEXSIZE_MASK;
|
2023-10-30 04:25:28 +01:00
|
|
|
|
2023-10-31 02:24:46 +01:00
|
|
|
for( i = w; i < m + w; i++, pbuf++ )
|
2023-10-30 04:25:28 +01:00
|
|
|
{
|
2023-10-31 02:24:46 +01:00
|
|
|
*pbuf = (
|
|
|
|
( (int)oldbuf[( i - ( w * 2 )) & m]
|
|
|
|
+ (int)oldbuf[( i - ( w + 1 )) & m]
|
|
|
|
+ (int)oldbuf[( i - ( w - 1 )) & m]
|
|
|
|
+ (int)oldbuf[( i ) & m]) >> 1 ) - (int)*pbuf;
|
2023-10-30 04:25:28 +01:00
|
|
|
|
2023-10-31 02:24:46 +01:00
|
|
|
*pbuf -= ( *pbuf >> 6 );
|
2023-10-30 04:25:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MostSignificantBit( unsigned int v )
|
|
|
|
{
|
|
|
|
#if __GNUC__
|
|
|
|
return 31 - __builtin_clz( v );
|
|
|
|
#else
|
|
|
|
int i;
|
|
|
|
for( i = 0, v >>= 1; v; v >>= 1, i++ );
|
|
|
|
return i;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_AnimateRipples( void )
|
|
|
|
{
|
|
|
|
double frametime = gpGlobals->time - g_ripple.time;
|
|
|
|
|
|
|
|
g_ripple.update = r_ripple.value && frametime >= r_ripple_updatetime.value;
|
|
|
|
|
|
|
|
if( !g_ripple.update )
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_ripple.time = gpGlobals->time;
|
|
|
|
|
|
|
|
R_SwapBufs();
|
|
|
|
|
|
|
|
if( g_ripple.time - g_ripple.oldtime > r_ripple_spawntime.value )
|
|
|
|
{
|
|
|
|
int x, y, val;
|
|
|
|
|
|
|
|
g_ripple.oldtime = g_ripple.time;
|
|
|
|
|
2023-10-30 05:47:13 +01:00
|
|
|
x = rand() & 0x7fff;
|
|
|
|
y = rand() & 0x7fff;
|
|
|
|
val = rand() & 0x3ff;
|
2023-10-30 04:25:28 +01:00
|
|
|
|
|
|
|
R_SpawnNewRipple( x, y, val );
|
|
|
|
}
|
|
|
|
|
|
|
|
R_RunRipplesAnimation( g_ripple.oldbuf, g_ripple.curbuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_UpdateRippleTexParams( void )
|
|
|
|
{
|
|
|
|
gl_texture_t *tex = R_GetTexture( g_ripple.rippletexturenum );
|
|
|
|
|
|
|
|
GL_Bind( XASH_TEXTURE0, g_ripple.rippletexturenum );
|
|
|
|
|
|
|
|
if( gl_texture_nearest.value )
|
|
|
|
{
|
|
|
|
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
|
|
|
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
|
|
|
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_UploadRipples( texture_t *image )
|
|
|
|
{
|
|
|
|
gl_texture_t *glt;
|
|
|
|
uint32_t *pixels;
|
2023-10-31 02:24:46 +01:00
|
|
|
int wbits, wmask, wshft;
|
2023-10-30 04:25:28 +01:00
|
|
|
|
|
|
|
// discard unuseful textures
|
|
|
|
if( !r_ripple.value || image->width > RIPPLES_CACHEWIDTH || image->width != image->height )
|
|
|
|
{
|
|
|
|
GL_Bind( XASH_TEXTURE0, image->gl_texturenum );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glt = R_GetTexture( image->gl_texturenum );
|
|
|
|
if( !glt || !glt->original || !glt->original->buffer || !FBitSet( glt->flags, TF_EXPAND_SOURCE ))
|
|
|
|
{
|
|
|
|
GL_Bind( XASH_TEXTURE0, image->gl_texturenum );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_Bind( XASH_TEXTURE0, g_ripple.rippletexturenum );
|
|
|
|
|
|
|
|
// no updates this frame
|
|
|
|
if( !g_ripple.update && image->gl_texturenum == g_ripple.gl_texturenum )
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_ripple.gl_texturenum = image->gl_texturenum;
|
2023-10-31 02:27:34 +01:00
|
|
|
if( r_ripple.value == 1.0f )
|
|
|
|
{
|
|
|
|
g_ripple.texturescale = Q_max( 1.0f, image->width / 64.0f );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_ripple.texturescale = 1.0f;
|
|
|
|
}
|
|
|
|
|
2023-10-30 04:25:28 +01:00
|
|
|
|
|
|
|
pixels = (uint32_t *)glt->original->buffer;
|
2023-10-31 02:24:46 +01:00
|
|
|
wbits = MostSignificantBit( image->width );
|
|
|
|
wshft = 7 - wbits;
|
2023-10-30 04:25:28 +01:00
|
|
|
wmask = image->width - 1;
|
|
|
|
|
2023-10-31 02:24:46 +01:00
|
|
|
for( int y = 0; y < image->height; y++ )
|
2023-10-30 04:25:28 +01:00
|
|
|
{
|
2023-10-31 02:24:46 +01:00
|
|
|
int ry = y << ( 7 + wshft );
|
2023-10-30 04:25:28 +01:00
|
|
|
|
2023-10-31 02:24:46 +01:00
|
|
|
for( int x = 0; x < image->width; x++ )
|
|
|
|
{
|
|
|
|
int rx = x << wshft;
|
|
|
|
int val = g_ripple.curbuf[ry + rx] >> 4;
|
|
|
|
|
|
|
|
int py = (y - val) & wmask;
|
|
|
|
int px = (x + val) & wmask;
|
|
|
|
int p = ( py << wbits ) + px;
|
|
|
|
|
|
|
|
g_ripple.texture[(y << wbits) + x] = pixels[p];
|
|
|
|
}
|
2023-10-30 04:25:28 +01:00
|
|
|
}
|
|
|
|
|
2023-10-31 02:24:46 +01:00
|
|
|
pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->width, 0,
|
2023-10-30 04:25:28 +01:00
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, g_ripple.texture );
|
|
|
|
}
|