mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-11 10:40:47 +00:00
- upgraded the polymost fragment shader to GLSL 3.3 as well, removing all legacy features from it.
The only compatibility mode feature left is the main drawer function using glBegin/glEnd but changing that is not as urgent as the rest. This also cleans up the fog application and adds the exponential fog mode again that somehow got lost over time.
This commit is contained in:
parent
3d538b4c8f
commit
cf30f5560b
6 changed files with 51 additions and 30 deletions
|
@ -21,6 +21,8 @@ struct PolymostRenderState
|
|||
float NPOTEmulationXOffset;
|
||||
float Brightness = 1.f;
|
||||
float ShadeInterpolate = 1.f;
|
||||
float Fog[4];
|
||||
float FogColor[4];
|
||||
|
||||
void Apply(PolymostShader *shader);
|
||||
};
|
||||
|
|
|
@ -156,14 +156,17 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char
|
|||
NPOTEmulationFactor.Init(hShader, "u_npotEmulationFactor");
|
||||
NPOTEmulationXOffset.Init(hShader, "u_npotEmulationXOffset");
|
||||
Brightness.Init(hShader, "u_brightness");
|
||||
ShadeInterpolate.Init(hShader, "u_shadeInterpolate");
|
||||
Fog.Init(hShader, "u_fog");
|
||||
FogColor.Init(hShader, "u_fogColor");
|
||||
|
||||
RotMatrix.Init(hShader, "u_rotMatrix");
|
||||
ModelMatrix.Init(hShader, "u_modelMatrix");
|
||||
ProjectionMatrix.Init(hShader, "u_projectionMatrix");
|
||||
DetailMatrix.Init(hShader, "u_detailMatrix");
|
||||
GlowMatrix.Init(hShader, "u_glowMatrix");
|
||||
|
||||
ShadeInterpolate.Init(hShader, "u_shadeInterpolate");
|
||||
|
||||
|
||||
glUseProgram(hShader);
|
||||
|
||||
int SamplerLoc;
|
||||
|
|
|
@ -50,12 +50,15 @@ public:
|
|||
FBufferedUniform1f NPOTEmulationFactor;
|
||||
FBufferedUniform1f NPOTEmulationXOffset;
|
||||
FBufferedUniform1f Brightness;
|
||||
FUniformMatrix4f RotMatrix;
|
||||
FBufferedUniform4f Fog;
|
||||
FBufferedUniform4f FogColor;
|
||||
FBufferedUniform1f ShadeInterpolate;
|
||||
|
||||
FUniformMatrix4f RotMatrix;
|
||||
FUniformMatrix4f ModelMatrix;
|
||||
FUniformMatrix4f ProjectionMatrix;
|
||||
FUniformMatrix4f DetailMatrix;
|
||||
FUniformMatrix4f GlowMatrix;
|
||||
FBufferedUniform1f ShadeInterpolate;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -326,17 +326,18 @@ void GLInstance::SetDepthFunc(int func)
|
|||
|
||||
void GLInstance::SetFogLinear(float* color, float start, float end)
|
||||
{
|
||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||
glFogf(GL_FOG_START, start);
|
||||
glFogf(GL_FOG_END, end);
|
||||
glFogfv(GL_FOG_COLOR, color);
|
||||
}
|
||||
renderState.Fog[0] = end;
|
||||
renderState.Fog[1] = 1.f / (end - start);
|
||||
renderState.Fog[2] = 0.f;
|
||||
memcpy(renderState.FogColor, color, 4 * sizeof(float));
|
||||
};
|
||||
|
||||
void GLInstance::SetFogExp2(float* color, float coefficient)
|
||||
{
|
||||
glFogi(GL_FOG_MODE, GL_EXP2);
|
||||
glFogf(GL_FOG_DENSITY, coefficient);
|
||||
glFogfv(GL_FOG_COLOR, color);
|
||||
renderState.Fog[0] =
|
||||
renderState.Fog[1] = 0.f;
|
||||
renderState.Fog[2] = coefficient;
|
||||
memcpy(renderState.FogColor, color, 4 * sizeof(float));
|
||||
}
|
||||
|
||||
void GLInstance::SetColorMask(bool on)
|
||||
|
@ -441,6 +442,8 @@ void PolymostRenderState::Apply(PolymostShader* shader)
|
|||
shader->NPOTEmulationXOffset.Set(NPOTEmulationXOffset);
|
||||
shader->ShadeInterpolate.Set(ShadeInterpolate);
|
||||
shader->Brightness.Set(Brightness);
|
||||
shader->Fog.Set(Fog);
|
||||
shader->FogColor.Set(FogColor);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -274,6 +274,7 @@ public:
|
|||
{
|
||||
renderState.Brightness = 8.f / (brightness + 8.f);
|
||||
}
|
||||
|
||||
|
||||
FTexture *GetTexture(const char *filename);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#version 120
|
||||
|
||||
#extension GL_ARB_uniform_buffer_object:enable
|
||||
#version 330
|
||||
|
||||
//s_texture points to an indexed color texture
|
||||
uniform sampler2D s_texture;
|
||||
|
@ -29,6 +27,8 @@ uniform float u_npotEmulationFactor;
|
|||
uniform float u_npotEmulationXOffset;
|
||||
uniform float u_shadeInterpolate;
|
||||
uniform float u_brightness;
|
||||
uniform vec4 u_fog;
|
||||
uniform vec4 u_fogColor;
|
||||
|
||||
uniform float u_useDetailMapping;
|
||||
uniform float u_useGlowMapping;
|
||||
|
@ -36,12 +36,12 @@ uniform float u_useGlowMapping;
|
|||
uniform int u_tinteffect;
|
||||
uniform vec3 u_tintcolor;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying float v_distance;
|
||||
varying vec4 v_texCoord;
|
||||
varying vec4 v_detailCoord;
|
||||
varying vec4 v_glowCoord;
|
||||
varying float v_fogCoord;
|
||||
in vec4 v_color;
|
||||
in float v_distance;
|
||||
in vec4 v_texCoord;
|
||||
in vec4 v_detailCoord;
|
||||
in vec4 v_glowCoord;
|
||||
in float v_fogCoord;
|
||||
|
||||
const float c_basepalScale = 255.0/256.0;
|
||||
const float c_basepalOffset = 0.5/256.0;
|
||||
|
@ -52,6 +52,8 @@ const float c_two = 2.0;
|
|||
const vec4 c_vec4_one = vec4(c_one);
|
||||
const float c_wrapThreshold = 0.9;
|
||||
|
||||
layout(location=0) out vec4 fragColor;
|
||||
|
||||
layout(std140) uniform Palette {
|
||||
vec4 palette[256];
|
||||
};
|
||||
|
@ -154,7 +156,7 @@ void main()
|
|||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;
|
||||
vec4 palettedColorNext = texture2D(s_palette, vec2(colorIndex, c_zero));
|
||||
palettedColor.rgb = mix(palettedColor.rgb, palettedColorNext.rgb, shadeFrac*u_shadeInterpolate);
|
||||
float fullbright = mix(u_usePalette*palettedColor.a, c_zero, u_useColorOnly);
|
||||
float fullbright = mix(u_usePalette*palettedColor.a, c_zero, u_useColorOnly); // This only gets set for paletted rendering.
|
||||
palettedColor.a = c_one-floor(color.r);
|
||||
color = mix(color, palettedColor, u_usePalette);
|
||||
|
||||
|
@ -165,24 +167,31 @@ void main()
|
|||
color.rgb *= detailColor.rgb;
|
||||
}
|
||||
|
||||
// should be an 'else' to all the above.
|
||||
color = mix(color, c_vec4_one, u_useColorOnly);
|
||||
|
||||
// only relevant for paletted rendering - in true color this requires a fifth color channel (i.e. an external brightmap - work for later) or an overlay (current implementation)
|
||||
color.rgb = mix(v_color.rgb*color.rgb, color.rgb, fullbright);
|
||||
|
||||
float fogEnabled = mix(u_fogEnabled, c_zero, u_usePalette);
|
||||
fullbright = max(c_one-fogEnabled, fullbright);
|
||||
float fogFactor = clamp((gl_Fog.end-v_fogCoord)*gl_Fog.scale, fullbright, c_one);
|
||||
//float fogFactor = clamp(v_fogCoord, fullbright, c_one);
|
||||
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);
|
||||
if (u_usePalette == 0.0 && u_fogEnabled != 0.0)// the following would make sense if 'fullbright' could ever be true in non-paletted rendering: && (fullbright != 0.0 || u_fogColor.rgb != vec3(0.0) ))
|
||||
{
|
||||
float fogFactor;
|
||||
|
||||
if (u_useGlowMapping != 0.0)
|
||||
if (u_fog.z == 0) fogFactor = (u_fog.x-v_fogCoord)*u_fog.y; // linear fog
|
||||
else fogFactor = exp2 (u_fog.z * v_fogCoord); // exponential fog
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
color.rgb = mix(u_fogColor.rgb, color.rgb, fogFactor);
|
||||
}
|
||||
|
||||
if (u_useGlowMapping != 0.0 && u_useColorOnly == 0.0)
|
||||
{
|
||||
vec4 glowColor = texture2D(s_glow, v_glowCoord.xy);
|
||||
color.rgb = mix(color.rgb, glowColor.rgb, glowColor.a*(c_one-u_useColorOnly));
|
||||
color.rgb = mix(color.rgb, glowColor.rgb, glowColor.a);
|
||||
}
|
||||
|
||||
color.a *= v_color.a;
|
||||
color.rgb = pow(color.rgb, vec3(u_brightness));
|
||||
|
||||
gl_FragData[0] = color;
|
||||
fragColor = color;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue