Share R_SubdivideSurface between renders

This commit is contained in:
Denis Pauk 2023-10-07 23:00:21 +03:00
parent 4c4d244788
commit f3b2a9c4bf
14 changed files with 196 additions and 696 deletions

View file

@ -26,6 +26,8 @@
#include "../ref_shared.h"
#define SUBDIVIDE_SIZE 64.0f
/*
===============
R_TextureAnimation
@ -185,7 +187,7 @@ R_SetFrustum(vec3_t vup, vec3_t vpn, vec3_t vright, vec3_t r_origin,
}
}
void
static void
R_BoundPoly(int numverts, float *verts, vec3_t mins, vec3_t maxs)
{
int i, j;
@ -211,3 +213,173 @@ R_BoundPoly(int numverts, float *verts, vec3_t mins, vec3_t maxs)
}
}
}
static void
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
{
int i, j, k;
vec3_t mins, maxs;
float *v;
vec3_t front[64], back[64];
int f, b;
float dist[64];
float frac;
mpoly_t *poly;
vec3_t total;
float total_s, total_t;
vec3_t normal;
VectorCopy(warpface->plane->normal, normal);
if (numverts > 60)
{
Com_Error(ERR_DROP, "%s: numverts = %i", __func__, numverts);
}
R_BoundPoly(numverts, verts, mins, maxs);
for (i = 0; i < 3; i++)
{
float m;
m = (mins[i] + maxs[i]) * 0.5;
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
if (maxs[i] - m < 8)
{
continue;
}
if (m - mins[i] < 8)
{
continue;
}
/* cut it */
v = verts + i;
for (j = 0; j < numverts; j++, v += 3)
{
dist[j] = *v - m;
}
/* wrap cases */
dist[j] = dist[0];
v -= i;
VectorCopy(verts, v);
f = b = 0;
v = verts;
for (j = 0; j < numverts; j++, v += 3)
{
if (dist[j] >= 0)
{
VectorCopy(v, front[f]);
f++;
}
if (dist[j] <= 0)
{
VectorCopy(v, back[b]);
b++;
}
if ((dist[j] == 0) || (dist[j + 1] == 0))
{
continue;
}
if ((dist[j] > 0) != (dist[j + 1] > 0))
{
/* clip point */
frac = dist[j] / (dist[j] - dist[j + 1]);
for (k = 0; k < 3; k++)
{
front[f][k] = back[b][k] = v[k] + frac * (v[3 + k] - v[k]);
}
f++;
b++;
}
}
R_SubdividePolygon(f, front[0], warpface);
R_SubdividePolygon(b, back[0], warpface);
return;
}
/* add a point in the center to help keep warp valid */
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
poly->next = warpface->polys;
warpface->polys = poly;
poly->numverts = numverts + 2;
VectorClear(total);
total_s = 0;
total_t = 0;
for (i = 0; i < numverts; i++, verts += 3)
{
float s, t;
VectorCopy(verts, poly->verts[i + 1].pos);
s = DotProduct(verts, warpface->texinfo->vecs[0]);
t = DotProduct(verts, warpface->texinfo->vecs[1]);
total_s += s;
total_t += t;
VectorAdd(total, verts, total);
poly->verts[i + 1].texCoord[0] = s;
poly->verts[i + 1].texCoord[1] = t;
VectorCopy(normal, poly->verts[i + 1].normal);
poly->verts[i + 1].lightFlags = 0;
}
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
poly->verts[0].texCoord[0] = total_s / numverts;
poly->verts[0].texCoord[1] = total_t / numverts;
VectorCopy(normal, poly->verts[0].normal);
/* copy first vertex to last */
memcpy(&poly->verts[i + 1], &poly->verts[1], sizeof(mvtx_t));
}
/*
* Breaks a polygon up along axial 64 unit
* boundaries so that turbulent and sky warps
* can be done reasonably.
*/
void
R_SubdivideSurface(int *surfedges, mvertex_t *vertexes, medge_t *edges, msurface_t *fa)
{
vec3_t verts[64];
int numverts;
int i;
float *vec;
/* convert edges back to a normal polygon */
numverts = 0;
for (i = 0; i < fa->numedges; i++)
{
int lindex;
lindex = surfedges[fa->firstedge + i];
if (lindex > 0)
{
vec = vertexes[edges[lindex].v[0]].position;
}
else
{
vec = vertexes[edges[-lindex].v[1]].position;
}
VectorCopy(vec, verts[numverts]);
numverts++;
}
R_SubdividePolygon(numverts, verts[0], fa);
}

