- cleanup of the revised y-clamping feature.

This integrates better with the existing features.
This commit is contained in:
Christoph Oelckers 2021-09-21 18:23:52 +02:00
parent 6e2aef617c
commit da806b354d
9 changed files with 32 additions and 25 deletions

View File

@ -51,12 +51,10 @@ enum ETexMode
TM_OPAQUE, // (r, g, b, 1)
TM_INVERSE, // (1-r, 1-g, 1-b, a)
TM_ALPHATEXTURE, // (1, 1, 1, r)
TM_INVERTOPAQUE = 6, // (1-r, 1-g, 1-b, 1)
TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0)
TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1)
TM_FOGLAYER, // (renders a fog layer in the shape of the active texture)
TM_FIXEDCOLORMAP = TM_FOGLAYER, // repurposes the objectcolor uniforms to render a fixed colormap range. (Same constant because they cannot be used in the same context.
TM_CLAMPY = 0x1000, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0)
};
// Legacy render styles

View File

@ -124,9 +124,7 @@ bool FGLRenderState::ApplyShader()
activeShader->muDesaturation.Set(mStreamData.uDesaturationFactor);
activeShader->muFogEnabled.Set(fogset);
int f = mTextureModeFlags;
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap);
activeShader->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f);
activeShader->muTextureMode.Set(GetTextureModeAndFlags(mTempTM));
activeShader->muLightParms.Set(mLightParms);
activeShader->muFogColor.Set(mStreamData.uFogColor);
activeShader->muObjectColor.Set(mStreamData.uObjectColor);

View File

@ -144,14 +144,15 @@ bool FGLRenderState::ApplyShader()
}
flavour.textureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) & 0xff;
if (mTextureClamp && flavour.textureMode == TM_NORMAL) flavour.textureMode = 5; // fixme. Clamp can now be combined with all modes.
int tm = GetTextureModeAndFlags(mTempTM);
flavour.textureMode = tm & 0xffff;
flavour.texFlags = tm >> 16; //Move flags to start of word
if (mTextureClamp && flavour.textureMode == TM_NORMAL) flavour.textureMode = TM_CLAMPY; // fixme. Clamp can now be combined with all modes.
if (flavour.textureMode == -1)
flavour.textureMode = 0;
flavour.texFlags = mTextureModeFlags; if (!mBrightmapEnabled) flavour.texFlags &= ~(TEXF_Brightmap | TEXF_Glowmap);
flavour.texFlags >>= 16; //Move flags to start of word
flavour.blendFlags = (int)(mStreamData.uTextureAddColor.a + 0.01);
@ -238,9 +239,6 @@ bool FGLRenderState::ApplyShader()
activeShader->cur->muDesaturation.Set(mStreamData.uDesaturationFactor);
//activeShader->cur->muFogEnabled.Set(fogset);
int f = mTextureModeFlags;
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap);
//activeShader->cur->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f);
activeShader->cur->muLightParms.Set(mLightParms);
activeShader->cur->muFogColor.Set(mStreamData.uFogColor);
activeShader->cur->muObjectColor.Set(mStreamData.uObjectColor);

View File

@ -378,6 +378,14 @@ public:
return mTextureMode;
}
int GetTextureModeAndFlags(int tempTM)
{
int f = mTextureModeFlags;
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap);
if (mTextureClamp) f |= TEXF_ClampY;
return (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f;
}
void EnableTexture(bool on)
{
mTextureEnabled = on;

View File

@ -287,7 +287,7 @@ void PolyRenderState::Apply()
PolyPushConstants constants;
constants.uFogEnabled = fogset;
constants.uTextureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode);
constants.uTextureMode = GetTextureModeAndFlags(mTempTM);
constants.uLightDist = mLightParms[0];
constants.uLightFactor = mLightParms[1];
constants.uFogDensity = mLightParms[2];

View File

@ -380,11 +380,7 @@ static void ProcessMaterial(int x0, int x1, PolyTriangleThreadData* thread)
{
auto constants = thread->PushConstants;
if (constants->uTextureMode == TM_CLAMPY)
{
FuncNormal_ClampY(x0, x1, thread);
}
else switch (constants->uTextureMode & 0xff)
switch (constants->uTextureMode)
{
default:
case TM_NORMAL:
@ -393,6 +389,7 @@ static void ProcessMaterial(int x0, int x1, PolyTriangleThreadData* thread)
case TM_OPAQUE: FuncNormal_Opaque(x0, x1, thread); break;
case TM_INVERSE: FuncNormal_Inverse(x0, x1, thread); break;
case TM_ALPHATEXTURE: FuncNormal_AlphaTexture(x0, x1, thread); break;
case TM_CLAMPY: FuncNormal_ClampY(x0, x1, thread); break;
case TM_INVERTOPAQUE: FuncNormal_InvertOpaque(x0, x1, thread); break;
}

View File

@ -371,9 +371,7 @@ void VkRenderState::ApplyPushConstants()
tempTM = TM_OPAQUE;
mPushConstants.uFogEnabled = fogset;
int f = mTextureModeFlags;
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap|TEXF_Glowmap);
mPushConstants.uTextureMode = (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f;
mPushConstants.uTextureMode = GetTextureModeAndFlags(tempTM);
mPushConstants.uLightDist = mLightParms[0];
mPushConstants.uLightFactor = mLightParms[1];
mPushConstants.uFogDensity = mLightParms[2];

View File

@ -92,6 +92,7 @@ enum texflags
TEXF_Brightmap = 0x10000,
TEXF_Detailmap = 0x20000,
TEXF_Glowmap = 0x40000,
TEXF_ClampY = 0x80000,
};

View File

@ -45,6 +45,7 @@ vec2 GetTexCoord();
const int TEXF_Brightmap = 0x10000;
const int TEXF_Detailmap = 0x20000;
const int TEXF_Glowmap = 0x40000;
const int TEXF_ClampY = 0x80000;
//===========================================================================
//
@ -166,7 +167,7 @@ vec4 getTexel(vec2 st)
//
// Apply texture modes
//
switch (uTextureMode & 0xfff)
switch (uTextureMode & 0xffff)
{
case 1: // TM_STENCIL
texel.rgb = vec3(1.0,1.0,1.0);
@ -187,6 +188,13 @@ vec4 getTexel(vec2 st)
break;
}
case 5: // TM_CLAMPY
if (st.t < 0.0 || st.t > 1.0)
{
texel.a = 0.0;
}
break;
case 6: // TM_OPAQUEINVERSE
texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, 1.0);
break;
@ -195,7 +203,8 @@ vec4 getTexel(vec2 st)
return texel;
}
if ((uTextureMode & 0x1000) != 0) // TM_CLAMPY
if (uTextureMode & TEXF_ClampY)
{
if (st.t < 0.0 || st.t > 1.0)
{