mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-23 09:51:26 +00:00
108 lines
3.2 KiB
GLSL
108 lines
3.2 KiB
GLSL
|
|
//===========================================================================
|
|
//
|
|
// Vanilla Doom wall colormap equation
|
|
//
|
|
//===========================================================================
|
|
float R_WallColormap(float lightnum, float z, vec3 normal)
|
|
{
|
|
// R_ScaleFromGlobalAngle calculation
|
|
float projection = 160.0; // projection depends on SCREENBLOCKS!! 160 is the fullscreen value
|
|
vec2 line_v1 = pixelpos.xz; // in vanilla this is the first curline vertex
|
|
vec2 line_normal = normal.xz;
|
|
float texscale = projection * clamp(dot(normalize(uCameraPos.xz - line_v1), line_normal), 0.0, 1.0) / z;
|
|
|
|
float lightz = clamp(16.0 * texscale, 0.0, 47.0);
|
|
|
|
// scalelight[lightnum][lightz] lookup
|
|
float startmap = (15.0 - lightnum) * 4.0;
|
|
return startmap - lightz * 0.5;
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// Vanilla Doom plane colormap equation
|
|
//
|
|
//===========================================================================
|
|
float R_PlaneColormap(float lightnum, float z)
|
|
{
|
|
float lightz = clamp(z / 16.0f, 0.0, 127.0);
|
|
|
|
// zlight[lightnum][lightz] lookup
|
|
float startmap = (15.0 - lightnum) * 4.0;
|
|
float scale = 160.0 / (lightz + 1.0);
|
|
return startmap - scale * 0.5;
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// zdoom colormap equation
|
|
//
|
|
//===========================================================================
|
|
float R_ZDoomColormap(float light, float z)
|
|
{
|
|
float L = light * 255.0;
|
|
float vis = min(uGlobVis / z, 24.0 / 32.0);
|
|
float shade = 2.0 - (L + 12.0) / 128.0;
|
|
float lightscale = shade - vis;
|
|
return lightscale * 31.0;
|
|
}
|
|
|
|
float R_DoomColormap(float light, float z)
|
|
{
|
|
if ((uPalLightLevels >> 16) == 16) // gl_lightmode 16
|
|
{
|
|
float lightnum = clamp(light * 15.0, 0.0, 15.0);
|
|
|
|
if (dot(vWorldNormal.xyz, vWorldNormal.xyz) > 0.5)
|
|
{
|
|
vec3 normal = normalize(vWorldNormal.xyz);
|
|
return mix(R_WallColormap(lightnum, z, normal), R_PlaneColormap(lightnum, z), abs(normal.y));
|
|
}
|
|
else // vWorldNormal is not set on sprites
|
|
{
|
|
return R_PlaneColormap(lightnum, z);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return R_ZDoomColormap(light, z);
|
|
}
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// Doom software lighting equation
|
|
//
|
|
//===========================================================================
|
|
float R_DoomLightingEquation(float light)
|
|
{
|
|
// z is the depth in view space, positive going into the screen
|
|
float z;
|
|
if (((uPalLightLevels >> 8) & 0xff) == 2)
|
|
{
|
|
z = distance(pixelpos.xyz, uCameraPos.xyz);
|
|
}
|
|
else
|
|
{
|
|
z = pixelpos.w;
|
|
}
|
|
|
|
if ((uPalLightLevels >> 16) == 5) // gl_lightmode 5: Build software lighting emulation.
|
|
{
|
|
// This is a lot more primitive than Doom's lighting...
|
|
float numShades = float(uPalLightLevels & 255);
|
|
float curshade = (1.0 - light) * (numShades - 1.0);
|
|
float visibility = max(uGlobVis * uLightFactor * z, 0.0);
|
|
float shade = clamp((curshade + visibility), 0.0, numShades - 1.0);
|
|
return clamp(shade * uLightDist, 0.0, 1.0);
|
|
}
|
|
|
|
float colormap = R_DoomColormap(light, z);
|
|
|
|
if ((uPalLightLevels & 0xff) != 0)
|
|
colormap = floor(colormap) + 0.5;
|
|
|
|
// Result is the normalized colormap index (0 bright .. 1 dark)
|
|
return clamp(colormap, 0.0, 31.0) / 32.0;
|
|
}
|