mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 06:53:58 +00:00
- Slightly improve sky rendering in softpoly
This commit is contained in:
parent
bb12dabe2b
commit
5c1dc900e3
2 changed files with 97 additions and 23 deletions
|
@ -37,31 +37,32 @@ PolySkyDome::PolySkyDome()
|
|||
|
||||
void PolySkyDome::Render(const TriMatrix &worldToClip)
|
||||
{
|
||||
#ifdef USE_GL_DOME_MATH
|
||||
TriMatrix modelMatrix = GLSkyMath();
|
||||
#else
|
||||
TriMatrix modelMatrix = TriMatrix::identity();
|
||||
|
||||
PolySkySetup frameSetup;
|
||||
frameSetup.Update();
|
||||
|
||||
if (frameSetup != mCurrentSetup)
|
||||
{
|
||||
double frontTexWidth = (double)frameSetup.frontskytex->GetWidth();
|
||||
float scaleFrontU = (float)(frameSetup.frontcyl / frontTexWidth);
|
||||
if (frameSetup.skyflip)
|
||||
scaleFrontU = -scaleFrontU;
|
||||
// frontcyl = pixels for full 360 degrees, front texture
|
||||
// backcyl = pixels for full 360 degrees, back texture
|
||||
// skymid = Y scaled pixel offset
|
||||
// sky1pos = unscaled X offset, front
|
||||
// sky2pos = unscaled X offset, back
|
||||
// frontpos = scaled X pixel offset (fixed point)
|
||||
// backpos = scaled X pixel offset (fixed point)
|
||||
// skyflip = flip X direction
|
||||
|
||||
float baseOffset = (float)(frameSetup.skyangle / 65536.0 / frontTexWidth);
|
||||
float offsetFrontU = baseOffset * scaleFrontU + (float)(frameSetup.frontpos / 65536.0 / frontTexWidth);
|
||||
float scaleBaseV = 1.42f;
|
||||
float offsetBaseV = 0.25f;
|
||||
|
||||
float scaleFrontV = (float)(frameSetup.frontskytex->Scale.Y * 1.6);
|
||||
float offsetFrontV;
|
||||
|
||||
// BTSX
|
||||
/*{
|
||||
offsetFrontU += 0.5f;
|
||||
offsetFrontV = (float)((28.0f - frameSetup.skymid) / frameSetup.frontskytex->GetHeight());
|
||||
}*/
|
||||
// E1M1
|
||||
{
|
||||
offsetFrontV = (float)((28.0f + frameSetup.skymid) / frameSetup.frontskytex->GetHeight());
|
||||
}
|
||||
float scaleFrontU = frameSetup.frontcyl / (float)frameSetup.frontskytex->GetWidth();
|
||||
float scaleFrontV = (float)frameSetup.frontskytex->Scale.Y * scaleBaseV;
|
||||
float offsetFrontU = (float)(frameSetup.frontpos / 65536.0 / frameSetup.frontskytex->GetWidth());
|
||||
float offsetFrontV = (float)((frameSetup.skymid / frameSetup.frontskytex->GetHeight() + offsetBaseV) * scaleBaseV);
|
||||
|
||||
unsigned int count = mVertices.Size();
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
|
@ -72,9 +73,10 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
|
|||
|
||||
mCurrentSetup = frameSetup;
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
TriMatrix objectToWorld = TriMatrix::translate((float)viewpoint.Pos.X, (float)viewpoint.Pos.Y, (float)viewpoint.Pos.Z);
|
||||
TriMatrix objectToWorld = TriMatrix::translate((float)viewpoint.Pos.X, (float)viewpoint.Pos.Y, (float)viewpoint.Pos.Z) * modelMatrix;
|
||||
objectToClip = worldToClip * objectToWorld;
|
||||
|
||||
int rc = mRows + 1;
|
||||
|
@ -203,6 +205,80 @@ void PolySkyDome::SkyVertex(int r, int c, bool zflip)
|
|||
mInitialUV.Push({ vert.u, vert.v });
|
||||
}
|
||||
|
||||
TriMatrix PolySkyDome::GLSkyMath()
|
||||
{
|
||||
PolySkySetup frameSetup;
|
||||
frameSetup.Update();
|
||||
mCurrentSetup = frameSetup;
|
||||
|
||||
float x_offset = 0.0f;
|
||||
float y_offset = 0.0f;
|
||||
bool mirror = false;
|
||||
FTexture *tex = mCurrentSetup.frontskytex;
|
||||
float skyoffset = 0.0f; // skyoffset debugging CVAR in GL renderer
|
||||
|
||||
int texh = 0;
|
||||
int texw = 0;
|
||||
|
||||
// 57 world units roughly represent one sky texel for the glTranslate call.
|
||||
const float skyoffsetfactor = 57;
|
||||
|
||||
TriMatrix modelMatrix = TriMatrix::identity();
|
||||
if (tex)
|
||||
{
|
||||
texw = tex->GetWidth();
|
||||
texh = tex->GetHeight();
|
||||
|
||||
modelMatrix = TriMatrix::rotate(-180.0f + x_offset, 0.f, 0.f, 1.f);
|
||||
|
||||
float xscale = texw < 1024.f ? floor(1024.f / float(texw)) : 1.f;
|
||||
float yscale = 1.f;
|
||||
if (texh <= 128 && (level.flags & LEVEL_FORCETILEDSKY))
|
||||
{
|
||||
modelMatrix = modelMatrix * TriMatrix::translate(0.f, 0.f, (-40 + tex->SkyOffset + skyoffset)*skyoffsetfactor);
|
||||
modelMatrix = modelMatrix * TriMatrix::scale(1.f, 1.f, 1.2f * 1.17f);
|
||||
yscale = 240.f / texh;
|
||||
}
|
||||
else if (texh < 128)
|
||||
{
|
||||
// smaller sky textures must be tiled. We restrict it to 128 sky pixels, though
|
||||
modelMatrix = modelMatrix * TriMatrix::translate(0.f, 0.f, -1250.f);
|
||||
modelMatrix = modelMatrix * TriMatrix::scale(1.f, 1.f, 128 / 230.f);
|
||||
yscale = (float)(128 / texh); // intentionally left as integer.
|
||||
}
|
||||
else if (texh < 200)
|
||||
{
|
||||
modelMatrix = modelMatrix * TriMatrix::translate(0.f, 0.f, -1250.f);
|
||||
modelMatrix = modelMatrix * TriMatrix::scale(1.f, 1.f, texh / 230.f);
|
||||
}
|
||||
else if (texh <= 240)
|
||||
{
|
||||
modelMatrix = modelMatrix * TriMatrix::translate(0.f, 0.f, (200 - texh + tex->SkyOffset + skyoffset)*skyoffsetfactor);
|
||||
modelMatrix = modelMatrix * TriMatrix::scale(1.f, 1.f, 1.f + ((texh - 200.f) / 200.f) * 1.17f);
|
||||
}
|
||||
else
|
||||
{
|
||||
modelMatrix = modelMatrix * TriMatrix::translate(0.f, 0.f, (-40 + tex->SkyOffset + skyoffset)*skyoffsetfactor);
|
||||
modelMatrix = modelMatrix * TriMatrix::scale(1.f, 1.f, 1.2f * 1.17f);
|
||||
yscale = 240.f / texh;
|
||||
}
|
||||
|
||||
float offsetU = 1.0f;
|
||||
float offsetV = y_offset / texh;
|
||||
float scaleU = mirror ? -xscale : xscale;
|
||||
float scaleV = yscale;
|
||||
|
||||
unsigned int count = mVertices.Size();
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
mVertices[i].u = offsetU + mInitialUV[i].X * scaleU;
|
||||
mVertices[i].v = offsetV + mInitialUV[i].Y * scaleV;
|
||||
}
|
||||
}
|
||||
|
||||
return modelMatrix;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void PolySkySetup::Update()
|
||||
|
@ -291,10 +367,6 @@ void PolySkySetup::Update()
|
|||
|
||||
int frontxscale = int(frontskytex->Scale.X * 1024);
|
||||
frontcyl = MAX(frontskytex->GetWidth(), frontxscale);
|
||||
if (skystretch)
|
||||
{
|
||||
skymid = skymid * frontskytex->GetScaledHeightDouble() / SKYSTRETCH_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
frontpos = int(fmod(frontdpos, sky1cyl * 65536.0));
|
||||
|
|
|
@ -63,5 +63,7 @@ private:
|
|||
|
||||
TriVertex SetVertexXYZ(float xx, float yy, float zz, float uu = 0, float vv = 0);
|
||||
|
||||
TriMatrix GLSkyMath();
|
||||
|
||||
PolySkySetup mCurrentSetup;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue