mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-27 04:00:42 +00:00
- some shader cleanup.
I think it's now as close to GZDoom's backend interface as it can be without disabling needed features.
This commit is contained in:
parent
09e31fd5f4
commit
9fc5f2d2e7
5 changed files with 30 additions and 61 deletions
|
@ -69,7 +69,7 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa
|
|||
int TextureType = (texpick.translation & 0x80000000) ? TT_INDEXED : TT_TRUECOLOR;
|
||||
if (TextureType == TT_INDEXED)
|
||||
{
|
||||
sampler = sampler + SamplerNoFilterRepeat - SamplerRepeat;
|
||||
sampler = sampler + CLAMP_NOFILTER - CLAMP_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -249,7 +249,6 @@ void GLInstance::DrawElement(EDrawType type, size_t start, size_t count, Polymos
|
|||
if (activeShader == polymostShader)
|
||||
{
|
||||
glVertexAttrib4fv(2, renderState.Color);
|
||||
if (renderState.Color[3] != 1.f) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all.
|
||||
renderState.Apply(polymostShader, lastState);
|
||||
}
|
||||
if (type != DT_Lines)
|
||||
|
@ -267,7 +266,6 @@ void GLInstance::DoDraw()
|
|||
for (auto& rs : rendercommands)
|
||||
{
|
||||
glVertexAttrib4fv(2, rs.Color);
|
||||
if (rs.Color[3] != 1.f) rs.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all.
|
||||
rs.Apply(polymostShader, lastState);
|
||||
glDrawArrays(primtypes[rs.primtype], rs.vindex, rs.vcount);
|
||||
}
|
||||
|
@ -543,12 +541,8 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState& oldState)
|
|||
}
|
||||
else shader->muFogEnabled.Set(0);
|
||||
|
||||
int texturemode = 0;
|
||||
if (Flags & RF_DetailMapping) texturemode |= 0x20000;
|
||||
if (Flags & RF_Brightmapping) texturemode |= 0x10000;
|
||||
if (Flags & RF_GlowMapping) texturemode |= 0x40000;
|
||||
shader->Flags.Set(Flags);
|
||||
shader->TextureMode.Set(texturemode);
|
||||
shader->TextureMode.Set(LayerFlags);
|
||||
shader->NPOTEmulationFactor.Set(NPOTEmulationFactor);
|
||||
shader->NPOTEmulationXOffset.Set(NPOTEmulationXOffset);
|
||||
shader->AlphaThreshold.Set(AlphaTest ? AlphaThreshold : -1.f);
|
||||
|
|
|
@ -20,24 +20,6 @@ class F2DDrawer;
|
|||
struct palette_t;
|
||||
extern int xdim, ydim;
|
||||
|
||||
enum ESampler
|
||||
{
|
||||
NoSampler = -1,
|
||||
SamplerRepeat = CLAMP_NONE,
|
||||
SamplerClampX = CLAMP_X,
|
||||
SamplerClampY = CLAMP_Y,
|
||||
SamplerClampXY = CLAMP_XY,
|
||||
Sampler2DFiltered = CLAMP_XY_NOMIP, // Currently unused shpuld be used for 2D content
|
||||
SamplerNoFilterRepeat = CLAMP_NOFILTER,
|
||||
SamplerNoFilterClampX = CLAMP_NOFILTER_X,
|
||||
SamplerNoFilterClampY = CLAMP_NOFILTER_Y,
|
||||
SamplerNoFilterClampXY = CLAMP_NOFILTER_XY,
|
||||
};
|
||||
enum
|
||||
{
|
||||
PALSWAP_TEXTURE_SIZE = 2048
|
||||
};
|
||||
|
||||
class PaletteManager
|
||||
{
|
||||
OpenGLRenderer::FHardwareTexture* palettetextures[256] = {};
|
||||
|
@ -391,20 +373,20 @@ public:
|
|||
|
||||
void UseDetailMapping(bool yes)
|
||||
{
|
||||
if (yes) renderState.Flags |= RF_DetailMapping;
|
||||
else renderState.Flags &= ~RF_DetailMapping;
|
||||
if (yes) renderState.LayerFlags |= TEXF_Detailmap;
|
||||
else renderState.LayerFlags &= ~TEXF_Detailmap;
|
||||
}
|
||||
|
||||
void UseGlowMapping(bool yes)
|
||||
{
|
||||
if (yes) renderState.Flags |= RF_GlowMapping;
|
||||
else renderState.Flags &= ~RF_GlowMapping;
|
||||
if (yes) renderState.LayerFlags |= TEXF_Glowmap;
|
||||
else renderState.LayerFlags &= ~TEXF_Glowmap;
|
||||
}
|
||||
|
||||
void UseBrightmaps(bool yes)
|
||||
{
|
||||
if (yes) renderState.Flags |= RF_Brightmapping;
|
||||
else renderState.Flags &= ~RF_Brightmapping;
|
||||
if (yes) renderState.LayerFlags |= TEXF_Brightmap;
|
||||
else renderState.LayerFlags &= ~TEXF_Brightmap;
|
||||
}
|
||||
|
||||
void SetNpotEmulation(float factor, float xOffset)
|
||||
|
|
|
@ -18,9 +18,6 @@ enum PRSFlags
|
|||
{
|
||||
RF_ColorOnly = 1,
|
||||
RF_UsePalette = 2,
|
||||
RF_DetailMapping = 4,
|
||||
RF_GlowMapping = 8,
|
||||
RF_Brightmapping = 16,
|
||||
RF_ShadeInterpolate = 64,
|
||||
RF_FogDisabled = 128,
|
||||
RF_MapFog = 256, // RRRA E2L1.
|
||||
|
@ -48,8 +45,6 @@ enum PRSFlags
|
|||
STF_CLEARDEPTH = 2048,
|
||||
STF_VIEWPORTSET = 4096,
|
||||
STF_SCISSORSET = 8192,
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct PolymostRenderState
|
||||
|
@ -59,6 +54,7 @@ struct PolymostRenderState
|
|||
float ShadeDiv = 62.f;
|
||||
float VisFactor = 128.f;
|
||||
int Flags = 0;
|
||||
int LayerFlags = 0;
|
||||
float NPOTEmulationFactor = 1.f;
|
||||
float NPOTEmulationXOffset;
|
||||
float Brightness = 1.f;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const int RF_ColorOnly = 1;
|
||||
const int RF_UsePalette = 2;
|
||||
const int RF_DetailMapping = 4;
|
||||
const int RF_GlowMapping = 8;
|
||||
const int RF_Brightmapping = 16;
|
||||
const int RF_ShadeInterpolate = 64;
|
||||
|
||||
const int TEXF_Brightmap = 0x10000;
|
||||
const int TEXF_Detailmap = 0x20000;
|
||||
const int TEXF_Glowmap = 0x40000;
|
||||
|
||||
|
||||
struct Material
|
||||
{
|
||||
|
@ -170,18 +171,8 @@ void main()
|
|||
}
|
||||
newCoord = vec2(coordX, coordY);
|
||||
|
||||
// Paletted textures are stored in column major order rather than row major so coordinates need to be swapped here.
|
||||
color = texture(s_texture, newCoord);
|
||||
|
||||
// This was further down but it really should be done before applying any kind of depth fading, not afterward.
|
||||
vec4 detailColor = vec4(1.0);
|
||||
if ((u_flags & RF_DetailMapping) != 0)
|
||||
{
|
||||
detailColor = texture(detailtexture, newCoord * uDetailParms.xy) * uDetailParms.z;
|
||||
detailColor = mix(vec4(1.0), 2.0 * detailColor, detailColor.a);
|
||||
// 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 * uLightFactor * v_distance - ((u_flags & RF_ShadeInterpolate) != 0.0? 0.5 : 0.0), 0.0);
|
||||
float numShades = float(uPalLightLevels & 255);
|
||||
float shade = clamp((uLightLevel + visibility), 0.0, numShades - 1.0);
|
||||
|
@ -207,13 +198,17 @@ void main()
|
|||
|
||||
palettedColor.a = color.r == 0.0? 0.0 : 1.0;// 1.0-floor(color.r);
|
||||
color = palettedColor;
|
||||
color.rgb *= detailColor.rgb; // with all this palettizing, this can only be applied afterward, even though it is wrong to do it this way.
|
||||
color.rgb *= v_color.rgb; // Well, this is dead wrong but unavoidable. For colored fog it applies the light to the fog as well...
|
||||
}
|
||||
else
|
||||
{
|
||||
color.rgb *= detailColor.rgb;
|
||||
|
||||
// This was further down but it really should be done before applying any kind of depth fading, not afterward.
|
||||
if ((uTextureMode & TEXF_Detailmap) != 0)
|
||||
{
|
||||
vec4 detailColor = texture(detailtexture, newCoord * uDetailParms.xy) * uDetailParms.z;
|
||||
detailColor = mix(vec4(1.0), 2.0 * detailColor, detailColor.a);
|
||||
color.rgb *= detailColor.rgb;
|
||||
}
|
||||
|
||||
// Apply the texture modification colors.
|
||||
int blendflags = int(uTextureAddColor.a); // this alpha is unused otherwise
|
||||
if (blendflags != 0)
|
||||
|
@ -224,10 +219,10 @@ void main()
|
|||
|
||||
if (uFogEnabled != 0) // Right now this code doesn't care about the fog modes yet.
|
||||
{
|
||||
shade = clamp(shade * uLightDist, 0.0, 1.0); // u_shadeDiv is really 1/shadeDiv.
|
||||
shade = clamp(shade * uLightDist, 0.0, 1.0);
|
||||
vec3 lightcolor = v_color.rgb * (1.0 - shade);
|
||||
|
||||
if ((u_flags & RF_Brightmapping) != 0)
|
||||
if ((uTextureMode & TEXF_Brightmap) != 0)
|
||||
{
|
||||
lightcolor = clamp(lightcolor + texture(brighttexture, v_texCoord.xy).rgb, 0.0, 1.0);
|
||||
}
|
||||
|
@ -235,6 +230,13 @@ void main()
|
|||
if (uFogDensity == 0.0) color.rgb += uFogColor.rgb * shade;
|
||||
}
|
||||
else color.rgb *= v_color.rgb;
|
||||
|
||||
if ((uTextureMode & TEXF_Glowmap) != 0)
|
||||
{
|
||||
vec4 glowColor = texture(glowtexture, v_texCoord.xy);
|
||||
color.rgb = mix(color.rgb, glowColor.rgb, glowColor.a);
|
||||
}
|
||||
|
||||
}
|
||||
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.
|
||||
{
|
||||
|
@ -250,11 +252,6 @@ void main()
|
|||
color = v_color;
|
||||
}
|
||||
|
||||
if ((u_flags & (RF_ColorOnly|RF_GlowMapping)) == RF_GlowMapping)
|
||||
{
|
||||
vec4 glowColor = texture(glowtexture, v_texCoord.xy);
|
||||
color.rgb = mix(color.rgb, glowColor.rgb, glowColor.a);
|
||||
}
|
||||
|
||||
/*
|
||||
int ix = int (v_worldPosition.x);
|
||||
|
|
Loading…
Reference in a new issue