View file

@ -231,7 +231,7 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(gl3_3D_vtx_t)
@ -307,7 +307,7 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(gl3_3D_vtx_t)
@ -436,7 +436,8 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->texturemins[i] = -8192;
}
R_SubdivideSurface(loadmodel, out); /* cut up polygon for warps */
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); /* cut up polygon for warps */
}
if (r_fixsurfsky->value)
@ -561,7 +562,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->texturemins[i] = -8192;
}
R_SubdivideSurface(loadmodel, out); /* cut up polygon for warps */
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); /* cut up polygon for warps */
}
if (r_fixsurfsky->value)

View file

@ -27,7 +27,6 @@
#include "header/local.h"
#define TURBSCALE (256.0 / (2 * M_PI))
#define SUBDIVIDE_SIZE 64
#define ON_EPSILON 0.1 /* point on plane side epsilon */
#define MAX_CLIP_VERTS 64
@ -84,170 +83,6 @@ static int vec_to_st[6][3] = {
static float skymins[2][6], skymaxs[2][6];
static float sky_min, sky_max;
void
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
{
int i, j, k;
vec3_t mins, maxs;
float *v;
vec3_t front[64], back[64];
int f, b;
float dist[64];
float frac;
mpoly_t *poly;
vec3_t total;
float total_s, total_t;
if (numverts > 60)
{
Com_Error(ERR_DROP, "%s: numverts = %i", __func__, numverts);
}
R_BoundPoly(numverts, verts, mins, maxs);
for (i = 0; i < 3; i++)
{
float m;
m = (mins[i] + maxs[i]) * 0.5;
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
if (maxs[i] - m < 8)
{
continue;
}
if (m - mins[i] < 8)
{
continue;
}
/* cut it */
v = verts + i;
for (j = 0; j < numverts; j++, v += 3)
{
dist[j] = *v - m;
}
/* wrap cases */
dist[j] = dist[0];
v -= i;
VectorCopy(verts, v);
f = b = 0;
v = verts;
for (j = 0; j < numverts; j++, v += 3)
{
if (dist[j] >= 0)
{
VectorCopy(v, front[f]);
f++;
}
if (dist[j] <= 0)
{
VectorCopy(v, back[b]);
b++;
}
if ((dist[j] == 0) || (dist[j + 1] == 0))
{
continue;
}
if ((dist[j] > 0) != (dist[j + 1] > 0))
{
/* clip point */
frac = dist[j] / (dist[j] - dist[j + 1]);
for (k = 0; k < 3; k++)
{
front[f][k] = back[b][k] = v[k] + frac * (v[3 + k] - v[k]);
}
f++;
b++;
}
}
R_SubdividePolygon(f, front[0], warpface);
R_SubdividePolygon(b, back[0], warpface);
return;
}
/* add a point in the center to help keep warp valid */
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
poly->next = warpface->polys;
warpface->polys = poly;
poly->numverts = numverts + 2;
VectorClear(total);
total_s = 0;
total_t = 0;
for (i = 0; i < numverts; i++, verts += 3)
{
float s, t;
VectorCopy(verts, poly->verts[i + 1].pos);
s = DotProduct(verts, warpface->texinfo->vecs[0]);
t = DotProduct(verts, warpface->texinfo->vecs[1]);
total_s += s;
total_t += t;
VectorAdd(total, verts, total);
poly->verts[i + 1].texCoord[0] = s;
poly->verts[i + 1].texCoord[1] = t;
}
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
poly->verts[0].texCoord[0] = total_s / numverts;
poly->verts[0].texCoord[1] = total_t / numverts;
/* copy first vertex to last */
memcpy(&poly->verts[i + 1], &poly->verts[1], sizeof(mvtx_t));
}
/*
* Breaks a polygon up along axial 64 unit
* boundaries so that turbulent and sky warps
* can be done reasonably.
*/
void
R_SubdivideSurface(model_t *loadmodel, msurface_t *fa)
{
vec3_t verts[64];
int numverts;
int i;
float *vec;
/* convert edges back to a normal polygon */
numverts = 0;
for (i = 0; i < fa->numedges; i++)
{
int lindex;
lindex = loadmodel->surfedges[fa->firstedge + i];
if (lindex > 0)
{
vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
}
else
{
vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
}
VectorCopy(vec, verts[numverts]);
numverts++;
}
R_SubdividePolygon(numverts, verts[0], fa);
}
/*
* Does a water warp on the pre-fragmented mpoly_t chain
*/

View file

@ -251,7 +251,6 @@ void R_RenderDlights(void);
void R_DrawAlphaSurfaces(void);
void R_InitParticleTexture(void);
void Draw_InitLocal(void);
void R_SubdivideSurface(model_t *loadmodel, msurface_t *fa);
void R_RotateForEntity(entity_t *e);
void R_MarkLeaves(void);

View file

@ -182,9 +182,6 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
extern void
GL3_SubdivideSurface(msurface_t *fa, gl3model_t* loadmodel);
static int
calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl)
{
@ -231,7 +228,7 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
@ -307,7 +304,7 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
@ -419,7 +416,8 @@ Mod_LoadFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->texturemins[i] = -8192;
}
GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); /* cut up polygon for warps */
}
if (r_fixsurfsky->value)
@ -527,7 +525,8 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->texturemins[i] = -8192;
}
GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); /* cut up polygon for warps */
}
if (r_fixsurfsky->value)

