mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-04-25 00:41:15 +00:00
Moved fog enable to precompiler for shader
This commit is contained in:
parent
284cda3638
commit
1b4533083f
4 changed files with 101 additions and 53 deletions
|
@ -117,9 +117,37 @@ bool FGLRenderState::ApplyShader()
|
|||
activeShader = GLRenderer->mShaderManager->Get(mTextureEnabled ? mEffectState : SHADER_NoTexture, mAlphaThreshold >= 0.f, mPassType);
|
||||
|
||||
int textureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode);
|
||||
|
||||
int texFlags = mTextureModeFlags; if (!mBrightmapEnabled) texFlags &= ~(TEXF_Brightmap | TEXF_Glowmap);
|
||||
texFlags >>= 16; //Move flags to start of word
|
||||
|
||||
activeShader->Bind(textureMode, texFlags, 0);
|
||||
int blendFlags = (int)(mStreamData.uTextureAddColor.a + 0.1);
|
||||
|
||||
bool twoDFog = false;
|
||||
bool fogEnabled = false;
|
||||
bool fogEquationRadial = false;
|
||||
bool colouredFog = false;
|
||||
|
||||
if (mFogEnabled)
|
||||
{
|
||||
if (mFogEnabled == 2)
|
||||
{
|
||||
twoDFog = true;
|
||||
}
|
||||
else if(gl_fogmode)
|
||||
{
|
||||
fogEnabled = true;
|
||||
|
||||
if (gl_fogmode == 2)
|
||||
fogEquationRadial = true;
|
||||
|
||||
if ((GetFogColor() & 0xffffff) != 0)
|
||||
colouredFog = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
activeShader->Bind(textureMode, texFlags, blendFlags, twoDFog, fogEnabled, fogEquationRadial, colouredFog);
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,7 +177,7 @@ bool FGLRenderState::ApplyShader()
|
|||
glVertexAttrib4fv(VATTR_NORMAL, &mStreamData.uVertexNormal.X);
|
||||
|
||||
activeShader->cur->muDesaturation.Set(mStreamData.uDesaturationFactor);
|
||||
activeShader->cur->muFogEnabled.Set(fogset);
|
||||
//activeShader->cur->muFogEnabled.Set(fogset);
|
||||
|
||||
int f = mTextureModeFlags;
|
||||
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap);
|
||||
|
|
|
@ -298,7 +298,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
#define uFogDensity uLightAttr.b
|
||||
#define uLightFactor uLightAttr.g
|
||||
#define uLightDist uLightAttr.r
|
||||
uniform int uFogEnabled;
|
||||
//uniform int uFogEnabled;
|
||||
|
||||
// dynamic lights
|
||||
uniform int uLightIndex;
|
||||
|
@ -662,9 +662,10 @@ FShader::~FShader()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FShader::Bind(int textureMode, int texFlags, int blendFlags)
|
||||
bool FShader::Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog)
|
||||
{
|
||||
uint32_t tag = CreateShaderTag(textureMode, texFlags, blendFlags);
|
||||
uint32_t tag = CreateShaderTag(textureMode, texFlags, blendFlags, twoDFog, fogEnabled, fogEquationRadial, colouredFog);
|
||||
|
||||
|
||||
cur = variants[tag];
|
||||
|
||||
|
@ -673,7 +674,11 @@ bool FShader::Bind(int textureMode, int texFlags, int blendFlags)
|
|||
FString variantConfig = "\n";
|
||||
variantConfig.AppendFormat("#define DEF_TEXTURE_MODE %d\n", textureMode);
|
||||
variantConfig.AppendFormat("#define DEF_BLEND_FLAGS %d\n", blendFlags);
|
||||
|
||||
variantConfig.AppendFormat("#define DEF_FOG_2D %d\n", twoDFog);
|
||||
variantConfig.AppendFormat("#define DEF_FOG_ENABLED %d\n", fogEnabled);
|
||||
variantConfig.AppendFormat("#define DEF_FOG_RADIAL %d\n", fogEquationRadial);
|
||||
variantConfig.AppendFormat("#define DEF_FOG_COLOURED %d\n", colouredFog);
|
||||
|
||||
Load(mName.GetChars(), mVertProg, mFragProg, mFragProg2, mLightProg, mDefinesBase + variantConfig);
|
||||
|
||||
variants[tag] = cur;
|
||||
|
@ -884,7 +889,7 @@ FShader *FShaderCollection::BindEffect(int effect)
|
|||
{
|
||||
if (effect >= 0 && effect < MAX_EFFECTS && mEffectShaders[effect] != NULL)
|
||||
{
|
||||
mEffectShaders[effect]->Bind(0,0,0);
|
||||
mEffectShaders[effect]->Bind(0,0,0,0,0,0,0);
|
||||
return mEffectShaders[effect];
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -353,16 +353,25 @@ public:
|
|||
|
||||
void LoadVariant();
|
||||
|
||||
uint32_t CreateShaderTag(int textureMode, int texf, int blendFlags)
|
||||
uint32_t CreateShaderTag(int textureMode, int texf, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog)
|
||||
{
|
||||
uint32_t tag = 0;
|
||||
tag |= textureMode & 0x7;
|
||||
tag |= (texf * 3) << 3;
|
||||
tag |= (textureMode & 0x7);
|
||||
|
||||
tag |= (texf & 7) << 3;
|
||||
|
||||
tag |= (blendFlags & 7) << 6;
|
||||
|
||||
tag |= (twoDFog & 1) << 7;
|
||||
tag |= (fogEnabled & 1) << 8;
|
||||
tag |= (fogEquationRadial & 1) << 9;
|
||||
tag |= (colouredFog & 1) << 10;
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
bool Bind(int textureMode, int texFlags, int blendFlags);
|
||||
bool Bind(int textureMode, int texFlags, int blendFlags, bool twoDFog, bool fogEnabled, bool fogEquationRadial, bool colouredFog);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -264,7 +264,7 @@ float spotLightAttenuation(vec4 lightpos, vec3 spotdir, float lightCosInnerAngle
|
|||
|
||||
void SetMaterialProps(inout Material material, vec2 texCoord)
|
||||
{
|
||||
material.Base = getTexel(texCoord.st);
|
||||
material.Base = getTexel(texCoord.st);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -290,18 +290,23 @@ vec4 getLightColor(Material material, float fogdist, float fogfactor)
|
|||
float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel);
|
||||
color.rgb *= newlightlevel;
|
||||
}
|
||||
else if (uFogEnabled > 0)
|
||||
else
|
||||
{
|
||||
// brightening around the player for light mode 2
|
||||
if (fogdist < uLightDist)
|
||||
|
||||
#if (DEF_FOG_ENABLED == 1) && (DEF_FOG_COLOURED == 0)
|
||||
{
|
||||
color.rgb *= uLightFactor - (fogdist / uLightDist) * (uLightFactor - 1.0);
|
||||
}
|
||||
// brightening around the player for light mode 2
|
||||
if (fogdist < uLightDist)
|
||||
{
|
||||
color.rgb *= uLightFactor - (fogdist / uLightDist) * (uLightFactor - 1.0);
|
||||
}
|
||||
|
||||
//
|
||||
// apply light diminishing through fog equation
|
||||
//
|
||||
color.rgb = mix(vec3(0.0, 0.0, 0.0), color.rgb, fogfactor);
|
||||
//
|
||||
// apply light diminishing through fog equation
|
||||
//
|
||||
color.rgb = mix(vec3(0.0, 0.0, 0.0), color.rgb, fogfactor);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -380,7 +385,7 @@ void main()
|
|||
if (frag.a <= uAlphaThreshold) discard;
|
||||
#endif
|
||||
|
||||
if (uFogEnabled != -3) // check for special 2D 'fog' mode.
|
||||
#if (DEF_FOG_2D == 0) // check for special 2D 'fog' mode.
|
||||
{
|
||||
float fogdist = 0.0;
|
||||
float fogfactor = 0.0;
|
||||
|
@ -388,50 +393,51 @@ void main()
|
|||
//
|
||||
// calculate fog factor
|
||||
//
|
||||
if (uFogEnabled != 0)
|
||||
#if (DEF_FOG_ENABLED == 1)
|
||||
{
|
||||
if (uFogEnabled == 1 || uFogEnabled == -1)
|
||||
{
|
||||
#if (DEF_FOG_RADIAL == 0)
|
||||
fogdist = max(16.0, pixelpos.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
#else
|
||||
fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz));
|
||||
}
|
||||
#endif
|
||||
|
||||
fogfactor = exp2 (uFogDensity * fogdist);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (DEF_TEXTURE_MODE != 7)
|
||||
|
||||
frag = getLightColor(material, fogdist, fogfactor);
|
||||
|
||||
//
|
||||
// colored fog
|
||||
//
|
||||
if (uFogEnabled < 0)
|
||||
#if (DEF_TEXTURE_MODE != 7)
|
||||
{
|
||||
frag = applyFog(frag, fogfactor);
|
||||
}
|
||||
#else
|
||||
frag = getLightColor(material, fogdist, fogfactor);
|
||||
|
||||
frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a);
|
||||
#endif
|
||||
|
||||
}
|
||||
else // simple 2D (uses the fog color to add a color overlay)
|
||||
//
|
||||
// colored fog
|
||||
//
|
||||
#if (DEF_FOG_ENABLED == 1) && (DEF_FOG_COLOURED == 1)
|
||||
{
|
||||
frag = applyFog(frag, fogfactor);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
{
|
||||
frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
{
|
||||
|
||||
#if (DEF_TEXTURE_MODE == 7)
|
||||
|
||||
float gray = grayscale(frag);
|
||||
vec4 cm = (uObjectColor + gray * (uAddColor - uObjectColor)) * 2;
|
||||
frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a);
|
||||
|
||||
#endif
|
||||
#if (DEF_TEXTURE_MODE == 7)
|
||||
{
|
||||
float gray = grayscale(frag);
|
||||
vec4 cm = (uObjectColor + gray * (uAddColor - uObjectColor)) * 2;
|
||||
frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a);
|
||||
}
|
||||
#endif
|
||||
|
||||
frag = frag * ProcessLight(material, vColor);
|
||||
frag.rgb = frag.rgb + uFogColor.rgb;
|
||||
}
|
||||
#endif // (DEF_2D_FOG == 0)
|
||||
|
||||
gl_FragColor = frag;
|
||||
|
||||
|
|
Loading…
Reference in a new issue