- store the lighting related uniforms in a GZDoom-style LightParms vec4.

This commit is contained in:
Christoph Oelckers 2020-06-06 00:44:57 +02:00
parent f159496f6e
commit 232b0c1bb6
4 changed files with 40 additions and 30 deletions

View file

@ -135,14 +135,13 @@ 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");
Shade.Init(hShader, "u_shade");
ShadeDiv.Init(hShader, "u_shadeDiv");
VisFactor.Init(hShader, "u_visFactor");
NPOTEmulationFactor.Init(hShader, "u_npotEmulationFactor");
NPOTEmulationXOffset.Init(hShader, "u_npotEmulationXOffset");
Brightness.Init(hShader, "u_brightness");
FogColor.Init(hShader, "u_fogColor");
muFogEnabled.Init(hShader, "uFogEnabled");
muLightParms.Init(hShader, "uLightAttr");
AlphaThreshold.Init(hShader, "uAlphaThreshold");
DetailParms.Init(hShader, "uDetailParms");
ModelMatrix.Init(hShader, "ModelMatrix");

View file

@ -27,17 +27,15 @@ class PolymostShader : public FShader
{
public:
FBufferedUniform1i Flags;
FBufferedUniform1f Shade;
FBufferedUniform1f ShadeDiv;
FBufferedUniform1f VisFactor;
FBufferedUniform1f NPOTEmulationFactor;
FBufferedUniform1f NPOTEmulationXOffset;
FBufferedUniform1f Brightness;
FBufferedUniform1f AlphaThreshold;
FBufferedUniformPalEntry FogColor;
FBufferedUniform4f DetailParms;
FBufferedUniform1f AlphaThreshold;
FBufferedUniform1i muFogEnabled;
FBufferedUniform4f muLightParms;
FUniformMatrix4f ModelMatrix;
FUniformMatrix4f TextureMatrix;
FBufferedUniform4f muTextureBlendColor;

View file

@ -126,6 +126,12 @@ auto i_data = R"(
uniform vec4 uTextureAddColor;
uniform float uAlphaThreshold;
uniform vec4 uLightAttr;
#define uLightLevel uLightAttr.a
#define uFogDensity uLightAttr.b
#define uLightFactor uLightAttr.g
#define uLightDist uLightAttr.r
uniform int uFogEnabled;
)";
@ -373,7 +379,7 @@ void PolymostRenderState::ApplyMaterial(FMaterial* mat, int clampmode, int trans
#endif
}
void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
void PolymostRenderState::Apply(PolymostShader* shader, GLState& oldState)
{
if (!OpenGLRenderer::GLRenderer) return;
auto sm = OpenGLRenderer::GLRenderer->mSamplerManager;
@ -386,7 +392,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
float buffer[] = { mMaterial.mMaterial->GetDetailScale().X, mMaterial.mMaterial->GetDetailScale().Y, 1.f, 0.f };
shader->DetailParms.Set(buffer);
}
if (PaletteTexture != nullptr)
{
PaletteTexture->Bind(4, false);
@ -417,7 +423,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
if (StateFlags & STF_MULTISAMPLE) glEnable(GL_MULTISAMPLE);
else glDisable(GL_MULTISAMPLE);
}
if ((StateFlags ^ oldState.Flags) & (STF_STENCILTEST|STF_STENCILWRITE))
if ((StateFlags ^ oldState.Flags) & (STF_STENCILTEST | STF_STENCILWRITE))
{
if (StateFlags & STF_STENCILWRITE)
{
@ -465,7 +471,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
{
glPolygonMode(GL_FRONT_AND_BACK, (StateFlags & STF_WIREFRAME) ? GL_LINE : GL_FILL);
}
if (StateFlags & (STF_CLEARCOLOR| STF_CLEARDEPTH))
if (StateFlags & (STF_CLEARCOLOR | STF_CLEARDEPTH))
{
glClearColor(ClearColor.r / 255.f, ClearColor.g / 255.f, ClearColor.b / 255.f, 1.f);
int bit = 0;
@ -517,17 +523,29 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
oldState.DepthFunc = DepthFunc;
}
// Disable brightmaps if non-black fog is used.
if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping;
shader->Flags.Set(Flags);
shader->Shade.Set(Shade);
shader->ShadeDiv.Set(ShadeDiv / (numshades - 2));
shader->VisFactor.Set(VisFactor);
if (!(Flags & RF_FogDisabled) && ShadeDiv >= 1 / 1000.f)
{
if (!FogColor.isBlack())
{
Flags &= ~RF_Brightmapping;
shader->muFogEnabled.Set(-1);
}
else
{
shader->muFogEnabled.Set(1);
}
}
else shader->muFogEnabled.Set(0);
shader->Flags.Set(Flags);
shader->NPOTEmulationFactor.Set(NPOTEmulationFactor);
shader->NPOTEmulationXOffset.Set(NPOTEmulationXOffset);
shader->AlphaThreshold.Set(AlphaTest ? AlphaThreshold : -1.f);
shader->Brightness.Set(Brightness);
shader->FogColor.Set(FogColor);
float lightattr[] = { ShadeDiv / (numshades - 2), VisFactor, (Flags & RF_MapFog) ? -5.f : 0.f , Shade };
shader->muLightParms.Set(lightattr);
FVector4 addcol(0, 0, 0, 0);
FVector4 modcol(fullscreenTint.r / 255.f, fullscreenTint.g / 255.f, fullscreenTint.b / 255.f, 0);
FVector4 blendcol(0, 0, 0, 0);

View file

@ -5,8 +5,6 @@ const int RF_GlowMapping = 8;
const int RF_Brightmapping = 16;
const int RF_NPOTEmulation = 32;
const int RF_ShadeInterpolate = 64;
const int RF_FogDisabled = 128;
const int RF_MapFog = 256;
//s_texture points to an indexed color texture
uniform sampler2D s_texture;
@ -19,9 +17,6 @@ uniform sampler2D s_detail;
uniform sampler2D s_glow;
uniform sampler2D s_brightmap;
uniform float u_shade;
uniform float u_shadeDiv;
uniform float u_visFactor;
uniform int u_flags;
uniform float u_npotEmulationFactor;
@ -175,9 +170,9 @@ void main()
// Application of this differs based on render mode because for paletted rendering with palettized shade tables it can only be done after processing the shade table. We only have a palette index before.
}
float visibility = max(uGlobVis * u_visFactor * v_distance - ((u_flags & RF_ShadeInterpolate) != 0.0? 0.5 : 0.0), 0.0);
float visibility = max(uGlobVis * uLightFactor * v_distance - ((u_flags & RF_ShadeInterpolate) != 0.0? 0.5 : 0.0), 0.0);
float numShades = float(uPalLightLevels & 255);
float shade = clamp((u_shade + visibility), 0.0, numShades - 1.0);
float shade = clamp((uLightLevel + visibility), 0.0, numShades - 1.0);
if ((u_flags & RF_UsePalette) != 0)
@ -215,9 +210,9 @@ void main()
color = ApplyTextureManipulation(color, blendflags);
}
if ((u_flags & RF_FogDisabled) == 0)
if (uFogEnabled != 0) // Right now this code doesn't care about the fog modes yet.
{
shade = clamp(shade * u_shadeDiv, 0.0, 1.0); // u_shadeDiv is really 1/shadeDiv.
shade = clamp(shade * uLightDist, 0.0, 1.0); // u_shadeDiv is really 1/shadeDiv.
vec3 lightcolor = v_color.rgb * (1.0 - shade);
if ((u_flags & RF_Brightmapping) != 0)
@ -225,13 +220,13 @@ void main()
lightcolor = clamp(lightcolor + texture(s_brightmap, v_texCoord.xy).rgb, 0.0, 1.0);
}
color.rgb *= lightcolor;
if ((u_flags & RF_MapFog) == 0) color.rgb += u_fogColor.rgb * shade;
if (uFogDensity == 0.0) color.rgb += u_fogColor.rgb * shade;
}
else color.rgb *= v_color.rgb;
}
if ((u_flags & RF_MapFog) != 0) // fog hack for RRRA E2L1. Needs to be done better, this is gross, but still preferable to the broken original implementation.
if (uFogDensity != 0.0) // fog hack for RRRA E2L1. Needs to be done better, this is gross, but still preferable to the broken original implementation.
{
float fogfactor = 0.55 + 0.3 * exp2 (-5.0*v_fogCoord);
float fogfactor = 0.55 + 0.3 * exp2 (uFogDensity * v_fogCoord);
color.rgb = vec3(0.6*(1.0-fogfactor)) + color.rgb * fogfactor;// mix(vec3(0.6), color.rgb, fogfactor);
}
if (color.a < uAlphaThreshold) discard; // it's only here that we have the alpha value available to be able to perform the alpha test.