View file

@ -27,176 +27,6 @@
#include "header/local.h"
static const float SUBDIVIDE_SIZE = 64.0f;
static void
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
{
int i, j, k;
vec3_t mins, maxs;
float m;
float *v;
vec3_t front[64], back[64];
int f, b;
float dist[64];
float frac;
mpoly_t *poly;
float s, t;
vec3_t total;
float total_s, total_t;
vec3_t normal;
VectorCopy(warpface->plane->normal, normal);
if (numverts > 60)
{
Com_Error(ERR_DROP, "numverts = %i", numverts);
}
R_BoundPoly(numverts, verts, mins, maxs);
for (i = 0; i < 3; i++)
{
m = (mins[i] + maxs[i]) * 0.5;
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
if (maxs[i] - m < 8)
{
continue;
}
if (m - mins[i] < 8)
{
continue;
}
/* cut it */
v = verts + i;
for (j = 0; j < numverts; j++, v += 3)
{
dist[j] = *v - m;
}
/* wrap cases */
dist[j] = dist[0];
v -= i;
VectorCopy(verts, v);
f = b = 0;
v = verts;
for (j = 0; j < numverts; j++, v += 3)
{
if (dist[j] >= 0)
{
VectorCopy(v, front[f]);
f++;
}
if (dist[j] <= 0)
{
VectorCopy(v, back[b]);
b++;
}
if ((dist[j] == 0) || (dist[j + 1] == 0))
{
continue;
}
if ((dist[j] > 0) != (dist[j + 1] > 0))
{
/* clip point */
frac = dist[j] / (dist[j] - dist[j + 1]);
for (k = 0; k < 3; k++)
{
front[f][k] = back[b][k] = v[k] + frac * (v[3 + k] - v[k]);
}
f++;
b++;
}
}
R_SubdividePolygon(f, front[0], warpface);
R_SubdividePolygon(b, back[0], warpface);
return;
}
/* add a point in the center to help keep warp valid */
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
poly->next = warpface->polys;
warpface->polys = poly;
poly->numverts = numverts + 2;
VectorClear(total);
total_s = 0;
total_t = 0;
for (i = 0; i < numverts; i++, verts += 3)
{
VectorCopy(verts, poly->verts[i + 1].pos);
s = DotProduct(verts, warpface->texinfo->vecs[0]);
t = DotProduct(verts, warpface->texinfo->vecs[1]);
total_s += s;
total_t += t;
VectorAdd(total, verts, total);
poly->verts[i + 1].texCoord[0] = s;
poly->verts[i + 1].texCoord[1] = t;
VectorCopy(normal, poly->verts[i + 1].normal);
poly->verts[i + 1].lightFlags = 0;
}
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
poly->verts[0].texCoord[0] = total_s / numverts;
poly->verts[0].texCoord[1] = total_t / numverts;
VectorCopy(normal, poly->verts[0].normal);
/* copy first vertex to last */
//memcpy(poly->verts[i + 1], poly->verts[1], sizeof(poly->verts[0]));
poly->verts[i + 1] = poly->verts[1];
}
/*
* Breaks a polygon up along axial 64 unit
* boundaries so that turbulent and sky warps
* can be done reasonably.
*/
void
GL3_SubdivideSurface(msurface_t *fa, gl3model_t* loadmodel)
{
vec3_t verts[64];
int numverts;
int i;
int lindex;
float *vec;
/* convert edges back to a normal polygon */
numverts = 0;
for (i = 0; i < fa->numedges; i++)
{
lindex = loadmodel->surfedges[fa->firstedge + i];
if (lindex > 0)
{
vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
}
else
{
vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
}
VectorCopy(vec, verts[numverts]);
numverts++;
}
R_SubdividePolygon(numverts, verts[0], fa);
}
/*
* Does a water warp on the pre-fragmented mpoly_t chain
*/

