Skip to content

Commit 49f2de1

Browse files
nstlaurent72hr
andauthored
invuln colormap emu: uniform -> shadervar (#1157)
Co-authored-by: 72hr <115905880+72hr@users.noreply.github.com>
1 parent ff9b193 commit 49f2de1

File tree

17 files changed

+43
-79
lines changed

17 files changed

+43
-79
lines changed

Core/Render/OpenGL/Renderers/Legacy/Hud/LegacyHudRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ public override void Render(Rectangle viewport, Dimension framebufferDimension,
137137
m_program.PaletteIndex((int)uniforms.PaletteIndex);
138138
m_program.ColorMapIndex(uniforms.ColorMapUniforms.SectorIndex == 0 ? uniforms.ColorMapUniforms.GlobalIndex : uniforms.ColorMapUniforms.SectorIndex);
139139
m_program.HasInvulnerability(uniforms.DrawInvulnerability);
140-
m_program.EmulateInvulnerabilityColorMap(uniforms.EmulateInvulnerabilityColorMap);
141140
m_program.GammaCorrection(uniforms.GammaCorrection);
142141
m_program.ScreenBounds((framebufferDimension.Width, framebufferDimension.Height));
143142
m_program.UseBrightmaps(uniforms.UseBrightmaps);

Core/Render/OpenGL/Renderers/Legacy/Hud/LegacyHudShader.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class LegacyHudShader : RenderProgram
1616
private readonly int m_paletteIndexLocation;
1717
private readonly int m_colorMapIndexLocation;
1818
private readonly int m_hasInvulnerabilityLocation;
19-
private readonly int m_emulateInvulnerabilityColorMapLocation;
2019
private readonly int m_gammaCorrectionLocation;
2120
private readonly int m_opaqueTextureLocation;
2221
private readonly int m_screenBoundsLocation;
@@ -33,7 +32,6 @@ public LegacyHudShader() : base("Hud")
3332
m_paletteIndexLocation = Uniforms.GetLocation("paletteIndex");
3433
m_colorMapIndexLocation = Uniforms.GetLocation("colormapIndex");
3534
m_hasInvulnerabilityLocation = Uniforms.GetLocation("hasInvulnerability");
36-
m_emulateInvulnerabilityColorMapLocation = Uniforms.GetLocation("emulateInvulnerabilityColorMap");
3735
m_gammaCorrectionLocation = Uniforms.GetLocation("gammaCorrection");
3836
m_opaqueTextureLocation = Uniforms.GetLocation("opaqueTexture");
3937
m_screenBoundsLocation = Uniforms.GetLocation("screenBounds");
@@ -50,7 +48,6 @@ public LegacyHudShader() : base("Hud")
5048
public void FuzzDiv(float div) => Uniforms.Set(div, m_fuzzDivLocation);
5149
public void PaletteIndex(int index) => Uniforms.Set(index, m_paletteIndexLocation);
5250
public void HasInvulnerability(bool invul) => Uniforms.Set(invul, m_hasInvulnerabilityLocation);
53-
public void EmulateInvulnerabilityColorMap(bool value) => Uniforms.Set(value, m_emulateInvulnerabilityColorMapLocation);
5451
public void ColorMapIndex(int index) => Uniforms.Set(index, m_colorMapIndexLocation);
5552
public void GammaCorrection(float value) => Uniforms.Set(value, m_gammaCorrectionLocation);
5653
public void ScreenBounds(Vec2I value) => Uniforms.Set(value, m_screenBoundsLocation);
@@ -132,7 +129,6 @@ private static string GetBrightmapColorBlend()
132129
uniform int paletteIndex;
133130
uniform int colormapIndex;
134131
uniform int hasInvulnerability;
135-
uniform int emulateInvulnerabilityColorMap;
136132
uniform int useBrightmaps;
137133
uniform float gammaCorrection;
138134
uniform ivec2 screenBounds;

Core/Render/OpenGL/Renderers/Legacy/World/Entities/EntityProgram.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class EntityProgram : RenderProgram
1616
private readonly int m_mvpLocation;
1717
private readonly int m_timeFracLocation;
1818
private readonly int m_hasInvulnerabilityLocation;
19-
private readonly int m_emulateInvulnerabilityColorMapLocation;
2019
private readonly int m_mvpNoPitchLocation;
2120
private readonly int m_fuzzFracLocation;
2221
private readonly int m_lightLevelMixLocation;
@@ -57,7 +56,6 @@ public EntityProgram(string name) : base($"Entity - {name}")
5756
m_mvpLocation = Uniforms.GetLocation("mvp");
5857
m_timeFracLocation = Uniforms.GetLocation("timeFrac");
5958
m_hasInvulnerabilityLocation = Uniforms.GetLocation("hasInvulnerability");
60-
m_emulateInvulnerabilityColorMapLocation = Uniforms.GetLocation("emulateInvulnerabilityColorMap");
6159
m_mvpNoPitchLocation = Uniforms.GetLocation("mvpNoPitch");
6260
m_fuzzFracLocation = Uniforms.GetLocation("fuzzFrac");
6361
m_lightLevelMixLocation = Uniforms.GetLocation("lightLevelMix");
@@ -105,7 +103,6 @@ public EntityProgram(string name) : base($"Entity - {name}")
105103

106104
public void ExtraLight(int extraLight) => Uniforms.Set(extraLight, m_extraLightLocation);
107105
public void HasInvulnerability(bool invul) => Uniforms.Set(invul, m_hasInvulnerabilityLocation);
108-
public void EmulateInvulnerabilityColorMap(bool value) => Uniforms.Set(value, m_emulateInvulnerabilityColorMapLocation);
109106
public void LightLevelMix(float lightLevelMix) => Uniforms.Set(lightLevelMix, m_lightLevelMixLocation);
110107
public void Mvp(mat4 mvp) => Uniforms.Set(mvp, m_mvpLocation);
111108
public void MvpNoPitch(mat4 mvpNoPitch) => Uniforms.Set(mvpNoPitch, m_mvpNoPitchLocation);
@@ -333,7 +330,6 @@ void main()
333330
${OutFragColor}
334331
335332
uniform int hasInvulnerability;
336-
uniform int emulateInvulnerabilityColorMap;
337333
uniform float fuzzFrac;
338334
uniform sampler2D boundTexture;
339335
uniform sampler2D brightmapTexture;

Core/Render/OpenGL/Renderers/Legacy/World/Entities/EntityRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ private void SetUniforms(EntityProgram program, RenderInfo renderInfo)
328328
program.SectorColormapTexture(BindTextures.SectorColormap);
329329
program.ExtraLight(renderInfo.Uniforms.ExtraLight);
330330
program.HasInvulnerability(renderInfo.Uniforms.DrawInvulnerability);
331-
program.EmulateInvulnerabilityColorMap(renderInfo.Uniforms.EmulateInvulnerabilityColorMap);
332331
program.LightLevelMix(renderInfo.Uniforms.Mix);
333332
program.Mvp(renderInfo.Uniforms.Mvp);
334333
program.MvpNoPitch(renderInfo.Uniforms.MvpNoPitch);

Core/Render/OpenGL/Renderers/Legacy/World/Geometry/Portals/FloodFill/FloodFillProgram.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class FloodFillProgram : RenderProgram
1717
private readonly int m_mvpLocation;
1818
private readonly int m_timeFracLocation;
1919
private readonly int m_hasInvulnerabilityLocation;
20-
private readonly int m_emulateInvulnerabilityColorMapLocation;
2120
private readonly int m_mvpNoPitchLocation;
2221
private readonly int m_lightLevelMixLocation;
2322
private readonly int m_extraLightLocation;
@@ -39,7 +38,6 @@ public FloodFillProgram(string name) : base($"FloodFill - {name}")
3938
m_mvpLocation = Uniforms.GetLocation("mvp");
4039
m_timeFracLocation = Uniforms.GetLocation("timeFrac");
4140
m_hasInvulnerabilityLocation = Uniforms.GetLocation("hasInvulnerability");
42-
m_emulateInvulnerabilityColorMapLocation = Uniforms.GetLocation("emulateInvulnerabilityColorMap");
4341
m_mvpNoPitchLocation = Uniforms.GetLocation("mvpNoPitch");
4442
m_lightLevelMixLocation = Uniforms.GetLocation("lightLevelMix");
4543
m_extraLightLocation = Uniforms.GetLocation("extraLight");
@@ -61,7 +59,6 @@ public FloodFillProgram(string name) : base($"FloodFill - {name}")
6159
public void Mvp(mat4 mvp) => Uniforms.Set(mvp, m_mvpLocation);
6260
public void TimeFrac(float frac) => Uniforms.Set(frac, m_timeFracLocation);
6361
public void HasInvulnerability(bool invul) => Uniforms.Set(invul, m_hasInvulnerabilityLocation);
64-
public void EmulateInvulnerabilityColorMap(bool value) => Uniforms.Set(value, m_emulateInvulnerabilityColorMapLocation);
6562
public void MvpNoPitch(mat4 mvpNoPitch) => Uniforms.Set(mvpNoPitch, m_mvpNoPitchLocation);
6663
public void LightLevelMix(float lightLevelMix) => Uniforms.Set(lightLevelMix, m_lightLevelMixLocation);
6764
public void ExtraLight(int extraLight) => Uniforms.Set(extraLight, m_extraLightLocation);
@@ -160,7 +157,6 @@ protected override string FragmentShader()
160157
uniform vec3 camera;
161158
uniform mat4 mvpNoPitch;
162159
uniform int hasInvulnerability;
163-
uniform int emulateInvulnerabilityColorMap;
164160
uniform vec3 colorMix;
165161
uniform int paletteIndex;
166162
uniform int colormapIndex;

Core/Render/OpenGL/Renderers/Legacy/World/Geometry/Portals/FloodFill/FloodFillRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ private static void SetUniforms(FloodFillProgram program, RenderInfo renderInfo)
344344
program.Mvp(renderInfo.Uniforms.Mvp);
345345
program.TimeFrac(renderInfo.TickFraction);
346346
program.HasInvulnerability(renderInfo.Uniforms.DrawInvulnerability);
347-
program.EmulateInvulnerabilityColorMap(renderInfo.Uniforms.EmulateInvulnerabilityColorMap);
348347
program.MvpNoPitch(renderInfo.Uniforms.MvpNoPitch);
349348
program.TimeFrac(renderInfo.TickFraction);
350349
program.LightLevelMix(renderInfo.Uniforms.Mix);

Core/Render/OpenGL/Renderers/Legacy/World/InterpolationShader.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class InterpolationShader : RenderProgram
1616
private readonly int m_mvpLocation;
1717
private readonly int m_timeFracLocation;
1818
private readonly int m_hasInvulnerabilityLocation;
19-
private readonly int m_emulateInvulnerabilityColorMapLocation;
2019
private readonly int m_mvpNoPitchLocation;
2120
private readonly int m_lightLevelMixLocation;
2221
private readonly int m_extraLightLocation;
@@ -43,7 +42,6 @@ public InterpolationShader(string name) : base($"World Interpolation - {name}")
4342
m_mvpLocation = Uniforms.GetLocation("mvp");
4443
m_timeFracLocation = Uniforms.GetLocation("timeFrac");
4544
m_hasInvulnerabilityLocation = Uniforms.GetLocation("hasInvulnerability");
46-
m_emulateInvulnerabilityColorMapLocation = Uniforms.GetLocation("emulateInvulnerabilityColorMap");
4745
m_mvpNoPitchLocation = Uniforms.GetLocation("mvpNoPitch");
4846
m_lightLevelMixLocation = Uniforms.GetLocation("lightLevelMix");
4947
m_extraLightLocation = Uniforms.GetLocation("extraLight");
@@ -72,7 +70,6 @@ public InterpolationShader(string name) : base($"World Interpolation - {name}")
7270
public void WallClipTexture(TextureUnit unit) => Uniforms.Set(unit, m_wallClipTextureLocation);
7371

7472
public void HasInvulnerability(bool invul) => Uniforms.Set(invul, m_hasInvulnerabilityLocation);
75-
public void EmulateInvulnerabilityColorMap(bool value) => Uniforms.Set(value, m_emulateInvulnerabilityColorMapLocation);
7673
public void Mvp(mat4 mvp) => Uniforms.Set(mvp, m_mvpLocation);
7774
public void MvpNoPitch(mat4 mvpNoPitch) => Uniforms.Set(mvpNoPitch, m_mvpNoPitchLocation);
7875
public void TimeFrac(float frac) => Uniforms.Set(frac, m_timeFracLocation);
@@ -180,7 +177,6 @@ protected override string FragmentShader()
180177
${OutFragColor}
181178
182179
uniform int hasInvulnerability;
183-
uniform int emulateInvulnerabilityColorMap;
184180
uniform sampler2D boundTexture;
185181
uniform sampler2D brightmapTexture;
186182
uniform vec3 colorMix;

Core/Render/OpenGL/Renderers/Legacy/World/LegacyWorldRenderer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ private static void SetInterpolationUniforms(InterpolationShader program, Render
595595
program.PlaneClipTexture(BindTextures.PlaneClipTexture);
596596
program.WallClipTexture(BindTextures.WallClipTexture);
597597
program.HasInvulnerability(renderInfo.Uniforms.DrawInvulnerability);
598-
program.EmulateInvulnerabilityColorMap(renderInfo.Uniforms.EmulateInvulnerabilityColorMap);
599598
program.Mvp(renderInfo.Uniforms.Mvp);
600599
program.MvpNoPitch(renderInfo.Uniforms.MvpNoPitch);
601600
program.TimeFrac(renderInfo.TickFraction);
@@ -624,7 +623,6 @@ private static void SetStaticUniforms(StaticShader program, RenderInfo renderInf
624623
program.SectorColormapTexture(BindTextures.SectorColormap);
625624
program.BrightmapTexture(BindTextures.BrightmapTexture);
626625
program.HasInvulnerability(renderInfo.Uniforms.DrawInvulnerability);
627-
program.EmulateInvulnerabilityColorMap(renderInfo.Uniforms.EmulateInvulnerabilityColorMap);
628626
program.Mvp(renderInfo.Uniforms.Mvp);
629627
program.MvpNoPitch(renderInfo.Uniforms.MvpNoPitch);
630628
program.LightLevelMix(renderInfo.Uniforms.Mix);

Core/Render/OpenGL/Renderers/Legacy/World/Shader/FragFunction.cs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -364,43 +364,41 @@ private static string Oit(OitOptions options, FragColorFunctionOptions fragColor
364364
"""
365365
float gray = fragColor.x * 0.299 + fragColor.y * 0.587 + fragColor.z * 0.144;
366366
gray = 1 - gray;
367-
if (emulateInvulnerabilityColorMap == 0)
368-
{
369-
fragColor.xyz = vec3(gray, gray, gray);
370-
}
371-
else
372-
{
373-
// Map brightness to white + white + gray ramp (32x) + low grays (3x) + black
374-
// in invuln color map, to emulate palette mode's invuln effect.
375-
// These grays are not completely evenly spaced (most are 8 apart,
376-
// some are 4), but it's even enough to work.
377-
// Since some colormaps customize non-gray colors instead of just
378-
// mapping to brightness, the degree to which the original effect
379-
// is matched can vary by WAD.
380-
const float maxIndex = 38 - 1;
381-
int indexA = int(gray * maxIndex);
382-
int indexB = indexA + 1;
383-
float localPos = (gray - float(indexA) / maxIndex) * maxIndex;
384-
385-
// [ 0, 1] => [ 4, 4]
386-
// [ 2, 33] => [80, 111]
387-
// [34, 36] => [ 5, 7]
388-
// [37, 37] => [ 0, 0]
389-
if (indexA <= 1) { indexA = 4; }
390-
else if (indexA <= 33) { indexA += 78; }
391-
else if (indexA <= 36) { indexA -= 29; }
392-
else { indexA = 0; }
393-
if (indexB <= 1) { indexB = 4; }
394-
else if (indexB <= 33) { indexB += 78; }
395-
else if (indexB <= 36) { indexB -= 29; }
396-
else { indexB = 0; }
397-
398-
const int colorMapOffset = 256 * 32; // invuln colormap start
399-
vec3 blendA = texelFetch(colormapTexture, colorMapOffset + indexA).rgb;
400-
vec3 blendB = texelFetch(colormapTexture, colorMapOffset + indexB).rgb;
401-
fragColor.rgb = mix(blendA, blendB, localPos);
402-
}
403-
""";
367+
"""
368+
+ (!ShaderVars.EmulateInvulnerabilityColorMap
369+
? """
370+
fragColor.xyz = vec3(gray, gray, gray);
371+
""" : """
372+
// Map brightness to white + white + gray ramp (32x) + low grays (3x) + black
373+
// in invuln color map, to emulate palette mode's invuln effect.
374+
// These grays are not completely evenly spaced (most are 8 apart,
375+
// some are 4), but it's even enough to work.
376+
// Since some colormaps customize non-gray colors instead of just
377+
// mapping to brightness, the degree to which the original effect
378+
// is matched can vary by WAD.
379+
const float maxIndex = 38 - 1;
380+
int indexA = int(gray * maxIndex);
381+
int indexB = indexA + 1;
382+
float localPos = (gray - float(indexA) / maxIndex) * maxIndex;
383+
384+
// [ 0, 1] => [ 4, 4]
385+
// [ 2, 33] => [80, 111]
386+
// [34, 36] => [ 5, 7]
387+
// [37, 37] => [ 0, 0]
388+
if (indexA <= 1) { indexA = 4; }
389+
else if (indexA <= 33) { indexA += 78; }
390+
else if (indexA <= 36) { indexA -= 29; }
391+
else { indexA = 0; }
392+
if (indexB <= 1) { indexB = 4; }
393+
else if (indexB <= 33) { indexB += 78; }
394+
else if (indexB <= 36) { indexB -= 29; }
395+
else { indexB = 0; }
396+
397+
const int colorMapOffset = 256 * 32; // invuln colormap start
398+
vec3 blendA = texelFetch(colormapTexture, colorMapOffset + indexA).rgb;
399+
vec3 blendB = texelFetch(colormapTexture, colorMapOffset + indexB).rgb;
400+
fragColor.rgb = mix(blendA, blendB, localPos);
401+
""");
404402

405403
public static string VertexGapVariables => "flat in vec2 uvClampMinFrag; flat in vec2 uvClampMaxFrag;";
406404
}

Core/Render/OpenGL/Renderers/Legacy/World/Shader/ShaderVars.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ public static class ShaderVars
55
public static bool ReversedZ;
66
public static string Depth = "z";
77
public static bool PaletteColorMode = true;
8+
public static bool EmulateInvulnerabilityColorMap = false;
89
}

0 commit comments

Comments
 (0)