port rr´s directional light
This commit is contained in:
1 parent
de4bcec782
commit
8c295e8d5f
25 files changed
+465
-83
No files matched your search
@@ -967,6 +967,27 @@ static void readlevelheader(MYFILE *f, INT32 num, INT32 wadnum)
|
||||
}*/
|
||||
else if (fastcmp(word, "MOBJSCALE"))
|
||||
mapheaderinfo[num-1]->mobj_scale = get_number(word2);
|
||||
else if (fastcmp(word, "LIGHTCONTRAST"))
|
||||
{
|
||||
mapheaderinfo[num-1]->light_contrast = (UINT8)i;
|
||||
}
|
||||
else if (fastcmp(word, "SPRITEBACKLIGHT"))
|
||||
{
|
||||
mapheaderinfo[num-1]->sprite_backlight = (SINT8)i;
|
||||
}
|
||||
else if (fastcmp(word, "LIGHTANGLE"))
|
||||
{
|
||||
if (fastcmp(word2, "EVEN"))
|
||||
{
|
||||
mapheaderinfo[num-1]->use_light_angle = false;
|
||||
mapheaderinfo[num-1]->light_angle = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapheaderinfo[num-1]->use_light_angle = true;
|
||||
mapheaderinfo[num-1]->light_angle = FixedAngle(FloatToFixed(atof(word2)));
|
||||
}
|
||||
}
|
||||
|
||||
// Individual triggers for level flags, for ease of use (and 2.0 compatibility)
|
||||
else if (fastcmp(word, "SCRIPTISFILE"))
|
||||
|
||||
@@ -259,6 +259,11 @@ typedef struct
|
||||
//boolean automap; ///< Displays a level's white map outline in modified games
|
||||
fixed_t mobj_scale; ///< Replacement for TOL_ERZ3
|
||||
|
||||
UINT8 light_contrast; ///< Range of wall lighting. 0 is no lighting.
|
||||
SINT8 sprite_backlight; ///< Subtract from wall lighting for sprites only.
|
||||
boolean use_light_angle; ///< When false, wall lighting is evenly distributed. When true, wall lighting is directional.
|
||||
angle_t light_angle; ///< Angle of directional wall lighting.
|
||||
|
||||
// Music stuff.
|
||||
UINT32 musinterfadeout; ///< Fade out level music on intermission screen in milliseconds
|
||||
char musintername[7]; ///< Intermission screen music.
|
||||
@@ -445,6 +450,14 @@ extern tic_t racecountdown, exitcountdown;
|
||||
extern fixed_t gravity;
|
||||
extern fixed_t mapobjectscale;
|
||||
|
||||
extern struct maplighting
|
||||
{
|
||||
UINT8 contrast;
|
||||
SINT8 backlight;
|
||||
boolean directional;
|
||||
angle_t angle;
|
||||
} maplighting;
|
||||
|
||||
//for CTF balancing
|
||||
extern INT16 autobalance;
|
||||
extern INT16 teamscramble;
|
||||
|
||||
@@ -243,6 +243,8 @@ tic_t racecountdown, exitcountdown; // for racing
|
||||
fixed_t gravity;
|
||||
fixed_t mapobjectscale;
|
||||
|
||||
struct maplighting maplighting;
|
||||
|
||||
INT16 autobalance; //for CTF team balance
|
||||
INT16 teamscramble; //for CTF team scramble
|
||||
INT16 scrambleplayers[MAXPLAYERS]; //for CTF team scramble
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "hw_main.h"
|
||||
#include "../i_system.h"
|
||||
|
||||
#include "../doomdef.h"
|
||||
|
||||
#include "../qs22j.h"
|
||||
|
||||
// The texture for the next polygon given to HWR_ProcessPolygon.
|
||||
@@ -178,6 +180,10 @@ static int comparePolygons(const void *p1, const void *p2)
|
||||
diff = poly1->surf.LightInfo.fade_start - poly2->surf.LightInfo.fade_start;
|
||||
if (diff != 0) return diff;
|
||||
diff = poly1->surf.LightInfo.fade_end - poly2->surf.LightInfo.fade_end;
|
||||
if (diff != 0) return diff;
|
||||
|
||||
diff = poly1->surf.LightInfo.directional - poly2->surf.LightInfo.directional;
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
@@ -241,6 +247,7 @@ void HWR_RenderBatches(void)
|
||||
nextSurfaceInfo.LightInfo.fade_end = 0;
|
||||
nextSurfaceInfo.LightInfo.fade_start = 0;
|
||||
nextSurfaceInfo.LightInfo.light_level = 0;
|
||||
nextSurfaceInfo.LightInfo.directional = false;
|
||||
|
||||
currently_batching = false;// no longer collecting batches
|
||||
if (!polygonArraySize)
|
||||
@@ -392,7 +399,8 @@ void HWR_RenderBatches(void)
|
||||
currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
|
||||
currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
|
||||
currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
|
||||
currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end)
|
||||
currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end ||
|
||||
currentSurfaceInfo.LightInfo.directional != nextSurfaceInfo.LightInfo.directional)
|
||||
{
|
||||
changeState = true;
|
||||
changeSurfaceInfo = true;
|
||||
|
||||
@@ -303,6 +303,7 @@ struct FLightInfo
|
||||
FUINT light_level;
|
||||
FUINT fade_start;
|
||||
FUINT fade_end;
|
||||
boolean directional;
|
||||
};
|
||||
typedef struct FLightInfo FLightInfo;
|
||||
|
||||
@@ -341,6 +342,11 @@ typedef enum hwdsetspecialstate hwdspecialstate_t;
|
||||
enum hwdshaderinfo
|
||||
{
|
||||
HWD_SHADERINFO_LEVELTIME = 1,
|
||||
HWD_SHADERINFO_LIGHT_X,
|
||||
HWD_SHADERINFO_LIGHT_Y,
|
||||
HWD_SHADERINFO_LIGHT_Z,
|
||||
HWD_SHADERINFO_LIGHT_CONTRAST,
|
||||
HWD_SHADERINFO_LIGHT_BACKLIGHT,
|
||||
};
|
||||
|
||||
typedef enum hwdshaderinfo hwdshaderinfo_t;
|
||||
|
||||
@@ -43,6 +43,8 @@ typedef struct gl_vissprite_s
|
||||
INT32 dispoffset; // copy of info->dispoffset, affects ordering but not drawing
|
||||
} gl_vissprite_t;
|
||||
|
||||
void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 *lightlevel, boolean model);
|
||||
|
||||
// --------
|
||||
// hw_bsp.c
|
||||
// --------
|
||||
|
||||
+83
-35
@@ -14,13 +14,14 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "../doomstat.h"
|
||||
#include "../doomdef.h"
|
||||
|
||||
#include "../qs22j.h"
|
||||
|
||||
#ifdef HWRENDER
|
||||
#include "hw_main.h"
|
||||
#include "hw_glob.h"
|
||||
#include "hw_drv.h"
|
||||
#include "hw_gpu.h"
|
||||
#include "hw_batching.h"
|
||||
#include "hw_md2.h"
|
||||
#include "hw_clip.h"
|
||||
@@ -337,7 +338,48 @@ boolean HWR_PalRenderFlashpal(void)
|
||||
return (HWR_ShouldUsePaletteRendering() && cv_glflashpal.value);
|
||||
}
|
||||
|
||||
void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap)
|
||||
void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 *lightlevel, boolean model)
|
||||
{
|
||||
const boolean papersprite = (spr->mobj->frame & FF_PAPERSPRITE);
|
||||
|
||||
*lightlevel += R_ThingLightLevel(spr->mobj);
|
||||
|
||||
if (maplighting.directional == true && P_SectorUsesDirectionalLighting(sector))
|
||||
{
|
||||
if (model == false) // this is implemented by shader
|
||||
{
|
||||
fixed_t extralight = R_GetSpriteDirectionalLighting(
|
||||
papersprite
|
||||
? R_PointToAngle(spr->mobj->x, spr->mobj->y) + (spr->flip ? -ANGLE_90 : ANGLE_90)
|
||||
: R_PointToAngle(spr->mobj->x, spr->mobj->y) // fixme
|
||||
);
|
||||
|
||||
// Less change in contrast in dark sectors
|
||||
extralight = FixedMul(extralight, min(max(0, *lightlevel), 255) * FRACUNIT / 255);
|
||||
|
||||
if (papersprite)
|
||||
{
|
||||
// Papersprite contrast should match walls
|
||||
*lightlevel += FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
// simple OGL approximation
|
||||
fixed_t tr = R_PointToDist(spr->mobj->x, spr->mobj->y);
|
||||
fixed_t xscale = FixedDiv((vid.width / 2) << FRACBITS, tr);
|
||||
|
||||
// Less change in contrast at further distances, to counteract DOOM diminished light
|
||||
fixed_t n = FixedDiv(FixedMul(xscale, LIGHTRESOLUTIONFIX), ((MAXLIGHTSCALE-1) << LIGHTSCALESHIFT));
|
||||
extralight = FixedMul(extralight, min(n, FRACUNIT));
|
||||
|
||||
// Contrast is stronger for normal sprites, stronger than wall lighting is at the same distance
|
||||
*lightlevel += FixedFloor((extralight * 2) + (FRACUNIT / 2)) / FRACUNIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap, const boolean directional)
|
||||
{
|
||||
RGBA_t poly_color, tint_color, fade_color;
|
||||
|
||||
@@ -397,6 +439,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.directional = (maplighting.directional == true && directional == true);
|
||||
Surface->LightTableId = HWR_ShouldUsePaletteRendering() ? HWR_GetLightTableID(colormap) : 0;
|
||||
}
|
||||
|
||||
@@ -429,43 +472,31 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, seg_t *seg)
|
||||
{
|
||||
INT16 finallight = lightnum;
|
||||
|
||||
if (seg != NULL && cv_glfakecontrast.value != 0)
|
||||
if (seg != NULL && P_ApplyLightOffsetFine(lightnum, seg->frontsector) && cv_glfakecontrast.value != 0)
|
||||
{
|
||||
fixed_t extralight = 0;
|
||||
|
||||
if (cv_glfakecontrast.value == 2) // Smooth setting
|
||||
extralight += seg->hwLightOffset;
|
||||
finallight += seg->hwLightOffset;
|
||||
else
|
||||
extralight += seg->lightOffset * 8;
|
||||
finallight += seg->lightOffset * 8;
|
||||
|
||||
if (extralight != 0)
|
||||
{
|
||||
finallight += extralight;
|
||||
finallight = CLAMP(finallight, 0 , 255);
|
||||
}
|
||||
finallight = CLAMP(finallight, 0 , 255);
|
||||
}
|
||||
|
||||
return (FUINT)finallight;
|
||||
}
|
||||
|
||||
static FUINT HWR_CalcSlopeLight(FUINT lightnum, pslope_t *slope)
|
||||
static FUINT HWR_CalcSlopeLight(FUINT lightnum, pslope_t *slope, const sector_t *sector, const boolean fof)
|
||||
{
|
||||
INT16 finallight = lightnum;
|
||||
|
||||
if (slope != NULL && cv_glfakecontrast.value != 0 && cv_glslopecontrast.value != 0)
|
||||
if (slope != NULL && sector != NULL && P_ApplyLightOffsetFine(lightnum, sector) && cv_glfakecontrast.value != 0 && cv_glslopecontrast.value != 0)
|
||||
{
|
||||
fixed_t extralight = 0;
|
||||
|
||||
if (cv_glfakecontrast.value == 2) // Smooth setting
|
||||
extralight += slope->hwLightOffset;
|
||||
finallight += (fof ? -slope->hwLightOffset : slope->hwLightOffset);
|
||||
else
|
||||
extralight += slope->lightOffset * 8;
|
||||
finallight += (fof ? -slope->lightOffset * 8 : slope->lightOffset * 8);
|
||||
|
||||
if (extralight != 0)
|
||||
{
|
||||
finallight += extralight;
|
||||
finallight = CLAMP(finallight, 0 , 255);
|
||||
}
|
||||
finallight = CLAMP(finallight, 0 , 255);
|
||||
}
|
||||
|
||||
return (FUINT)finallight;
|
||||
@@ -650,10 +681,12 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
|
||||
SETUP3DVERT(v3d, pv->x, pv->y);
|
||||
|
||||
if (slope)
|
||||
lightlevel = HWR_CalcSlopeLight(lightlevel, slope);
|
||||
lightlevel = HWR_CalcSlopeLight(lightlevel, slope, gl_frontsector, (FOFsector != NULL));
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, planecolormap);
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, planecolormap, P_SectorUsesDirectionalLighting(gl_frontsector));
|
||||
|
||||
if (PolyFlags & (PF_Translucent|PF_Fog))
|
||||
{
|
||||
Surf.PolyColor.s.alpha = (UINT8)alpha;
|
||||
@@ -864,7 +897,7 @@ static void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIEL
|
||||
{
|
||||
INT32 shader = SHADER_NONE;
|
||||
|
||||
HWR_Lighting(pSurf, lightlevel, wallcolormap);
|
||||
HWR_Lighting(pSurf, lightlevel, wallcolormap, P_SectorUsesDirectionalLighting(gl_frontsector));
|
||||
|
||||
if (HWR_UseShader())
|
||||
{
|
||||
@@ -2624,7 +2657,7 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
|
||||
v3d->z = FIXED_TO_FLOAT(polysector->vertices[i]->y);
|
||||
}
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, planecolormap);
|
||||
HWR_Lighting(&Surf, lightlevel, planecolormap, P_SectorUsesDirectionalLighting((FOFsector != NULL) ? FOFsector : gl_frontsector));
|
||||
|
||||
if (blendmode & PF_Translucent)
|
||||
{
|
||||
@@ -3487,7 +3520,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
GLPatch_t *gpatch;
|
||||
FSurfaceInfo Surf;
|
||||
extracolormap_t *colormap;
|
||||
FUINT lightlevel;
|
||||
INT32 lightlevel;
|
||||
FBITFIELD blend = 0;
|
||||
UINT8 alpha;
|
||||
|
||||
@@ -3629,6 +3662,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
break;
|
||||
}
|
||||
|
||||
HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false);
|
||||
|
||||
for (i = 0; i < sector->numlights; i++)
|
||||
{
|
||||
if (endtop < endrealbot && top < realbot)
|
||||
@@ -3639,6 +3674,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
{
|
||||
if (!(spr->mobj->frame & FF_FULLBRIGHT))
|
||||
lightlevel = min(*list[i].lightlevel, 255);
|
||||
HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false);
|
||||
colormap = list[i].extra_colormap;
|
||||
}
|
||||
|
||||
@@ -3701,7 +3737,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
wallVerts[1].z = baseWallVerts[2].z + (baseWallVerts[2].z - baseWallVerts[1].z) * heightmult;
|
||||
}
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap);
|
||||
HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !(spr->mobj->frame & FF_FULLBRIGHT));
|
||||
|
||||
Surf.PolyColor.s.alpha = alpha;
|
||||
|
||||
@@ -3728,7 +3764,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
wallVerts[0].y = bot;
|
||||
wallVerts[1].y = endbot;
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap);
|
||||
HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector));
|
||||
|
||||
Surf.PolyColor.s.alpha = alpha;
|
||||
|
||||
@@ -3834,13 +3870,15 @@ static void HWR_DrawSprite(gl_vissprite_t *spr)
|
||||
|
||||
// colormap test
|
||||
sector_t *sector = spr->mobj->subsector->sector;
|
||||
UINT8 lightlevel = 255;
|
||||
INT32 lightlevel = 255;
|
||||
extracolormap_t *colormap = sector->extra_colormap;
|
||||
|
||||
if (!(spr->mobj->frame & FF_FULLBRIGHT))
|
||||
lightlevel = min(sector->lightlevel, 255);
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap);
|
||||
HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false);
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !(spr->mobj->frame & FF_FULLBRIGHT));
|
||||
|
||||
if (!cv_translucency.value) // translucency disabled
|
||||
{
|
||||
@@ -3947,7 +3985,7 @@ static inline void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr)
|
||||
colormap = sector->extra_colormap;
|
||||
}
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap);
|
||||
HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector));
|
||||
|
||||
if (spr->mobj->frame & FF_TRANSMASK)
|
||||
blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf);
|
||||
@@ -5439,8 +5477,18 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
|
||||
HWD.pfnClearBuffer(true, false, false, &ClearColor);
|
||||
}
|
||||
|
||||
if (HWR_UseShader() && cv_ripplewater.value)
|
||||
HWD.pfnSetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime.
|
||||
if (HWR_UseShader())
|
||||
{
|
||||
if (cv_ripplewater.value)
|
||||
GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime.
|
||||
const angle_t light_angle = maplighting.angle - viewangle + ANGLE_90; // I fucking hate OGL's coordinate system
|
||||
GL_SetShaderInfo(HWD_SHADERINFO_LIGHT_X, FINECOSINE(light_angle >> ANGLETOFINESHIFT));
|
||||
GL_SetShaderInfo(HWD_SHADERINFO_LIGHT_Y, 0);
|
||||
GL_SetShaderInfo(HWD_SHADERINFO_LIGHT_Z, -FINESINE(light_angle >> ANGLETOFINESHIFT));
|
||||
|
||||
GL_SetShaderInfo(HWD_SHADERINFO_LIGHT_CONTRAST, maplighting.contrast);
|
||||
GL_SetShaderInfo(HWD_SHADERINFO_LIGHT_BACKLIGHT, maplighting.backlight);
|
||||
}
|
||||
|
||||
if (viewnumber > 3)
|
||||
return;
|
||||
@@ -5619,7 +5667,7 @@ static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD
|
||||
INT32 shader = SHADER_NONE;
|
||||
|
||||
// Lighting is done here instead so that fog isn't drawn incorrectly on transparent walls after sorting
|
||||
HWR_Lighting(pSurf, lightlevel, wallcolormap);
|
||||
HWR_Lighting(pSurf, lightlevel, wallcolormap, P_SectorUsesDirectionalLighting(gl_frontsector));
|
||||
|
||||
pSurf->PolyColor.s.alpha = alpha; // put the alpha back after lighting
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ boolean HWR_PalRenderFlashpal(void);
|
||||
// into files like hw_bsp.c, hw_sprites.c...
|
||||
|
||||
// hw_main.c: Lighting and fog
|
||||
void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap);
|
||||
void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap, const boolean directional);
|
||||
|
||||
FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "../r_bsp.h"
|
||||
#include "../r_fps.h"
|
||||
#include "../r_main.h"
|
||||
#include "../p_setup.h"
|
||||
#include "../m_misc.h"
|
||||
#include "../w_wad.h"
|
||||
#include "../z_zone.h"
|
||||
@@ -1118,7 +1119,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
|
||||
{
|
||||
sector_t *sector = spr->mobj->subsector->sector;
|
||||
extracolormap_t *colormap = sector->extra_colormap;
|
||||
UINT8 lightlevel = 255;
|
||||
INT32 lightlevel = 255;
|
||||
|
||||
if (sector->numlights)
|
||||
{
|
||||
@@ -1141,7 +1142,9 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
|
||||
colormap = sector->extra_colormap;
|
||||
}
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap);
|
||||
HWR_ObjectLightLevelPost(spr, sector, &lightlevel, true);
|
||||
|
||||
HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !(spr->mobj->frame & FF_FULLBRIGHT));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ static struct {
|
||||
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER},
|
||||
|
||||
// Model shader
|
||||
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER},
|
||||
{GLSL_MODEL_LIGHTING_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER},
|
||||
|
||||
// Water shader
|
||||
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_WATER_FRAGMENT_SHADER},
|
||||
|
||||
@@ -31,6 +31,31 @@
|
||||
"gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \
|
||||
"}\0"
|
||||
|
||||
// reinterpretation of sprite lighting for models
|
||||
// it's a combination of how it works for normal sprites & papersprites
|
||||
#define GLSL_MODEL_LIGHTING_VERTEX_SHADER \
|
||||
"uniform float lighting;\n" \
|
||||
"uniform vec3 light_dir;\n" \
|
||||
"uniform float light_contrast;\n" \
|
||||
"uniform float light_backlight;\n" \
|
||||
"void main()\n" \
|
||||
"{\n" \
|
||||
"gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \
|
||||
"float light = lighting;\n" \
|
||||
"if (length(light_dir) > 0.000001) {\n" \
|
||||
"mat4 m4 = gl_ProjectionMatrix * gl_ModelViewMatrix;\n" \
|
||||
"mat3 m3 = mat3( m4[0].xyz, m4[1].xyz, m4[2].xyz );\n" \
|
||||
"float extralight = -dot(normalize(gl_Normal * m3), normalize(light_dir));\n" \
|
||||
"extralight *= light_contrast - light_backlight;\n" \
|
||||
"extralight *= lighting / 255.0;\n" \
|
||||
"light += extralight * 2.5;\n" \
|
||||
"}\n" \
|
||||
"light = clamp(light / 255.0, 0.0, 1.0);\n" \
|
||||
"gl_FrontColor = vec4(light, light, light, 1.0);\n" \
|
||||
"gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \
|
||||
"gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \
|
||||
"}\0"
|
||||
|
||||
// ==================
|
||||
// Fragment shaders
|
||||
// ==================
|
||||
@@ -99,6 +124,7 @@
|
||||
GLSL_DOOM_COLORMAP_NODITHER \
|
||||
"#endif\n" \
|
||||
"}\n"
|
||||
|
||||
// lighting cap adjustment:
|
||||
// first num (155.0), increase to make it start to go dark sooner
|
||||
// second num (0.26), increase to make it go dark faster
|
||||
|
||||
@@ -667,6 +667,9 @@ typedef enum
|
||||
gluniform_lighting,
|
||||
gluniform_fade_start,
|
||||
gluniform_fade_end,
|
||||
gluniform_light_dir,
|
||||
gluniform_light_contrast,
|
||||
gluniform_light_backlight,
|
||||
|
||||
// palette rendering
|
||||
gluniform_palette_tex, // 1d texture containing a palette
|
||||
@@ -704,10 +707,15 @@ static gl_shaderstate_t gl_shaderstate;
|
||||
|
||||
// Shader info
|
||||
static float shader_leveltime = 0;
|
||||
static float shader_light_x = 0.0f;
|
||||
static float shader_light_y = 0.0f;
|
||||
static float shader_light_z = 0.0f;
|
||||
static INT32 shader_light_contrast = 0;
|
||||
static INT32 shader_light_backlight = 0;
|
||||
|
||||
// Lactozilla: Shader functions
|
||||
static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i);
|
||||
static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade);
|
||||
static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i);
|
||||
static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade);
|
||||
|
||||
static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
|
||||
@@ -854,23 +862,38 @@ EXPORT boolean HWRAPI(CompileShader) (int slot)
|
||||
// Those are given to the uniforms.
|
||||
//
|
||||
|
||||
EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value)
|
||||
void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value)
|
||||
{
|
||||
switch (info)
|
||||
{
|
||||
case HWD_SHADERINFO_LEVELTIME:
|
||||
shader_leveltime = (((float)(value-1)) + FIXED_TO_FLOAT(rendertimefrac)) / TICRATE;
|
||||
break;
|
||||
case HWD_SHADERINFO_LIGHT_X:
|
||||
shader_light_x = FixedToFloat(value);
|
||||
break;
|
||||
case HWD_SHADERINFO_LIGHT_Y:
|
||||
shader_light_y = FixedToFloat(value);
|
||||
break;
|
||||
case HWD_SHADERINFO_LIGHT_Z:
|
||||
shader_light_z = FixedToFloat(value);
|
||||
break;
|
||||
case HWD_SHADERINFO_LIGHT_CONTRAST:
|
||||
shader_light_contrast = value;
|
||||
break;
|
||||
case HWD_SHADERINFO_LIGHT_BACKLIGHT:
|
||||
shader_light_backlight = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPORT void HWRAPI(SetShader) (int slot)
|
||||
void GL_SetShader(int slot)
|
||||
{
|
||||
if (slot == SHADER_NONE)
|
||||
{
|
||||
UnSetShader();
|
||||
GL_UnSetShader();
|
||||
return;
|
||||
}
|
||||
if (gl_allowshaders)
|
||||
@@ -1851,11 +1874,32 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
|
||||
UNIFORM_4(shader->uniforms[gluniform_tint_color], tint->red, tint->green, tint->blue, tint->alpha, pglUniform4f);
|
||||
UNIFORM_4(shader->uniforms[gluniform_fade_color], fade->red, fade->green, fade->blue, fade->alpha, pglUniform4f);
|
||||
|
||||
boolean directional = false;
|
||||
if (Surface != NULL)
|
||||
{
|
||||
UNIFORM_1(shader->uniforms[gluniform_lighting], (GLfloat)Surface->LightInfo.light_level, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_fade_start], (GLfloat)Surface->LightInfo.fade_start, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_fade_end], (GLfloat)Surface->LightInfo.fade_end, pglUniform1f);
|
||||
directional = Surface->LightInfo.directional;
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (directional)
|
||||
{
|
||||
UNIFORM_3(shader->uniforms[gluniform_light_dir], shader_light_x, shader_light_y, shader_light_z, pglUniform3f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_light_contrast], shader_light_contrast, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_light_backlight], shader_light_backlight, pglUniform1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
UNIFORM_3(shader->uniforms[gluniform_light_dir], 0, 0, 0, pglUniform3f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_light_contrast], 0, pglUniform1f);
|
||||
UNIFORM_1(shader->uniforms[gluniform_light_backlight], 0, pglUniform1f);
|
||||
}
|
||||
|
||||
UNIFORM_1(shader->uniforms[gluniform_leveltime], shader_leveltime, pglUniform1f);
|
||||
@@ -1980,6 +2024,9 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
|
||||
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_light_dir] = GETUNI("light_dir");
|
||||
shader->uniforms[gluniform_light_contrast] = GETUNI("light_contrast");
|
||||
shader->uniforms[gluniform_light_backlight] = GETUNI("light_backlight");
|
||||
|
||||
// palette rendering
|
||||
shader->uniforms[gluniform_palette_tex] = GETUNI("palette_tex");
|
||||
@@ -1988,6 +2035,9 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
|
||||
|
||||
shader->uniforms[gluniform_scr_resolution] = GETUNI("scr_resolution");
|
||||
|
||||
// supersampling crap
|
||||
shader->uniforms[gluniform_inv_supersamplefactor] = GETUNI("inv_supersamplefactor");
|
||||
|
||||
// misc.
|
||||
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
|
||||
#undef GETUNI
|
||||
|
||||
@@ -445,6 +445,7 @@ typedef struct precipmobj_s
|
||||
fixed_t spritexoffset, spriteyoffset;
|
||||
fixed_t old_spritexscale, old_spriteyscale;
|
||||
fixed_t old_spritexoffset, old_spriteyoffset;
|
||||
INT16 lightlevel; // Add to sector lightlevel, -255 - 255
|
||||
|
||||
fixed_t realxscale, realyscale; // funn-E streeetch
|
||||
|
||||
|
||||
+64
-3
@@ -327,6 +327,14 @@ static void P_ClearSingleMapHeaderInfo(INT16 i)
|
||||
mapheaderinfo[num]->numCustomOptions = 0;
|
||||
}
|
||||
|
||||
static void P_ClearDirectionalLightMapHeaderInfo(INT16 i) // lol dont always reset this on every map load
|
||||
{
|
||||
mapheaderinfo[i]->light_contrast = M_RandomRange(0, 58);
|
||||
mapheaderinfo[i]->sprite_backlight = 0;
|
||||
mapheaderinfo[i]->use_light_angle = true;
|
||||
mapheaderinfo[i]->light_angle = M_RandomRange(-382, 382);
|
||||
}
|
||||
|
||||
/** Allocates a new map-header structure.
|
||||
*
|
||||
* \param i Index of header to allocate.
|
||||
@@ -337,6 +345,7 @@ void P_AllocMapHeader(INT16 i)
|
||||
{
|
||||
mapheaderinfo[i] = Z_Malloc(sizeof(mapheader_t), PU_STATIC, NULL);
|
||||
mapheaderinfo[i]->grades = NULL;
|
||||
P_ClearDirectionalLightMapHeaderInfo(i);
|
||||
}
|
||||
P_ClearSingleMapHeaderInfo(i + 1);
|
||||
}
|
||||
@@ -397,21 +406,73 @@ static inline float P_SegLengthFloat(seg_t *seg)
|
||||
*/
|
||||
void P_UpdateSegLightOffset(seg_t *li)
|
||||
{
|
||||
const UINT8 contrast = 8;
|
||||
const UINT8 contrast = maplighting.contrast;
|
||||
const fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT;
|
||||
fixed_t light = FRACUNIT;
|
||||
fixed_t extralight = 0;
|
||||
|
||||
light = FixedDiv(R_PointToAngle2(0, 0, abs(li->v1->x - li->v2->x), abs(li->v1->y - li->v2->y)), ANGLE_90);
|
||||
if (maplighting.directional == true)
|
||||
{
|
||||
angle_t liAngle = R_PointToAngle2(0, 0, (li->v1->x - li->v2->x), (li->v1->y - li->v2->y)) - ANGLE_90;
|
||||
|
||||
light = FixedMul(FINECOSINE(liAngle >> ANGLETOFINESHIFT), FINECOSINE(maplighting.angle >> ANGLETOFINESHIFT))
|
||||
+ FixedMul(FINESINE(liAngle >> ANGLETOFINESHIFT), FINESINE(maplighting.angle >> ANGLETOFINESHIFT));
|
||||
light = (light + FRACUNIT) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
light = FixedDiv(R_PointToAngle2(0, 0, abs(li->v1->x - li->v2->x), abs(li->v1->y - li->v2->y)), ANGLE_90);
|
||||
}
|
||||
|
||||
extralight = -contrastFixed + FixedMul(light, contrastFixed * 2);
|
||||
|
||||
// Between -2 and 2 for software, -8 and 8 for hardware
|
||||
li->lightOffset = FixedFloor((extralight / contrast) + (FRACUNIT / 2)) / FRACUNIT;
|
||||
li->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;
|
||||
#ifdef HWRENDER
|
||||
li->hwLightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT;
|
||||
#endif
|
||||
}
|
||||
|
||||
boolean P_SectorUsesDirectionalLighting(const sector_t *sector)
|
||||
{
|
||||
if (sector != NULL)
|
||||
{
|
||||
// automatically turned on
|
||||
if (sector->ceilingpic == skyflatnum || sector->floorpic == skyflatnum)
|
||||
{
|
||||
// sky is visible
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// default is off, for indoors
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean P_ApplyLightOffset(UINT8 baselightnum, const sector_t *sector)
|
||||
{
|
||||
if (!P_SectorUsesDirectionalLighting(sector))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't apply light offsets at full bright or full dark.
|
||||
// Is in steps of light num .
|
||||
return (baselightnum < LIGHTLEVELS-1 && baselightnum > 0);
|
||||
}
|
||||
|
||||
boolean P_ApplyLightOffsetFine(UINT8 baselightlevel, const sector_t *sector)
|
||||
{
|
||||
if (!P_SectorUsesDirectionalLighting(sector))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't apply light offsets at full bright or full dark.
|
||||
// Uses exact light levels for more smoothness.
|
||||
return (baselightlevel < 255 && baselightlevel > 0);
|
||||
}
|
||||
|
||||
// Loads the SEGS resource from a level.
|
||||
static void P_LoadRawSegs(UINT8 *data)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,9 @@ fixed_t P_SegLength(seg_t *seg);
|
||||
#endif
|
||||
|
||||
void P_UpdateSegLightOffset(seg_t *li);
|
||||
boolean P_ApplyLightOffset(UINT8 baselightnum, const sector_t *sector);
|
||||
boolean P_ApplyLightOffsetFine(UINT8 baselightlevel, const sector_t *sector);
|
||||
boolean P_SectorUsesDirectionalLighting(const sector_t *sector);
|
||||
size_t P_PrecacheLevelFlats(void);
|
||||
void P_AllocMapHeader(INT16 i);
|
||||
|
||||
|
||||
+39
-7
@@ -30,14 +30,14 @@ static UINT16 slopecount = 0;
|
||||
// Calculate light
|
||||
static void P_UpdateSlopeLightOffset(pslope_t *slope)
|
||||
{
|
||||
const boolean ceiling = (slope->normal.z < 0);
|
||||
const UINT8 contrast = 8;
|
||||
const UINT8 contrast = maplighting.contrast;
|
||||
|
||||
fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT;
|
||||
fixed_t zMul = FRACUNIT;
|
||||
angle_t slopeDir = ANGLE_MAX;
|
||||
fixed_t light = FRACUNIT;
|
||||
fixed_t extralight = 0;
|
||||
|
||||
|
||||
if (slope->normal.z == 0)
|
||||
{
|
||||
slope->lightOffset = 0;
|
||||
@@ -47,15 +47,47 @@ static void P_UpdateSlopeLightOffset(pslope_t *slope)
|
||||
return;
|
||||
}
|
||||
|
||||
slopeDir = R_PointToAngle2(0, 0, abs(slope->normal.y), abs(slope->normal.x));
|
||||
if (ceiling == true)
|
||||
if (maplighting.directional == true)
|
||||
{
|
||||
slopeDir ^= ANGLE_180;
|
||||
fixed_t nX = -slope->normal.x;
|
||||
fixed_t nY = -slope->normal.y;
|
||||
fixed_t nLen = FixedHypot(nX, nY);
|
||||
|
||||
if (nLen == 0)
|
||||
{
|
||||
slope->lightOffset = 0;
|
||||
#ifdef HWRENDER
|
||||
slope->hwLightOffset = 0;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
nX = FixedDiv(nX, nLen);
|
||||
nY = FixedDiv(nY, nLen);
|
||||
|
||||
/*
|
||||
* if (slope is ceiling)
|
||||
* {
|
||||
* // There is no good way to calculate this condition here.
|
||||
* // We reverse it in R_FindPlane now.
|
||||
* nX = -nX;
|
||||
* nY = -nY;
|
||||
}
|
||||
*/
|
||||
|
||||
light = FixedMul(nX, FINECOSINE(maplighting.angle >> ANGLETOFINESHIFT))
|
||||
+ FixedMul(nY, FINESINE(maplighting.angle >> ANGLETOFINESHIFT));
|
||||
light = (light + FRACUNIT) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
light = FixedDiv(R_PointToAngle2(0, 0, abs(slope->d.x), abs(slope->d.y)), ANGLE_90);
|
||||
}
|
||||
|
||||
zMul = min(FRACUNIT, abs(slope->zdelta)*3/2); // *3/2, to make 60 degree slopes match walls.
|
||||
contrastFixed = FixedMul(contrastFixed, zMul);
|
||||
extralight = -contrastFixed + FixedMul(FixedDiv(AngleFixed(slopeDir), ANGLE_90), (contrastFixed * 2));
|
||||
|
||||
extralight = -contrastFixed + FixedMul(light, contrastFixed * 2);
|
||||
|
||||
// Between -2 and 2 for software, -8 and 8 for hardware
|
||||
slope->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;
|
||||
|
||||
@@ -5187,6 +5187,12 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate)
|
||||
// Set the default gravity. Custom gravity overrides this setting.
|
||||
gravity = (FRACUNIT*8)/10;
|
||||
|
||||
// Set map lighting settings.
|
||||
maplighting.contrast = mapheaderinfo[gamemap-1]->light_contrast;
|
||||
maplighting.backlight = mapheaderinfo[gamemap-1]->sprite_backlight;
|
||||
maplighting.directional = mapheaderinfo[gamemap-1]->use_light_angle;
|
||||
maplighting.angle = mapheaderinfo[gamemap-1]->light_angle;
|
||||
|
||||
// Defaults in case levels don't have them set.
|
||||
sstimer = 90*TICRATE + 6;
|
||||
totalrings = 1;
|
||||
|
||||
+6
-7
@@ -947,7 +947,7 @@ static void R_Subsector(size_t num)
|
||||
frontsector->floor_xoffs, frontsector->floor_yoffs, frontsector->floorpic_angle, floorcolormap, NULL
|
||||
, NULL
|
||||
, frontsector->f_slope
|
||||
, R_NoEncore(frontsector, false));
|
||||
, R_NoEncore(frontsector, false), false, frontsector);
|
||||
}
|
||||
else
|
||||
floorplane = NULL;
|
||||
@@ -963,7 +963,7 @@ static void R_Subsector(size_t num)
|
||||
ceilingcolormap, NULL
|
||||
, NULL
|
||||
, frontsector->c_slope
|
||||
, R_NoEncore(frontsector, true));
|
||||
, R_NoEncore(frontsector, true), true, frontsector);
|
||||
}
|
||||
else
|
||||
ceilingplane = NULL;
|
||||
@@ -1013,7 +1013,7 @@ static void R_Subsector(size_t num)
|
||||
*rover->bottomyoffs, *rover->bottomangle, frontsector->lightlist[light].extra_colormap, rover
|
||||
, NULL
|
||||
, *rover->b_slope
|
||||
, R_NoEncore(rover->master->frontsector, true));
|
||||
, R_NoEncore(rover->master->frontsector, true), true, frontsector);
|
||||
|
||||
ffloor[numffloors].slope = *rover->b_slope;
|
||||
|
||||
@@ -1049,7 +1049,7 @@ static void R_Subsector(size_t num)
|
||||
frontsector->lightlist[light].extra_colormap, rover
|
||||
, NULL
|
||||
, *rover->t_slope
|
||||
, R_NoEncore(rover->master->frontsector, false));
|
||||
, R_NoEncore(rover->master->frontsector, false), false, frontsector);
|
||||
|
||||
ffloor[numffloors].slope = *rover->t_slope;
|
||||
|
||||
@@ -1094,7 +1094,7 @@ static void R_Subsector(size_t num)
|
||||
polysec->floorpic_angle-po->angle,
|
||||
(light == -1 ? frontsector->extra_colormap : frontsector->lightlist[light].extra_colormap), NULL, po
|
||||
,NULL // will ffloors be slopable eventually?
|
||||
, R_NoEncore(polysec, false));
|
||||
, R_NoEncore(polysec, false), false, frontsector);
|
||||
|
||||
ffloor[numffloors].height = polysec->floorheight;
|
||||
ffloor[numffloors].polyobj = po;
|
||||
@@ -1118,7 +1118,7 @@ static void R_Subsector(size_t num)
|
||||
(light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->ceiling_xoffs, polysec->ceiling_yoffs, polysec->ceilingpic_angle-po->angle,
|
||||
(light == -1 ? frontsector->extra_colormap : frontsector->lightlist[light].extra_colormap), NULL, po
|
||||
,NULL // will ffloors be slopable eventually?
|
||||
, R_NoEncore(polysec, true));
|
||||
, R_NoEncore(polysec, true), false, frontsector);
|
||||
|
||||
ffloor[numffloors].polyobj = po;
|
||||
ffloor[numffloors].height = polysec->ceilingheight;
|
||||
@@ -1336,7 +1336,6 @@ void R_RenderBSPNode(INT32 bspnum)
|
||||
|
||||
// Decide which side the view point is on.
|
||||
side = R_PointOnSideFast(viewx, viewy, bsp);
|
||||
|
||||
// Recursively divide front space.
|
||||
R_RenderBSPNode(bsp->children[side]);
|
||||
|
||||
|
||||
+11
-3
@@ -350,7 +350,8 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
|
||||
ffloor_t *pfloor
|
||||
, polyobj_t *polyobj
|
||||
, pslope_t *slope
|
||||
, boolean noencore)
|
||||
, boolean noencore
|
||||
, boolean reverseLight, const sector_t *lighting_sector)
|
||||
{
|
||||
visplane_t *check;
|
||||
unsigned hash;
|
||||
@@ -387,9 +388,16 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
|
||||
}
|
||||
}
|
||||
|
||||
if (slope != NULL)
|
||||
if (slope != NULL && P_ApplyLightOffset(lightlevel >> LIGHTSEGSHIFT, lighting_sector))
|
||||
{
|
||||
lightlevel += slope->lightOffset * 8;
|
||||
if (reverseLight)
|
||||
{
|
||||
lightlevel -= slope->lightOffset * 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
lightlevel += slope->lightOffset * 8;
|
||||
}
|
||||
}
|
||||
|
||||
// This appears to fix the Nimbus Ruins sky bug.
|
||||
|
||||
+2
-1
@@ -87,7 +87,8 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, fixed_t
|
||||
extracolormap_t *planecolormap, ffloor_t *ffloor
|
||||
, polyobj_t *polyobj
|
||||
, pslope_t *slope
|
||||
, boolean noencore);
|
||||
, boolean noencore
|
||||
, boolean reverseLight, const sector_t *lighting_sector);
|
||||
visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop);
|
||||
void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop);
|
||||
void R_PlaneBounds(visplane_t *plane);
|
||||
|
||||
+8
-6
@@ -23,6 +23,7 @@
|
||||
#include "d_netcmd.h"
|
||||
#include "m_misc.h"
|
||||
#include "p_local.h" // Camera...
|
||||
#include "p_setup.h"
|
||||
#include "p_slopes.h"
|
||||
#include "console.h" // con_clipviewtop
|
||||
|
||||
@@ -408,7 +409,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
|
||||
|
||||
if (rlight->extra_colormap && rlight->extra_colormap->fog)
|
||||
;
|
||||
else
|
||||
else if (P_ApplyLightOffset(lightnum, frontsector))
|
||||
lightnum += curline->lightOffset;
|
||||
|
||||
rlight->lightnum = lightnum;
|
||||
@@ -429,7 +430,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
|
||||
if (colfunc == R_DrawFogColumn_8
|
||||
|| (frontsector->extra_colormap && frontsector->extra_colormap->fog))
|
||||
;
|
||||
else
|
||||
else if (P_ApplyLightOffset(lightnum, frontsector))
|
||||
lightnum += curline->lightOffset;
|
||||
|
||||
if (lightnum < 0)
|
||||
@@ -834,7 +835,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
|
||||
|
||||
if (pfloor->flags & FF_FOG || rlight->flags & FF_FOG || (rlight->extra_colormap && rlight->extra_colormap->fog))
|
||||
;
|
||||
else
|
||||
else if (P_ApplyLightOffset(rlight->lightnum, frontsector))
|
||||
rlight->lightnum += curline->lightOffset;
|
||||
|
||||
p++;
|
||||
@@ -857,7 +858,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
|
||||
|
||||
if (pfloor->flags & FF_FOG || (frontsector->extra_colormap && frontsector->extra_colormap->fog))
|
||||
;
|
||||
else
|
||||
else if (P_ApplyLightOffset(lightnum, frontsector))
|
||||
lightnum += curline->lightOffset;
|
||||
|
||||
if (lightnum < 0)
|
||||
@@ -1412,7 +1413,7 @@ static void R_RenderSegLoop (void)
|
||||
|
||||
if (dc_lightlist[i].extra_colormap)
|
||||
;
|
||||
else
|
||||
else if (P_ApplyLightOffset(lightnum, curline->frontsector))
|
||||
lightnum += curline->lightOffset;
|
||||
|
||||
if (lightnum < 0)
|
||||
@@ -2417,7 +2418,8 @@ void R_StoreWallRange(INT32 start, INT32 stop)
|
||||
// OPTIMIZE: get rid of LIGHTSEGSHIFT globally
|
||||
lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT);
|
||||
|
||||
lightnum += curline->lightOffset;
|
||||
if (P_ApplyLightOffset(lightnum, frontsector))
|
||||
lightnum += curline->lightOffset;
|
||||
|
||||
if (lightnum < 0)
|
||||
walllights = scalelight[0];
|
||||
|
||||
+90
-10
@@ -27,6 +27,7 @@
|
||||
#include "r_plane.h"
|
||||
#include "p_tick.h"
|
||||
#include "p_local.h"
|
||||
#include "p_setup.h"
|
||||
#include "p_slopes.h"
|
||||
#include "dehacked.h" // get_number (for thok)
|
||||
#include "d_netfil.h" // blargh. for nameonly().
|
||||
@@ -108,6 +109,13 @@ static drawseg_xrange_item_t *drawsegs_xrange;
|
||||
static size_t drawsegs_xrange_size = 0;
|
||||
static INT32 drawsegs_xrange_count = 0;
|
||||
|
||||
INT32 R_ThingLightLevel(mobj_t* thing)
|
||||
{
|
||||
INT32 lightlevel = thing->lightlevel;
|
||||
|
||||
return lightlevel;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
//
|
||||
// Sprite loading routines: support sprites in pwad, dehacked sprite renaming,
|
||||
@@ -1109,6 +1117,26 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
|
||||
#undef CHECKZ
|
||||
}
|
||||
|
||||
fixed_t R_GetSpriteDirectionalLighting(angle_t angle)
|
||||
{
|
||||
// Copied from P_UpdateSegLightOffset
|
||||
const UINT8 contrast = min(max(0, maplighting.contrast - maplighting.backlight), UINT8_MAX);
|
||||
const fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT;
|
||||
|
||||
fixed_t light = FRACUNIT;
|
||||
fixed_t extralight = 0;
|
||||
|
||||
light = FixedMul(FINECOSINE(angle >> ANGLETOFINESHIFT), FINECOSINE(maplighting.angle >> ANGLETOFINESHIFT))
|
||||
+ FixedMul(FINESINE(angle >> ANGLETOFINESHIFT), FINESINE(maplighting.angle >> ANGLETOFINESHIFT));
|
||||
light = (light + FRACUNIT) / 2;
|
||||
|
||||
light = FixedMul(light, FRACUNIT - FSIN(abs(AngleDeltaSigned(angle, maplighting.angle)) / 2));
|
||||
|
||||
extralight = -contrastFixed + FixedMul(light, contrastFixed * 2);
|
||||
|
||||
return extralight;
|
||||
}
|
||||
|
||||
//
|
||||
// R_ProjectSprite
|
||||
// Generates a vissprite for a thing
|
||||
@@ -1152,10 +1180,13 @@ static void R_ProjectSprite(mobj_t *thing)
|
||||
boolean papersprite = (thing->frame & FF_PAPERSPRITE);
|
||||
fixed_t paperoffset = 0, paperdistance = 0; angle_t centerangle = 0;
|
||||
|
||||
INT32 lightnum;
|
||||
|
||||
//SoM: 3/17/2000
|
||||
fixed_t gz, gzt;
|
||||
INT32 heightsec, phs;
|
||||
INT32 light = 0;
|
||||
lighttable_t **lights_array = spritelights;
|
||||
fixed_t this_scale;
|
||||
fixed_t spritexscale, spriteyscale;
|
||||
|
||||
@@ -1358,6 +1389,14 @@ static void R_ProjectSprite(mobj_t *thing)
|
||||
else
|
||||
pitchnroll += rollangle;
|
||||
|
||||
// this is kinda dumb lkmao, but try to mitigate shadows being weirdly offset on slopes
|
||||
if (thing->type == MT_SHADOW)
|
||||
{
|
||||
sprinfo->available = true; // < lmao
|
||||
sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].x = spr_offset>>FRACBITS;
|
||||
sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].y = -12; // noones gonna replace shadow sprite anyways, right?
|
||||
}
|
||||
|
||||
rollangle = R_GetRollAngle(pitchnroll);
|
||||
rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle);
|
||||
|
||||
@@ -1563,27 +1602,68 @@ static void R_ProjectSprite(mobj_t *thing)
|
||||
|
||||
if (thing->subsector->sector->numlights)
|
||||
{
|
||||
INT32 lightnum;
|
||||
light = thing->subsector->sector->numlights - 1;
|
||||
|
||||
for (lightnum = 1; lightnum < thing->subsector->sector->numlights; lightnum++) {
|
||||
fixed_t h = thing->subsector->sector->lightlist[lightnum].slope ? P_GetZAt(thing->subsector->sector->lightlist[lightnum].slope, interp.x, interp.y)
|
||||
: thing->subsector->sector->lightlist[lightnum].height;
|
||||
: thing->subsector->sector->lightlist[lightnum].height;
|
||||
if (h <= gzt)
|
||||
{
|
||||
light = lightnum - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lightnum = (*thing->subsector->sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT);
|
||||
|
||||
if (lightnum < 0)
|
||||
spritelights = scalelight[0];
|
||||
else if (lightnum >= LIGHTLEVELS)
|
||||
spritelights = scalelight[LIGHTLEVELS-1];
|
||||
else
|
||||
spritelights = scalelight[lightnum];
|
||||
lightnum = *thing->subsector->sector->lightlist[light].lightlevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
lightnum = thing->subsector->sector->lightlevel;
|
||||
}
|
||||
|
||||
lightnum = (lightnum + R_ThingLightLevel(thing)) >> LIGHTSEGSHIFT;
|
||||
|
||||
if (maplighting.directional == true && P_SectorUsesDirectionalLighting(thing->subsector->sector))
|
||||
{
|
||||
fixed_t extralight = R_GetSpriteDirectionalLighting(papersprite
|
||||
? interp.angle + (ang >= ANGLE_180 ? -ANGLE_90 : ANGLE_90)
|
||||
: R_PointToAngle(interp.x, interp.y));
|
||||
|
||||
// Krangle contrast in 3P/4P because scalelight
|
||||
// scales differently depending on the screen
|
||||
// width (which is halved in 3P/4P).
|
||||
if (splitscreen > 1)
|
||||
{
|
||||
extralight *= 2;
|
||||
}
|
||||
|
||||
// Less change in contrast in dark sectors
|
||||
extralight = FixedMul(extralight, min(max(0, lightnum), LIGHTLEVELS - 1) * FRACUNIT / (LIGHTLEVELS - 1));
|
||||
|
||||
if (papersprite)
|
||||
{
|
||||
// Papersprite contrast should match walls
|
||||
lightnum += FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed_t n = FixedDiv(FixedMul(xscale, LIGHTRESOLUTIONFIX), ((MAXLIGHTSCALE-1) << LIGHTSCALESHIFT));
|
||||
|
||||
// Less change in contrast at further distances, to counteract DOOM diminished light
|
||||
extralight = FixedMul(extralight, min(n, FRACUNIT));
|
||||
|
||||
// Contrast is stronger for normal sprites, stronger than wall lighting is at the same distance
|
||||
lightnum += FixedFloor((extralight / 4) + (FRACUNIT / 2)) / FRACUNIT;
|
||||
}
|
||||
}
|
||||
|
||||
if (lightnum < 0)
|
||||
lights_array = scalelight[0];
|
||||
else if (lightnum >= LIGHTLEVELS)
|
||||
lights_array = scalelight[LIGHTLEVELS-1];
|
||||
else
|
||||
lights_array = scalelight[lightnum];
|
||||
|
||||
|
||||
heightsec = thing->subsector->sector->heightsec;
|
||||
if (viewplayer && viewplayer->mo && viewplayer->mo->subsector)
|
||||
@@ -1702,7 +1782,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
||||
// Mitigate against negative xscale and arithmetic overflow
|
||||
lindex = CLAMP(lindex, 0, MAXLIGHTSCALE - 1);
|
||||
|
||||
vis->colormap = spritelights[lindex];
|
||||
vis->colormap = lights_array[lindex];
|
||||
}
|
||||
|
||||
vis->precip = false;
|
||||
|
||||
@@ -57,6 +57,9 @@ extern fixed_t windowtop;
|
||||
extern fixed_t windowbottom;
|
||||
extern INT32 lengthcol;
|
||||
|
||||
INT32 R_ThingLightLevel(mobj_t *thing);
|
||||
fixed_t R_GetSpriteDirectionalLighting(angle_t angle);
|
||||
|
||||
fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope);
|
||||
|
||||
void R_DrawMaskedColumn(column_t *column);
|
||||
|
||||
+6
-1
@@ -176,13 +176,18 @@ fixed_t *finecosine = &finesine[FINEANGLES/4];
|
||||
|
||||
#include "t_facon.c"
|
||||
|
||||
|
||||
FUNCMATH angle_t FixedAcos(fixed_t x)
|
||||
{
|
||||
if (-FRACUNIT > x || x >= FRACUNIT) return 0;
|
||||
return fineacon[((x<<(FINE_FRACBITS-FRACBITS)))+FRACUNIT];
|
||||
}
|
||||
|
||||
INT32 AngleDeltaSigned(angle_t a1, angle_t a2)
|
||||
{
|
||||
// Silly but easy way to do it through integer conversion.
|
||||
return (INT32)(a1) - (INT32)(a2);
|
||||
}
|
||||
|
||||
//
|
||||
// AngleBetweenVectors
|
||||
//
|
||||
|
||||
@@ -110,6 +110,8 @@ FUNCMATH angle_t FixedAngleC(fixed_t fa, fixed_t factor);
|
||||
/// The FixedAcos function
|
||||
FUNCMATH angle_t FixedAcos(fixed_t x);
|
||||
|
||||
FUNCMATH INT32 AngleDeltaSigned(angle_t a1, angle_t a2);
|
||||
|
||||
/// Fixed Point Vector functions
|
||||
angle_t FV2_AngleBetweenVectors(const vector2_t *Vector1, const vector2_t *Vector2);
|
||||
angle_t FV3_AngleBetweenVectors(const vector3_t *Vector1, const vector3_t *Vector2);
|
||||
|
||||
Reference in new issue
Block a user