View file

@ -474,7 +474,6 @@ extern void GL3_LM_EndBuildingLightmaps(void);
// gl3_warp.c
extern void GL3_EmitWaterPolys(msurface_t *fa);
extern void GL3_SubdivideSurface(msurface_t *fa, gl3model_t* loadmodel);
extern void GL3_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis);
extern void GL3_DrawSkyBox(void);

View file

@ -180,9 +180,6 @@ Mod_LoadSubmodels(gl4model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
extern void
GL4_SubdivideSurface(msurface_t *fa, gl4model_t* loadmodel);
static int calcTexinfoAndFacesSize(byte *mod_base, const lump_t *fl, const lump_t *tl)
{
dface_t* face_in = (void *)(mod_base + fl->fileofs);
@ -228,7 +225,7 @@ static int calcTexinfoAndFacesSize(byte *mod_base, const lump_t *fl, const lump_
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// GL4_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
@ -333,7 +330,8 @@ Mod_LoadFaces(gl4model_t *loadmodel, byte *mod_base, lump_t *l)
out->texturemins[i] = -8192;
}
GL4_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); /* cut up polygon for warps */
}
if (r_fixsurfsky->value)

View file

@ -27,176 +27,6 @@
#include "header/local.h"
static const float SUBDIVIDE_SIZE = 64.0f;
static void
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
{
int i, j, k;
vec3_t mins, maxs;
float m;
float *v;
vec3_t front[64], back[64];
int f, b;
float dist[64];
float frac;
mpoly_t *poly;
float s, t;
vec3_t total;
float total_s, total_t;
vec3_t normal;
VectorCopy(warpface->plane->normal, normal);
if (numverts > 60)
{
Com_Error(ERR_DROP, "numverts = %i", numverts);
}
R_BoundPoly(numverts, verts, mins, maxs);
for (i = 0; i < 3; i++)
{
m = (mins[i] + maxs[i]) * 0.5;
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
if (maxs[i] - m < 8)
{
continue;
}
if (m - mins[i] < 8)
{
continue;
}
/* cut it */
v = verts + i;
for (j = 0; j < numverts; j++, v += 3)
{
dist[j] = *v - m;
}
/* wrap cases */
dist[j] = dist[0];
v -= i;
VectorCopy(verts, v);
f = b = 0;
v = verts;
for (j = 0; j < numverts; j++, v += 3)
{
if (dist[j] >= 0)
{
VectorCopy(v, front[f]);
f++;
}
if (dist[j] <= 0)
{
VectorCopy(v, back[b]);
b++;
}
if ((dist[j] == 0) || (dist[j + 1] == 0))
{
continue;
}
if ((dist[j] > 0) != (dist[j + 1] > 0))
{
/* clip point */
frac = dist[j] / (dist[j] - dist[j + 1]);
for (k = 0; k < 3; k++)
{
front[f][k] = back[b][k] = v[k] + frac * (v[3 + k] - v[k]);
}
f++;
b++;
}
}
R_SubdividePolygon(f, front[0], warpface);
R_SubdividePolygon(b, back[0], warpface);
return;
}
/* add a point in the center to help keep warp valid */
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
poly->next = warpface->polys;
warpface->polys = poly;
poly->numverts = numverts + 2;
VectorClear(total);
total_s = 0;
total_t = 0;
for (i = 0; i < numverts; i++, verts += 3)
{
VectorCopy(verts, poly->verts[i + 1].pos);
s = DotProduct(verts, warpface->texinfo->vecs[0]);
t = DotProduct(verts, warpface->texinfo->vecs[1]);
total_s += s;
total_t += t;
VectorAdd(total, verts, total);
poly->verts[i + 1].texCoord[0] = s;
poly->verts[i + 1].texCoord[1] = t;
VectorCopy(normal, poly->verts[i + 1].normal);
poly->verts[i + 1].lightFlags = 0;
}
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
poly->verts[0].texCoord[0] = total_s / numverts;
poly->verts[0].texCoord[1] = total_t / numverts;
VectorCopy(normal, poly->verts[0].normal);
/* copy first vertex to last */
//memcpy(poly->verts[i + 1], poly->verts[1], sizeof(poly->verts[0]));
poly->verts[i + 1] = poly->verts[1];
}
/*
* Breaks a polygon up along axial 64 unit
* boundaries so that turbulent and sky warps
* can be done reasonably.
*/
void
GL4_SubdivideSurface(msurface_t *fa, gl4model_t* loadmodel)
{
vec3_t verts[64];
int numverts;
int i;
int lindex;
float *vec;
/* convert edges back to a normal polygon */
numverts = 0;
for (i = 0; i < fa->numedges; i++)
{
lindex = loadmodel->surfedges[fa->firstedge + i];
if (lindex > 0)
{
vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
}
else
{
vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
}
VectorCopy(vec, verts[numverts]);
numverts++;
}
R_SubdividePolygon(numverts, verts[0], fa);
}
/*
* Does a water warp on the pre-fragmented mpoly_t chain
*/

View file

@ -474,7 +474,6 @@ extern void GL4_LM_EndBuildingLightmaps(void);
// gl4_warp.c
extern void GL4_EmitWaterPolys(msurface_t *fa);
extern void GL4_SubdivideSurface(msurface_t *fa, gl4model_t* loadmodel);
extern void GL4_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis);
extern void GL4_DrawSkyBox(void);

View file

@ -374,7 +374,8 @@ extern qboolean R_AreaVisible(const byte *areabits, mleaf_t *pleaf);
extern qboolean R_CullBox(vec3_t mins, vec3_t maxs, cplane_t *frustum);
extern void R_SetFrustum(vec3_t vup, vec3_t vpn, vec3_t vright, vec3_t r_origin,
float fov_x, float fov_y, cplane_t *frustum);
extern void R_BoundPoly(int numverts, float *verts, vec3_t mins, vec3_t maxs);
extern void R_SubdivideSurface(int *surfedges, mvertex_t *vertexes, medge_t *edges,
msurface_t *fa);
/* Lights logic */
extern bspxlightgrid_t *Mod_LoadBSPXLightGrid(const bspx_header_t *bspx_header, const byte *mod_base);

View file

@ -197,7 +197,6 @@ void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
void R_DrawAlphaSurfaces(void);
void RE_InitParticleTexture(void);
void Draw_InitLocal(void);
void Vk_SubdivideSurface(msurface_t *fa, model_t *loadmodel);
void R_RotateForEntity(entity_t *e, float *mvMatrix);
void R_MarkLeaves(void);

View file

@ -201,7 +201,7 @@ calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// Vk_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t)
@ -277,7 +277,7 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t
if (numverts > 60)
return 0; // will error out in R_SubdividePolygon()
// GL3_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */
// for each (pot. recursive) call to R_SubdividePolygon():
// sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(gl3_3D_vtx_t)
@ -406,7 +406,8 @@ Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->texturemins[i] = -8192;
}
Vk_SubdivideSurface(out, loadmodel); // cut up polygon for warps
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); // cut up polygon for warps
}
if (r_fixsurfsky->value)
@ -531,7 +532,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l,
out->texturemins[i] = -8192;
}
Vk_SubdivideSurface(out, loadmodel); // cut up polygon for warps
R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes,
loadmodel->edges, out); // cut up polygon for warps
}
if (r_fixsurfsky->value)

