Fix visibility in Polymer with r_usenewshading 4 and palette emulation off.

Move some visibility-related constants from Polymer "core" code elsewhere.

Patch from Fox.

git-svn-id: https://svn.eduke32.com/eduke32@6590 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2018-01-26 04:35:06 +00:00
parent 1e04f43240
commit 392d5fc942
3 changed files with 30 additions and 16 deletions

View file

@ -7950,9 +7950,13 @@ int32_t drawrooms(int32_t daposx, int32_t daposy, int32_t daposz,
# ifdef POLYMER # ifdef POLYMER
case REND_POLYMER: case REND_POLYMER:
if (r_usenewshading == 4) if (r_usenewshading == 4)
globalvisibility = g_visibility; globalvisibility = g_visibility<<5;
else if (r_usenewshading > 1)
/* 0.65127==150/230, another constant found out by experiment. :/
* (150 is Polymost's old FOGDISTCONST.) */
globalvisibility = (g_visibility<<2) * 150 / (230 * 35);
else else
globalvisibility = g_visibility<<2; globalvisibility = (g_visibility<<2) / 35;
break; break;
# endif # endif
#endif #endif

View file

@ -326,11 +326,7 @@ static const _prprogrambit prprogrambits[PR_BIT_COUNT] = {
"\n", "\n",
// frag_prog // frag_prog
// NOTE: the denominator was 1.024, but we increase it towards a bit " float shadeLookup = length(horizDistance) / 1.024 * visibility;\n"
// farther far clipoff distance to account for the fact that the
// distance to the fragment is the common Euclidean one, as opposed to
// the "ortho" distance of Build.
" float shadeLookup = length(horizDistance) / 1.07 * visibility;\n"
" shadeLookup = shadeLookup + shadeOffset;\n" " shadeLookup = shadeLookup + shadeOffset;\n"
"\n" "\n"
" float colorIndex = texture2D(artMap, commonTexCoord.st).r * 256.0;\n" " float colorIndex = texture2D(artMap, commonTexCoord.st).r * 256.0;\n"
@ -497,17 +493,15 @@ static const _prprogrambit prprogrambits[PR_BIT_COUNT] = {
" float fragDepth;\n" " float fragDepth;\n"
" float fogFactor;\n" " float fogFactor;\n"
"\n" "\n"
" fragDepth = gl_FragCoord.z / gl_FragCoord.w / 35.0;\n" " fragDepth = gl_FragCoord.z / gl_FragCoord.w;\n"
#ifdef PR_LINEAR_FOG #ifdef PR_LINEAR_FOG
" if (!linearFog) {\n" " if (!linearFog) {\n"
#endif #endif
" fragDepth *= fragDepth;\n" " fragDepth *= fragDepth;\n"
" fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fragDepth * 1.442695);\n" " fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fragDepth * 1.442695);\n"
#ifdef PR_LINEAR_FOG #ifdef PR_LINEAR_FOG
/* 0.65127==150/230, another constant found out by experiment. :/
* (150 is Polymost's old FOGDISTCONST.) */
" } else {\n" " } else {\n"
" fogFactor = gl_Fog.scale * (gl_Fog.end - fragDepth*0.65217);\n" " fogFactor = gl_Fog.scale * (gl_Fog.end - fragDepth);\n"
" fogFactor = clamp(fogFactor, 0.0, 1.0);" " fogFactor = clamp(fogFactor, 0.0, 1.0);"
" }\n" " }\n"
#endif #endif
@ -4970,7 +4964,7 @@ static _prbucket* polymer_getbuildmaterial(_prmaterial* material, int16_t tile
} }
material->shadeoffset = shade; material->shadeoffset = shade;
material->visibility = ((uint8_t) (vis+16) / 16.0f); material->visibility = (uint8_t)(vis+16);
// all the stuff below is mutually exclusive with artmapping // all the stuff below is mutually exclusive with artmapping
goto done; goto done;
@ -5265,9 +5259,25 @@ static int32_t polymer_bindmaterial(const _prmaterial *material, int16_t* l
texunit++; texunit++;
bglUniform1fARB(prprograms[programbits].uniform_shadeOffset, (GLfloat)material->shadeoffset); bglUniform1fARB(prprograms[programbits].uniform_shadeOffset, (GLfloat)material->shadeoffset);
// the furthest visible point is the same as Polymost, however the fog in Polymer is a sphere insted of a plane if (r_usenewshading == 4)
float const visfactor = r_usenewshading == 4 ? 1.f/512.f : 1.f/2048.f; {
bglUniform1fARB(prprograms[programbits].uniform_visibility, globalvisibility * visfactor * material->visibility); // the fog in Polymer is a sphere insted of a plane, the furthest visible point should be the same as Polymost
bglUniform1fARB(prprograms[programbits].uniform_visibility, globalvisibility / 262144.f * material->visibility);
}
else
{
static constexpr float material_visibility_divisor = 16.f;
// NOTE: the denominator was 1.024, but we increase it towards a bit
// farther far clipoff distance to account for the fact that the
// distance to the fragment is the common Euclidean one, as opposed to
// the "ortho" distance of Build.
static constexpr float factor_new = 1.f / ((2048.f * (1.07f / 1.024f) * (150.f / 230.f) / 35.f) * material_visibility_divisor);
static constexpr float factor_old = 1.f / ((2048.f * (1.07f / 1.024f) / 35.f) * material_visibility_divisor);
bglUniform1fARB(prprograms[programbits].uniform_visibility, globalvisibility * material->visibility * r_usenewshading > 1 ? factor_new : factor_old);
}
} }
// PR_BIT_DIFFUSE_MAP // PR_BIT_DIFFUSE_MAP

View file

@ -494,7 +494,7 @@ void calc_and_apply_fog(int32_t tile, int32_t shade, int32_t vis, int32_t pal)
fogresult2 = -GL_FOG_MAX; // hide fog behind the camera fogresult2 = -GL_FOG_MAX; // hide fog behind the camera
fogcol = fogtable[pal]; fogcol = fogtable[pal];
if (((uint8_t)(vis + 16)) > 0 && g_visibility > 0) if (((uint8_t)(vis + 16)) > 0 && globalvisibility > 0)
{ {
GLfloat glfogconstant = 262144.f; GLfloat glfogconstant = 262144.f;
GLfloat fogrange = (frealmaxshade * glfogconstant) / (((uint8_t)(vis + 16)) * globalvisibility); GLfloat fogrange = (frealmaxshade * glfogconstant) / (((uint8_t)(vis + 16)) * globalvisibility);