- switched NPOT emulation to the renamed uniforms.

This was the last feature that needed to be mapped to a GZDoom compatible render state
This commit is contained in:
Christoph Oelckers 2020-06-08 08:16:50 +02:00
parent 5cbe9fc49c
commit 17e1e4175e
7 changed files with 22 additions and 20 deletions

View file

@ -135,9 +135,8 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char
if (tempindex != -1) glUniformBlockBinding(hShader, tempindex, VIEWPOINT_BINDINGPOINT);
Flags.Init(hShader, "u_flags");
NPOTEmulationFactor.Init(hShader, "u_npotEmulationFactor");
NPOTEmulationXOffset.Init(hShader, "u_npotEmulationXOffset");
NPOTEmulation.Init(hShader, "uNpotEmulation");
TextureMode.Init(hShader, "uTextureMode");
FogColor.Init(hShader, "uFogColor");
muFogEnabled.Init(hShader, "uFogEnabled");

View file

@ -27,9 +27,8 @@ class PolymostShader : public FShader
{
public:
FBufferedUniform1i Flags;
FBufferedUniform1f NPOTEmulationFactor;
FBufferedUniform1f NPOTEmulationXOffset;
FBufferedUniformPalEntry FogColor;
FBufferedUniform2f NPOTEmulation;
FBufferedUniformPalEntry FogColor;
FBufferedUniform1i TextureMode;
FBufferedUniform4f DetailParms;

View file

@ -138,6 +138,7 @@ auto i_data = R"(
uniform int uFogEnabled;
uniform vec4 uFogColor;
uniform int uTextureMode;
uniform vec2 uNpotEmulation;
)";
@ -543,8 +544,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState& oldState)
shader->Flags.Set(Flags);
shader->TextureMode.Set(LayerFlags);
shader->NPOTEmulationFactor.Set(NPOTEmulationFactor);
shader->NPOTEmulationXOffset.Set(NPOTEmulationXOffset);
shader->NPOTEmulation.Set(&NPOTEmulation.X);
shader->AlphaThreshold.Set(AlphaTest ? AlphaThreshold : -1.f);
shader->FogColor.Set((Flags& RF_MapFog)? PalEntry(0x999999) : FogColor);
float lightattr[] = { ShadeDiv / (numshades - 2), VisFactor, (Flags & RF_MapFog) ? -5.f : 0.f , ShadeDiv >= 1 / 1000.f? Shade : 0 };

View file

@ -391,8 +391,8 @@ public:
void SetNpotEmulation(float factor, float xOffset)
{
renderState.NPOTEmulationFactor = factor;
renderState.NPOTEmulationXOffset = xOffset;
renderState.NPOTEmulation.Y = factor;
renderState.NPOTEmulation.X = xOffset;
}
void SetShadeInterpolate(int32_t yes)

View file

@ -55,8 +55,7 @@ struct PolymostRenderState
float VisFactor = 128.f;
int Flags = 0;
int LayerFlags = 0;
float NPOTEmulationFactor = 1.f;
float NPOTEmulationXOffset;
FVector2 NPOTEmulation = { 0.f, 0.f };
float AlphaThreshold = 0.5f;
bool AlphaTest = true;
float Color[4] = { 1,1,1,1 };

View file

@ -33,9 +33,6 @@ uniform sampler2D s_palette;
uniform int u_flags;
uniform float u_npotEmulationFactor;
uniform float u_npotEmulationXOffset;
in vec4 v_color;
in float v_distance;
in vec4 v_texCoord;
@ -161,12 +158,12 @@ void main()
float coordY = v_texCoord.y;
vec2 newCoord;
// Coordinate adjustment for NPOT textures (something must have gone very wrong to make this necessary...)
if (u_npotEmulationFactor != 0.0)
// Coordinate adjustment for NPOT textures. It is somehow fitting that Build games exploited this texture wrapping quirk of the software rendering engine...
if (uNpotEmulation.y != 0.0)
{
float period = floor(coordY / u_npotEmulationFactor);
coordX += u_npotEmulationXOffset * floor(mod(coordY, u_npotEmulationFactor));
coordY = period + mod(coordY, u_npotEmulationFactor);
float period = floor(coordY / uNpotEmulation.y);
coordX += uNpotEmulation.x * floor(mod(coordY, uNpotEmulation.y));
coordY = period + mod(coordY, uNpotEmulation.y);
}
newCoord = vec2(coordX, coordY);

View file

@ -540,6 +540,14 @@ vec3 ApplyNormalMap(vec2 texcoord)
void SetMaterialProps(inout Material material, vec2 texCoord)
{
#ifdef NPOT_EMULATION
if (uNpotEmulation.y != 0.0)
{
float period = floor(texCoord.t / uNpotEmulation.y);
texCoord.s += uNpotEmulation.x * floor(mod(texCoord.t, uNpotEmulation.y));
texCoord.t = period + mod(texCoord.t, uNpotEmulation.y);
}
#endif
material.Base = getTexel(texCoord.st);
material.Normal = ApplyNormalMap(texCoord.st);