use actual view to clip segs in ogl instead of calculated fov

thx dsda-doom!
basically better performance in alot of cases and technically should fix any future issues if someone plays on weird aspect ratios
This commit is contained in:
Alug 2024-11-19 17:28:36 +01:00
parent 67ea1fdc04
commit a09bde5364
5 changed files with 28 additions and 32 deletions

View file

@ -79,12 +79,6 @@
#include "r_opengl/r_opengl.h"
#include "../r_main.h" // for cv_fov
#ifdef HAVE_SPHEREFRUSTRUM
static GLdouble viewMatrix[16];
static GLdouble projMatrix[16];
float frustum[6][4];
#endif
typedef struct clipnode_s
{
struct clipnode_s *prev, *next;
@ -322,16 +316,14 @@ void gld_clipper_Clear(void)
#define RMUL (1.6f/1.333333f)
angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle)
angle_t gld_FrustumAngle(angle_t tiltangle)
{
double clipfov;
double floatangle;
angle_t a1;
float tilt = (float)fabs(((double)(int)tiltangle) / ANG1);
float render_fovratio = (float)BASEVIDWIDTH / (float)BASEVIDHEIGHT; // SRB2CBTODO: NEWCLIPTODO: Is this right?
float render_multiplier = 64.0f / render_fovratio / RMUL;
if (tilt > 90.0f)
tilt = 90.0f;
@ -341,10 +333,11 @@ angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle)
// ok, this is a gross hack that barely works...
// but at least it doesn't overestimate too much...
floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * (float)render_fov * 48.0f / render_multiplier / 90.0f;
a1 = ANG1 * (int)floatangle;
if (a1 >= ANGLE_180)
clipfov = atan(1 / projMatrix[0]) * 360 / M_PI; // use the actual view of the scene
floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * clipfov / 90.0f;
if (floatangle >= ANGLE_180)
return 0xffffffff;
a1 = (angle_t)(ANG1 * (int)floatangle);
return a1;
}
@ -357,6 +350,10 @@ angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle)
// gld_FrustrumSetup
//
static GLdouble viewMatrix[16];
static GLdouble projMatrix[16];
float frustum[6][4];
#define CALCMATRIX(a, b, c, d, e, f, g, h)\
(float)(viewMatrix[a] * projMatrix[b] + \
viewMatrix[c] * projMatrix[d] + \

View file

@ -24,7 +24,7 @@ extern "C" {
boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle);
void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle);
void gld_clipper_Clear(void);
angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle);
angle_t gld_FrustumAngle(angle_t tiltangle);
#ifdef HAVE_SPHEREFRUSTRUM
void gld_FrustrumSetup(void);
boolean gld_SphereInFrustum(float x, float y, float z, float radius);

View file

@ -5901,6 +5901,16 @@ static void HWR_SetShaderState(void)
HWD.pfnSetShader(SHADER_DEFAULT);
}
static void HWR_ClearClipper(void)
{
angle_t a1 = gld_FrustumAngle(gl_aimingangle);
gld_clipper_Clear();
gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1);
#ifdef HAVE_SPHEREFRUSTRUM
gld_FrustrumSetup();
#endif
}
// ==========================================================================
// Same as rendering the player view, but from the skybox object
// ==========================================================================
@ -5985,19 +5995,12 @@ void HWR_RenderSkyboxView(player_t *player)
drawcount = 0;
{
angle_t a1 = gld_FrustumAngle(fpov, gl_aimingangle);
gld_clipper_Clear();
gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1);
#ifdef HAVE_SPHEREFRUSTRUM
gld_FrustrumSetup();
#endif
}
//04/01/2000: Hurdler: added for T&L
// Actually it only works on Walls and Planes
HWD.pfnSetTransform(&atransform);
HWR_ClearClipper();
// Reset the shader state.
HWR_SetShaderState();
@ -6167,18 +6170,12 @@ void HWR_RenderPlayerView(void)
drawcount = 0;
{
angle_t a1 = gld_FrustumAngle(fpov, gl_aimingangle);
gld_clipper_Clear();
gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1);
#ifdef HAVE_SPHEREFRUSTRUM
gld_FrustrumSetup();
#endif
}
//04/01/2000: Hurdler: added for T&L
// Actually it only works on Walls and Planes
HWD.pfnSetTransform(&atransform);
HWR_ClearClipper();
// Reset the shader state.
HWR_SetShaderState();

View file

@ -86,7 +86,7 @@ const GLubyte *gl_extensions = NULL;
//Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-)
static GLfloat modelMatrix[16];
static GLfloat projMatrix[16];
GLfloat projMatrix[16];
static GLint viewport[4];
// Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing

View file

@ -73,6 +73,8 @@ extern "C" {
extern FILE *gllogstream;
#endif
extern GLfloat projMatrix[16];
// ==========================================================================
// PROTOS
// ==========================================================================