Restore old colormap algorithm (now as an option!)
This commit is contained in:
parent
7ff01fa779
commit
286592bd97
6 changed files with 112 additions and 61 deletions
|
|
@ -278,6 +278,7 @@ struct FLightInfo
|
|||
FUINT light_level;
|
||||
FUINT fade_start;
|
||||
FUINT fade_end;
|
||||
boolean newfade;
|
||||
boolean directional;
|
||||
};
|
||||
typedef struct FLightInfo FLightInfo;
|
||||
|
|
|
|||
|
|
@ -313,6 +313,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col
|
|||
Surface->LightInfo.light_level = light_level;
|
||||
Surface->LightInfo.fade_start = (colormap != NULL) ? colormap->fadestart : 0;
|
||||
Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31;
|
||||
Surface->LightInfo.newfade = (colormap != NULL) ? !!(colormap->flags & CMF_NEWFADE) : false;
|
||||
|
||||
Surface->LightInfo.directional = (maplighting.directional == true && directional == true);
|
||||
}
|
||||
|
|
@ -3244,6 +3245,7 @@ static void HWR_LinkDrawHackFinish(void)
|
|||
surf.LightInfo.light_level = 0;
|
||||
surf.LightInfo.fade_start = 0;
|
||||
surf.LightInfo.fade_end = 31;
|
||||
surf.LightInfo.newfade = false;
|
||||
for (i = 0; i < linkdrawcount; i++)
|
||||
{
|
||||
// draw sprite shape, only to z-buffer
|
||||
|
|
|
|||
|
|
@ -591,6 +591,7 @@ typedef enum
|
|||
gluniform_lighting,
|
||||
gluniform_fade_start,
|
||||
gluniform_fade_end,
|
||||
gluniform_newfade,
|
||||
gluniform_light_dir,
|
||||
gluniform_light_contrast,
|
||||
gluniform_light_backlight,
|
||||
|
|
@ -672,38 +673,43 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
|
|||
"float fd = fe - fs;\n" \
|
||||
"darkness = clamp((darkness - fs) * (1.0 / fd), 0.0, 1.0);\n" \
|
||||
"}\n" \
|
||||
"float colorBrightness = sqrt((final_color.r * final_color.r) + (final_color.g * final_color.g) + (final_color.b * final_color.b));\n" \
|
||||
"float fogBrightness = sqrt((fade_color.r * fade_color.r) + (fade_color.g * fade_color.g) + (fade_color.b * fade_color.b));\n" \
|
||||
"float colorIntensity = 0.0;\n" \
|
||||
"if (colorBrightness < fogBrightness) {\n" \
|
||||
"colorIntensity = 1.0 - min(final_color.r, min(final_color.g, final_color.b));\n" \
|
||||
"colorIntensity = abs(colorIntensity - (1.0 - max(fade_color.r, max(fade_color.g, fade_color.b))));\n" \
|
||||
"if (newfade)\n" \
|
||||
"{\n" \
|
||||
"float colorBrightness = sqrt((final_color.r * final_color.r) + (final_color.g * final_color.g) + (final_color.b * final_color.b));\n" \
|
||||
"float fogBrightness = sqrt((fade_color.r * fade_color.r) + (fade_color.g * fade_color.g) + (fade_color.b * fade_color.b));\n" \
|
||||
"float colorIntensity = 0.0;\n" \
|
||||
"if (colorBrightness < fogBrightness) {\n" \
|
||||
"colorIntensity = 1.0 - min(final_color.r, min(final_color.g, final_color.b));\n" \
|
||||
"colorIntensity = abs(colorIntensity - (1.0 - max(fade_color.r, max(fade_color.g, fade_color.b))));\n" \
|
||||
"} else {\n" \
|
||||
"colorIntensity = max(final_color.r, max(final_color.g, final_color.b));\n" \
|
||||
"colorIntensity = abs(colorIntensity - min(fade_color.r, min(fade_color.g, fade_color.b)));\n" \
|
||||
"}\n" \
|
||||
"colorIntensity *= darkness;\n" \
|
||||
"colorIntensity *= fade_color.a * 10.0;\n" \
|
||||
"if (abs(final_color.r - fade_color.r) <= colorIntensity) {\n" \
|
||||
"final_color.r = fade_color.r;\n" \
|
||||
"} else if (final_color.r < fade_color.r) {\n" \
|
||||
"final_color.r += colorIntensity;\n" \
|
||||
"} else {\n" \
|
||||
"final_color.r -= colorIntensity;\n" \
|
||||
"}\n" \
|
||||
"if (abs(final_color.g - fade_color.g) <= colorIntensity) {\n" \
|
||||
"final_color.g = fade_color.g;\n" \
|
||||
"} else if (final_color.g < fade_color.g) {\n" \
|
||||
"final_color.g += colorIntensity;\n" \
|
||||
"} else {\n" \
|
||||
"final_color.g -= colorIntensity;\n" \
|
||||
"}\n" \
|
||||
"if (abs(final_color.b - fade_color.b) <= colorIntensity) {\n" \
|
||||
"final_color.b = fade_color.b;\n" \
|
||||
"} else if (final_color.b < fade_color.b) {\n" \
|
||||
"final_color.b += colorIntensity;\n" \
|
||||
"} else {\n" \
|
||||
"final_color.b -= colorIntensity;\n" \
|
||||
"}\n" \
|
||||
"} else {\n" \
|
||||
"colorIntensity = max(final_color.r, max(final_color.g, final_color.b));\n" \
|
||||
"colorIntensity = abs(colorIntensity - min(fade_color.r, min(fade_color.g, fade_color.b)));\n" \
|
||||
"}\n" \
|
||||
"colorIntensity *= darkness;\n" \
|
||||
"colorIntensity *= fade_color.a * 10.0;\n" \
|
||||
"if (abs(final_color.r - fade_color.r) <= colorIntensity) {\n" \
|
||||
"final_color.r = fade_color.r;\n" \
|
||||
"} else if (final_color.r < fade_color.r) {\n" \
|
||||
"final_color.r += colorIntensity;\n" \
|
||||
"} else {\n" \
|
||||
"final_color.r -= colorIntensity;\n" \
|
||||
"}\n" \
|
||||
"if (abs(final_color.g - fade_color.g) <= colorIntensity) {\n" \
|
||||
"final_color.g = fade_color.g;\n" \
|
||||
"} else if (final_color.g < fade_color.g) {\n" \
|
||||
"final_color.g += colorIntensity;\n" \
|
||||
"} else {\n" \
|
||||
"final_color.g -= colorIntensity;\n" \
|
||||
"}\n" \
|
||||
"if (abs(final_color.b - fade_color.b) <= colorIntensity) {\n" \
|
||||
"final_color.b = fade_color.b;\n" \
|
||||
"} else if (final_color.b < fade_color.b) {\n" \
|
||||
"final_color.b += colorIntensity;\n" \
|
||||
"} else {\n" \
|
||||
"final_color.b -= colorIntensity;\n" \
|
||||
"final_color = mix(final_color, fade_color, darkness);\n" \
|
||||
"}\n"
|
||||
|
||||
// ================
|
||||
|
|
@ -776,6 +782,7 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
|
|||
"uniform float lighting;\n" \
|
||||
"uniform float fade_start;\n" \
|
||||
"uniform float fade_end;\n" \
|
||||
"uniform bool newfade;\n" \
|
||||
GLSL_DOOM_COLORMAP \
|
||||
GLSL_DOOM_LIGHT_EQUATION \
|
||||
"void main(void) {\n" \
|
||||
|
|
@ -801,6 +808,7 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
|
|||
"uniform vec4 fade_color;\n" \
|
||||
"uniform float fade_start;\n" \
|
||||
"uniform float fade_end;\n" \
|
||||
"uniform bool newfade;\n" \
|
||||
GLSL_DOOM_COLORMAP \
|
||||
GLSL_DOOM_LIGHT_EQUATION \
|
||||
"void main(void) {\n" \
|
||||
|
|
@ -833,6 +841,7 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
|
|||
"uniform float lighting;\n" \
|
||||
"uniform float fade_start;\n" \
|
||||
"uniform float fade_end;\n" \
|
||||
"uniform bool newfade;\n" \
|
||||
"uniform float leveltime;\n" \
|
||||
"const float freq = 0.025;\n" \
|
||||
"const float amp = 0.025;\n" \
|
||||
|
|
@ -869,6 +878,7 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
|
|||
"uniform float lighting;\n" \
|
||||
"uniform float fade_start;\n" \
|
||||
"uniform float fade_end;\n" \
|
||||
"uniform bool newfade;\n" \
|
||||
GLSL_DOOM_COLORMAP \
|
||||
GLSL_DOOM_LIGHT_EQUATION \
|
||||
"void main(void) {\n" \
|
||||
|
|
@ -2174,6 +2184,7 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
|
|||
UNIFORM_1(shader->uniforms[gluniform_lighting], Surface->LightInfo.light_level, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_fade_start], Surface->LightInfo.fade_start, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_fade_end], Surface->LightInfo.fade_end, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_newfade], Surface->LightInfo.newfade, pglUniform1i);
|
||||
directional = Surface->LightInfo.directional;
|
||||
}
|
||||
else
|
||||
|
|
@ -2181,6 +2192,7 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
|
|||
UNIFORM_1(shader->uniforms[gluniform_lighting], 255, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_fade_start], 0, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_fade_end], 31, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_newfade], false, pglUniform1i);
|
||||
}
|
||||
|
||||
if (directional)
|
||||
|
|
@ -2297,6 +2309,7 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i, const GLchar
|
|||
shader->uniforms[gluniform_lighting] = GETUNI("lighting");
|
||||
shader->uniforms[gluniform_fade_start] = GETUNI("fade_start");
|
||||
shader->uniforms[gluniform_fade_end] = GETUNI("fade_end");
|
||||
shader->uniforms[gluniform_newfade] = GETUNI("newfade");
|
||||
shader->uniforms[gluniform_light_dir] = GETUNI("light_dir");
|
||||
shader->uniforms[gluniform_light_contrast] = GETUNI("light_contrast");
|
||||
shader->uniforms[gluniform_light_backlight] = GETUNI("light_backlight");
|
||||
|
|
|
|||
|
|
@ -3268,6 +3268,7 @@ static void P_LoadTextmap(void)
|
|||
P_InitializeSector(sc);
|
||||
if (textmap_colormap.used)
|
||||
{
|
||||
textmap_colormap.flags |= CMF_NEWFADE; // TODO: an actual option?
|
||||
INT32 rgba = P_ColorToRGBA(textmap_colormap.lightcolor, textmap_colormap.lightalpha);
|
||||
INT32 fadergba = P_ColorToRGBA(textmap_colormap.fadecolor, textmap_colormap.fadealpha);
|
||||
sc->extra_colormap = sc->spawn_extra_colormap = R_CreateColormap(rgba, fadergba, textmap_colormap.fadestart, textmap_colormap.fadeend, textmap_colormap.flags);
|
||||
|
|
|
|||
93
src/r_data.c
93
src/r_data.c
|
|
@ -637,6 +637,7 @@ extracolormap_t *R_ColormapForName(char *name)
|
|||
// data and not the colormap data.
|
||||
//
|
||||
static double brightChange[256], map[256][3];
|
||||
static double deltas[256][3]; // for old fade colormaps
|
||||
|
||||
static int RoundUp(double number);
|
||||
|
||||
|
|
@ -722,22 +723,31 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
|||
if (map[i][2] > 255.0l)
|
||||
map[i][2] = 255.0l;
|
||||
|
||||
// Get the "best" color.
|
||||
// Our brightest color's value, if we're fading to a darker color,
|
||||
// or our (inverted) darkest color's value, if we're fading to a brighter color.
|
||||
if (cbrightness < cdestbright)
|
||||
if (extra_colormap->flags & CMF_NEWFADE)
|
||||
{
|
||||
cbest = 255.0l - min(r, min(g, b));
|
||||
cdist = 255.0l - max(cdestr, max(cdestg, cdestb));
|
||||
// Get the "best" color.
|
||||
// Our brightest color's value, if we're fading to a darker color,
|
||||
// or our (inverted) darkest color's value, if we're fading to a brighter color.
|
||||
if (cbrightness < cdestbright)
|
||||
{
|
||||
cbest = 255.0l - min(r, min(g, b));
|
||||
cdist = 255.0l - max(cdestr, max(cdestg, cdestb));
|
||||
}
|
||||
else
|
||||
{
|
||||
cbest = max(r, max(g, b));
|
||||
cdist = min(cdestr, min(cdestg, cdestb));
|
||||
}
|
||||
|
||||
// Add/subtract this value during fading.
|
||||
brightChange[i] = (fabs(cbest - cdist) / (double)fadedist) * fmaskamt;
|
||||
}
|
||||
else
|
||||
{
|
||||
cbest = max(r, max(g, b));
|
||||
cdist = min(cdestr, min(cdestg, cdestb));
|
||||
deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist;
|
||||
deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist;
|
||||
deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist;
|
||||
}
|
||||
|
||||
// Add/subtract this value during fading.
|
||||
brightChange[i] = (fabs(cbest - cdist) / (double)fadedist) * fmaskamt;
|
||||
}
|
||||
|
||||
// Now allocate memory for the actual colormap array itself!
|
||||
|
|
@ -759,27 +769,47 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
|||
if ((UINT32)p < fadestart)
|
||||
continue;
|
||||
|
||||
// Add/subtract towards the destination color.
|
||||
if (fabs(map[i][0] - cdestr) <= brightChange[i])
|
||||
map[i][0] = cdestr;
|
||||
else if (map[i][0] > cdestr)
|
||||
map[i][0] -= brightChange[i];
|
||||
else
|
||||
map[i][0] += brightChange[i];
|
||||
if (extra_colormap->flags & CMF_NEWFADE)
|
||||
{
|
||||
// Add/subtract towards the destination color.
|
||||
if (fabs(map[i][0] - cdestr) <= brightChange[i])
|
||||
map[i][0] = cdestr;
|
||||
else if (map[i][0] > cdestr)
|
||||
map[i][0] -= brightChange[i];
|
||||
else
|
||||
map[i][0] += brightChange[i];
|
||||
|
||||
if (fabs(map[i][1] - cdestg) <= brightChange[i])
|
||||
map[i][1] = cdestg;
|
||||
else if (map[i][1] > cdestg)
|
||||
map[i][1] -= brightChange[i];
|
||||
else
|
||||
map[i][1] += brightChange[i];
|
||||
if (fabs(map[i][1] - cdestg) <= brightChange[i])
|
||||
map[i][1] = cdestg;
|
||||
else if (map[i][1] > cdestg)
|
||||
map[i][1] -= brightChange[i];
|
||||
else
|
||||
map[i][1] += brightChange[i];
|
||||
|
||||
if (fabs(map[i][2] - cdestb) <= brightChange[i])
|
||||
map[i][2] = cdestb;
|
||||
else if (map[i][2] > cdestb)
|
||||
map[i][2] -= brightChange[i];
|
||||
if (fabs(map[i][2] - cdestb) <= brightChange[i])
|
||||
map[i][2] = cdestb;
|
||||
else if (map[i][2] > cdestb)
|
||||
map[i][2] -= brightChange[i];
|
||||
else
|
||||
map[i][2] += brightChange[i];
|
||||
}
|
||||
else
|
||||
map[i][2] += brightChange[i];
|
||||
{
|
||||
if (fabs(map[i][0] - cdestr) > fabs(deltas[i][0]))
|
||||
map[i][0] -= deltas[i][0];
|
||||
else
|
||||
map[i][0] = cdestr;
|
||||
|
||||
if (fabs(map[i][1] - cdestg) > fabs(deltas[i][1]))
|
||||
map[i][1] -= deltas[i][1];
|
||||
else
|
||||
map[i][1] = cdestg;
|
||||
|
||||
if (fabs(map[i][2] - cdestb) > fabs(deltas[i][1])) // typo alert!
|
||||
map[i][2] -= deltas[i][2];
|
||||
else
|
||||
map[i][2] = cdestb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -861,7 +891,7 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3)
|
|||
{
|
||||
if (p2[1])
|
||||
{
|
||||
flags = NUMFROMCHAR(p2[1]);
|
||||
flags = HEX2INT(p2[1]);
|
||||
if (p2[2] && p2[3])
|
||||
{
|
||||
fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10);
|
||||
|
|
@ -921,6 +951,9 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3)
|
|||
#undef ALPHA2INT
|
||||
#undef HEX2INT
|
||||
|
||||
if (!(flags & CMF_NEWFADE))
|
||||
cfa = 25; // no fade alpha in kart!
|
||||
|
||||
if (encoremap)
|
||||
{
|
||||
UINT8 j = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)];
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ typedef UINT8 lighttable_t;
|
|||
|
||||
#define CMF_FADEFULLBRIGHTSPRITES 1
|
||||
#define CMF_FOG (udmf ? 4 : 1)
|
||||
#define CMF_NEWFADE 8
|
||||
|
||||
// ExtraColormap type. Use for extra_colormaps from now on.
|
||||
struct extracolormap_t
|
||||
|
|
|
|||
Loading…
Reference in a new issue