View file

@ -27,7 +27,6 @@
#include "header/local.h"
#define SUBDIVIDE_SIZE 64
#define ON_EPSILON 0.1 /* point on plane side epsilon */
#define MAX_CLIP_VERTS 64
@ -71,170 +70,6 @@ static int vec_to_st[6][3] = {
static float skymins[2][6], skymaxs[2][6];
static float sky_min, sky_max;
static void
R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
{
int i, j, k;
vec3_t mins, maxs;
float *v;
vec3_t front[64], back[64];
int f, b;
float dist[64];
float frac;
mpoly_t *poly;
vec3_t total;
float total_s, total_t;
if (numverts > 60)
{
Com_Error(ERR_DROP, "%s: numverts = %i", __func__, numverts);
}
R_BoundPoly(numverts, verts, mins, maxs);
for (i = 0; i < 3; i++)
{
float m;
m = (mins[i] + maxs[i]) * 0.5;
m = SUBDIVIDE_SIZE * floor(m / SUBDIVIDE_SIZE + 0.5);
if (maxs[i] - m < 8)
{
continue;
}
if (m - mins[i] < 8)
{
continue;
}
/* cut it */
v = verts + i;
for (j = 0; j < numverts; j++, v += 3)
{
dist[j] = *v - m;
}
/* wrap cases */
dist[j] = dist[0];
v -= i;
VectorCopy(verts, v);
f = b = 0;
v = verts;
for (j = 0; j < numverts; j++, v += 3)
{
if (dist[j] >= 0)
{
VectorCopy(v, front[f]);
f++;
}
if (dist[j] <= 0)
{
VectorCopy(v, back[b]);
b++;
}
if ((dist[j] == 0) || (dist[j + 1] == 0))
{
continue;
}
if ((dist[j] > 0) != (dist[j + 1] > 0))
{
/* clip point */
frac = dist[j] / (dist[j] - dist[j + 1]);
for (k = 0; k < 3; k++)
{
front[f][k] = back[b][k] = v[k] + frac * (v[3 + k] - v[k]);
}
f++;
b++;
}
}
R_SubdividePolygon(f, front[0], warpface);
R_SubdividePolygon(b, back[0], warpface);
return;
}
/* add a point in the center to help keep warp valid */
poly = Hunk_Alloc(sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t));
poly->next = warpface->polys;
warpface->polys = poly;
poly->numverts = numverts + 2;
VectorClear(total);
total_s = 0;
total_t = 0;
for (i = 0; i < numverts; i++, verts += 3)
{
float s, t;
VectorCopy(verts, poly->verts[i + 1].pos);
s = DotProduct(verts, warpface->texinfo->vecs[0]);
t = DotProduct(verts, warpface->texinfo->vecs[1]);
total_s += s;
total_t += t;
VectorAdd(total, verts, total);
poly->verts[i + 1].texCoord[0] = s;
poly->verts[i + 1].texCoord[1] = t;
}
VectorScale(total, (1.0 / numverts), poly->verts[0].pos);
poly->verts[0].texCoord[0] = total_s / numverts;
poly->verts[0].texCoord[1] = total_t / numverts;
/* copy first vertex to last */
memcpy(&poly->verts[i + 1], &poly->verts[1], sizeof(mvtx_t));
}
/*
* Breaks a polygon up along axial 64 unit
* boundaries so that turbulent and sky warps
* can be done reasonably.
*/
void
Vk_SubdivideSurface (msurface_t *fa, model_t *loadmodel)
{
vec3_t verts[64];
int numverts;
int i;
float *vec;
/* convert edges back to a normal polygon */
numverts = 0;
for (i = 0; i < fa->numedges; i++)
{
int lindex;
lindex = loadmodel->surfedges[fa->firstedge + i];
if (lindex > 0)
{
vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
}
else
{
vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
}
VectorCopy(vec, verts[numverts]);
numverts++;
}
R_SubdividePolygon(numverts, verts[0], fa);
}
/*
* Does a water warp on the pre-fragmented mpoly_t chain
*/