Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • STJr/SRB2
  • Sryder/SRB2
  • wolfy852/SRB2
  • Alpha2244/SRB2
  • Inuyasha/SRB2
  • yoshibot/SRB2
  • TehRealSalt/SRB2
  • PrisimaTF/SRB2
  • Hatninja/SRB2
  • SteelT/SRB2
  • james/SRB2
  • ShaderWraith/SRB2
  • SinnamonLat/SRB2
  • mazmazz_/SRB2
  • filpAM/SRB2
  • chaoloveicemdboy/SRB2
  • Whooa21/SRB2
  • Machturne/SRB2
  • Golden/SRB2
  • Tatsuru/SRB2
  • Snu/SRB2
  • Zwip-Zwap_Zapony/SRB2
  • fickleheart/SRB2
  • alphaRexJames/SRB2
  • JJK/SRB2
  • diskpoppy/SRB2
  • Hannu_Hanhi/SRB2
  • ZipperQR/SRB2
  • kays/SRB2
  • spherallic/SRB2
  • Zippy_Zolton/SRB2
  • namiishere/SRB2
  • Ors/SRB2
  • SMS_Alfredo/SRB2
  • sonic_edge/SRB2
  • pastel/SRB2
  • ashi/SRB2
  • X.organic/SRB2
  • Fafabis/SRB2
  • Meziu/SRB2
  • v-rob/SRB2
  • tertu/SRB2
  • bitten2up/SRB2
  • flarn2006/SRB2
  • Krabs/SRB2
  • clairebun/SRB2
  • Lactozilla/SRB2
  • thehackstack/SRB2
  • Spice/SRB2
  • win8linux/SRB2
  • JohnFrostFox/SRB2
  • talktoneon726/SRB2
  • Wane/SRB2
  • Lamibe/SRB2
  • spectrumuk2/srb-2
  • nerdyminer18/srb-2
  • 256nil/SRB2
  • ARJr/SRB2
  • Alam/SRB2
  • Zenya/srb-2-marathon-demos
  • Acelite/srb-2-archivedmodifications
  • MIDIMan/SRB2
  • Lach/SRB2
  • Frostiikin/bounce-tweaks
  • Hanicef/SRB2Classic
  • Jaden/SRB2
  • Tyron/SRB2
  • Astronight/SRB2
  • Mari0shi06/SRB2
  • aiire/SRB2
  • Galactice/SRB2
  • srb2-ports/srb2-dreamcast
  • sdasdas/SRB2
  • chreas/srb-2-vr
  • StarManiaKG/the-story-of-sinically-rocketing-and-botching-the-2nd
  • LoganAir/SRB2
  • NepDisk/srb-2
  • alufolie91/SRB2
  • Felicia.iso/SRB2
  • twi/SRB2
  • BarrelsOFun/SRB2
  • Speed2411/SRB2
  • Leather_Realms/SRB2
  • Ayemar/SRB2
  • Acelite/SRB2
  • VladDoc/SRB2
  • kaldrum/model-features
  • strawberryfox417/SRB2
  • Lugent/SRB2
  • Jisk/SRB2
  • Rem/SRB2
  • Refrag/SRB2
  • Henry_3230/srb-3230
  • TehPuertoRicanSpartan2/tprs-srb2
  • Leminn/srb-2-marathon-stuff
  • chromaticpipe2/SRB2
  • MiguelGustavo15/SRB2
  • Maru/srb-2-tests
  • SilicDev/SRB2
  • UnmatchedBracket/SRB2
  • HybridDog/SRB2
  • xordspar0/SRB2
  • jsjhbewfhh/SRB2
  • Fancy2209/SRB2
  • Lorsoen/SRB2
  • shindoukin/SRB2
  • GamerOfDays/SRB2
  • Craftyawesome/SRB2
  • tenshi-tensai-tennoji/SRB2
  • Scarfdudebalder/SRB2
  • luigi-budd/srb-2-fix-interplag-lockon
  • mskluesner/SRB2
  • johnpetersa19/SRB2
  • Pheazant/SRB2
  • chromaticpipe2/srb2classic
  • romoney5/SRB2
  • PAS/SRB2Classic
  • BlueStaggo/SRB2
118 results
Show changes
Commits on Source (54)
Showing with 1125 additions and 53 deletions
File added
File added
......@@ -3,7 +3,7 @@
#
ifndef MINGW64
EXENAME?=srb2win.exe
EXENAME?=srb2rr-2214nightly.exe
else
EXENAME?=srb2win64.exe
endif
......
......@@ -98,3 +98,4 @@ lua_hudlib.c
lua_hudlib_drawlist.c
lua_inputlib.c
lua_colorlib.c
k_brightmap.c
......@@ -1352,6 +1352,12 @@ void readgametype(MYFILE *f, char *gtname)
CONS_Printf("Added gametype %s\n", Gametype_Names[newgtidx]);
}
// rr
static mapheader_lighting_t *usemaplighting(INT32 mapnum)
{
return &mapheaderinfo[mapnum]->lighting;
}
void readlevelheader(MYFILE *f, INT32 num)
{
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
......@@ -1712,6 +1718,31 @@ void readlevelheader(MYFILE *f, INT32 num)
else if (fastcmp(word, "SKYBOXSCALEZ"))
mapheaderinfo[num-1]->skybox_scalez = (INT16)i;
// rr
else if (fastcmp(word, "LIGHTCONTRAST") || fastcmp(word, "ENCORELIGHTCONTRAST"))
{
usemaplighting(num-1)->light_contrast = (UINT8)i;
}
else if (fastcmp(word, "SPRITEBACKLIGHT") || fastcmp(word, "ENCORESPRITEBACKLIGHT"))
{
usemaplighting(num-1)->sprite_backlight = (SINT8)i;
}
else if (fastcmp(word, "LIGHTANGLE") || fastcmp(word, "ENCORELIGHTANGLE"))
{
mapheader_lighting_t *lighting = usemaplighting(num-1);
if (fastcmp(word2, "EVEN"))
{
lighting->use_light_angle = false;
lighting->light_angle = 0;
}
else
{
lighting->use_light_angle = true;
lighting->light_angle = FixedAngle(FloatToFixed(atof(word2)));
}
}
else if (fastcmp(word, "BONUSTYPE"))
{
if (fastcmp(word2, "NONE")) i = -1;
......
......@@ -106,7 +106,7 @@
FILE *fopenfile(const char*, const char*);
//#define NOMD5
#define NOMD5
// If you don't disable ALL debug first, you get ALL debug enabled
#if !defined (NDEBUG)
......@@ -553,6 +553,7 @@ void *M_Memcpy(void* dest, const void* src, size_t n);
char *va(const char *format, ...) FUNCPRINTF;
char *M_GetToken(const char *inputString);
void M_UnGetToken(void);
UINT32 M_GetTokenPos(void); // rr
void M_TokenizerOpen(const char *inputString, size_t len);
void M_TokenizerClose(void);
const char *M_TokenizerRead(UINT32 i);
......
......@@ -291,6 +291,23 @@ typedef struct
char value[256]; // 255 usable characters. If this seriously isn't enough then wtf.
} customoption_t;
// rr
extern struct maplighting
{
UINT8 contrast;
SINT8 backlight;
boolean directional;
angle_t angle;
} maplighting;
typedef struct
{
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.
} mapheader_lighting_t;
/** Map header information.
*/
typedef struct
......@@ -361,6 +378,11 @@ typedef struct
SINT8 musforcereset; ///< Force resetmusic (-1 for default; 0 for force off; 1 for force on)
// rr
//fixed_t darkness; ///< Pohbee darkness multiplier
//fixed_t mobj_scale; ///< Defines the size all object calculations are relative to
mapheader_lighting_t lighting; ///< Wall and sprite lighting
// Lua stuff.
// (This is not ifdeffed so the map header structure can stay identical, just in case.)
UINT8 numCustomOptions; ///< Internal. For Lua custom value support.
......
......@@ -235,6 +235,9 @@ UINT32 countdown, countdown2; // for racing
fixed_t gravity;
// rr
struct maplighting maplighting;
INT16 autobalance; //for CTF team balance
INT16 teamscramble; //for CTF team scramble
INT16 scrambleplayers[MAXPLAYERS]; //for CTF team scramble
......
......@@ -17,6 +17,7 @@
// The texture for the next polygon given to HWR_ProcessPolygon.
// Set with HWR_SetCurrentTexture.
GLMipmap_t *current_texture = NULL;
GLMipmap_t *current_brightmap = NULL; // rr
boolean currently_batching = false;
......@@ -61,7 +62,7 @@ void HWR_StartBatching(void)
// This replaces the direct calls to pfnSetTexture in cases where batching is available.
// The texture selection is saved for the next HWR_ProcessPolygon call.
// Doing this was easier than getting a texture pointer to HWR_ProcessPolygon.
void HWR_SetCurrentTexture(GLMipmap_t *texture)
/*void HWR_SetCurrentTexture(GLMipmap_t *texture)
{
if (currently_batching)
{
......@@ -71,6 +72,34 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture)
{
HWD.pfnSetTexture(texture);
}
}*/
// rr
void HWR_SetCurrentTexture(GLMipmap_t *texture)
{
if (currently_batching)
{
if (texture != NULL)
{
if (texture->flags & TF_BRIGHTMAP)
{
current_brightmap = texture;
}
else
{
current_texture = texture;
current_brightmap = NULL;
}
}
else
{
current_texture = current_brightmap = NULL;
}
}
else
{
HWD.pfnSetTexture(texture);
}
}
// If batching is enabled, this function collects the polygon data and the chosen texture
......@@ -114,6 +143,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt
polygonArray[polygonArraySize].numVerts = iNumPts;
polygonArray[polygonArraySize].polyFlags = PolyFlags;
polygonArray[polygonArraySize].texture = current_texture;
polygonArray[polygonArraySize].brightmap = current_brightmap; // rr
polygonArray[polygonArraySize].shader = (shader_target != -1) ? HWR_GetShaderFromTarget(shader_target) : shader_target;
polygonArray[polygonArraySize].horizonSpecial = horizonSpecial;
// default to polygonArraySize so we don't lose order on horizon lines
......@@ -129,6 +159,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt
if (current_texture)
{
DIGEST(hash, current_texture->downloaded);
//DIGEST(hash, current_brightmap->downloaded); // rr
}
DIGEST(hash, PolyFlags);
DIGEST(hash, pSurf->PolyColor.rgba);
......@@ -140,6 +171,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt
DIGEST(hash, pSurf->LightInfo.light_level);
DIGEST(hash, pSurf->LightInfo.fade_start);
DIGEST(hash, pSurf->LightInfo.fade_end);
DIGEST(hash, pSurf->LightInfo.directional); // rr
}
#undef DIGEST
// remove the sign bit to ensure that skybox and horizon line comes first.
......@@ -178,6 +210,8 @@ void HWR_RenderBatches(void)
int nextShader = 0;
GLMipmap_t *currentTexture;
GLMipmap_t *nextTexture = NULL;
GLMipmap_t *currentBrightmap = NULL; // rr
GLMipmap_t *nextBrightmap = NULL; // rr
FBITFIELD currentPolyFlags = 0;
FBITFIELD nextPolyFlags = 0;
FSurfaceInfo currentSurfaceInfo;
......@@ -191,6 +225,7 @@ void HWR_RenderBatches(void)
nextSurfaceInfo.LightInfo.fade_end = 0;
nextSurfaceInfo.LightInfo.fade_start = 0;
nextSurfaceInfo.LightInfo.light_level = 0;
nextSurfaceInfo.LightInfo.directional = false; // rr
currently_batching = false;// no longer collecting batches
if (!polygonArraySize)
......@@ -226,6 +261,7 @@ void HWR_RenderBatches(void)
currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texture;
currentBrightmap = polygonArray[polygonIndexArray[0]].brightmap; // rr - 3rd in sort order now
currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags;
currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf;
// For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
......@@ -238,10 +274,21 @@ void HWR_RenderBatches(void)
HWD.pfnSetShader(currentShader);
}
if (currentPolyFlags & PF_NoTexture)
/*if (currentPolyFlags & PF_NoTexture)
currentTexture = NULL;
else
HWD.pfnSetTexture(currentTexture);
HWD.pfnSetTexture(currentTexture);*/
// rr
if (currentPolyFlags & PF_NoTexture)
{
currentTexture = currentBrightmap = NULL;
}
else
{
HWD.pfnSetTexture(currentTexture);
if (currentBrightmap)
HWD.pfnSetTexture(currentBrightmap);
}
while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons)
{
......@@ -314,15 +361,18 @@ void HWR_RenderBatches(void)
changeState = true;
nextShader = polygonArray[nextIndex].shader;
nextTexture = polygonArray[nextIndex].texture;
nextBrightmap = polygonArray[nextIndex].brightmap; // rr
nextPolyFlags = polygonArray[nextIndex].polyFlags;
nextSurfaceInfo = polygonArray[nextIndex].surf;
if (nextPolyFlags & PF_NoTexture)
nextTexture = 0;
//nextTexture = 0;
nextTexture = nextBrightmap = 0; // rr
if (currentShader != nextShader && cv_glshaders.value && gl_shadersavailable)
{
changeShader = true;
}
if (currentTexture != nextTexture)
//if (currentTexture != nextTexture)
if (currentTexture != nextTexture || currentBrightmap != nextBrightmap) // rr
{
changeTexture = true;
}
......@@ -337,7 +387,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) // rr
{
changeSurfaceInfo = true;
}
......@@ -384,6 +435,12 @@ void HWR_RenderBatches(void)
// texture should be already ready for use from calls to SetTexture during batch collection
HWD.pfnSetTexture(nextTexture);
currentTexture = nextTexture;
// rr
if (nextBrightmap)
HWD.pfnSetTexture(nextBrightmap);
currentBrightmap = nextBrightmap;
changeTexture = false;
ps_hw_numtextures.value.i++;
......
......@@ -23,6 +23,7 @@ typedef struct
FUINT numVerts;
FBITFIELD polyFlags;
GLMipmap_t *texture;
GLMipmap_t *brightmap; // rr
int shader;
// this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls
boolean horizonSpecial;
......
......@@ -788,6 +788,52 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean chromakeyed)
HWR_SetCurrentTexture(grMipmap);
Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED);
// rr
if (R_GetTextureBrightmap(tex))
{
GLMapTexture_t *grtexbright = &gl_textures[R_GetTextureBrightmap(tex)];
GLMipmap_t *grMipmapBright = &grtexbright->mipmap;
GLMipmap_t *originalMipmapBright = grMipmapBright;
if (!originalMipmapBright->downloaded)
{
originalMipmapBright->flags = TF_WRAPXY | TF_BRIGHTMAP;
originalMipmapBright->width = (UINT16)textures[tex]->width;
originalMipmapBright->height = (UINT16)textures[tex]->height;
originalMipmapBright->format = textureformat;
}
// If chroma-keyed, create or use a different mipmap for the variant
if (chromakeyed && !textures[tex]->transparency)
{
// Allocate it if it wasn't already
if (!originalMipmapBright->nextcolormap)
{
GLMipmap_t *newMipmapBright = calloc(1, sizeof (*grMipmapBright));
if (newMipmapBright == NULL)
I_Error("%s: Out of memory", "HWR_GetTexture");
newMipmapBright->flags = originalMipmapBright->flags | TF_CHROMAKEYED | TF_BRIGHTMAP;
newMipmapBright->width = originalMipmapBright->width;
newMipmapBright->height = originalMipmapBright->height;
newMipmapBright->format = originalMipmapBright->format;
originalMipmapBright->nextcolormap = newMipmapBright;
}
// Generate, upload and bind the variant texture instead of the original one
grMipmapBright = originalMipmapBright->nextcolormap;
}
if (!grMipmapBright->data)
HWR_GenerateTexture(R_GetTextureBrightmap(tex), grtexbright, grMipmapBright);
if (!grMipmapBright->downloaded)
HWD.pfnSetTexture(grMipmapBright);
HWR_SetCurrentTexture(grMipmapBright);
Z_ChangeTag(grMipmapBright->data, PU_HWRCACHE_UNLOCKED);
}
return grtex;
}
......@@ -897,6 +943,59 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean chromakeyed)
HWR_SetCurrentTexture(grMipmap);
Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED);
// rr
if ((texturenum = R_GetTextureBrightmap(texturenum)))
{
grtex = &gl_flats[texturenum];
grMipmap = &grtex->mipmap;
originalMipmap = grMipmap;
INT32 bmNum = R_GetTextureBrightmap(R_GetTextureNumForFlat(levelflat));
if (bmNum == 0) { bmNum = texturenum; }
if (!originalMipmap->downloaded)
MakeLevelFlatMipmap(originalMipmap, texturenum, TF_WRAPXY | TF_BRIGHTMAP);
if (!originalMipmap->data)
{
size_t size = originalMipmap->width * originalMipmap->height;
memcpy(Z_Malloc(size, PU_HWRCACHE, &originalMipmap->data), R_GetFlatForTexture(bmNum), size);
}
// If chroma-keyed, create or use a different mipmap for the variant
if (chromakeyed)
{
if (!originalMipmap->data)
{
HWR_SetCurrentTexture(NULL);
return;
}
// Allocate it if it wasn't already
if (!originalMipmap->nextcolormap)
{
GLMipmap_t *newMipmap = calloc(1, sizeof (*grMipmap));
if (newMipmap == NULL)
I_Error("%s: Out of memory", "HWR_GetLevelFlat");
MakeLevelFlatMipmap(newMipmap, texturenum, TF_WRAPXY | TF_CHROMAKEYED | TF_BRIGHTMAP);
originalMipmap->nextcolormap = newMipmap;
}
// Upload and bind the variant texture instead of the original one
grMipmap = originalMipmap->nextcolormap;
// Use the original texture's pixel data
// It can just be a pointer to it, since the r_opengl backend deals with the pixels
// that are supposed to be transparent.
grMipmap->data = originalMipmap->data;
}
if (!grMipmap->downloaded)
HWD.pfnSetTexture(grMipmap);
HWR_SetCurrentTexture(grMipmap);
Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED);
}
}
// --------------------+
......
......@@ -248,6 +248,9 @@ enum ETextureFlags
TF_WRAPXY = TF_WRAPY|TF_WRAPX, // very common so use alias is more easy
TF_CHROMAKEYED = 0x00000010, // Used only for flats with pixels that have palette index 255
TF_TRANSPARENT = 0x00000040, // texture with some alpha == 0
// rr
TF_BRIGHTMAP = 0x00000080,
};
struct FTextureInfo
......@@ -266,6 +269,7 @@ struct FLightInfo
FUINT light_level;
FUINT fade_start;
FUINT fade_end;
boolean directional; // rr
};
typedef struct FLightInfo FLightInfo;
......@@ -310,6 +314,13 @@ typedef enum hwdshaderstage hwdshaderstage_t;
enum hwdshaderinfo
{
HWD_SHADERINFO_LEVELTIME = 1,
// rr
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;
......
......@@ -93,6 +93,8 @@ typedef struct gl_vissprite_s
mobj_t *mobj; // NOTE: This is a precipmobj_t if precip is true !!! Watch out.
} gl_vissprite_t;
void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 *lightlevel, boolean model); // rr
// --------
// hw_bsp.c
// --------
......
This diff is collapsed.
......@@ -62,7 +62,7 @@ void HWR_DrawScreenFinalTexture(int width, int height);
// This stuff is put here so models can use them
boolean HWR_UseShader(void);
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); // rr
UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap); // Let's see if this can work
UINT8 HWR_GetTranstableAlpha(INT32 transtablenum);
......@@ -81,6 +81,10 @@ extern consvar_t cv_glcoronas;
extern consvar_t cv_glcoronasize;
#endif
// GLBADSHADOWS
extern consvar_t cv_shadowspr;
extern consvar_t cv_shadowsprdirection;
extern consvar_t cv_glshaders, cv_glallowshaders;
extern consvar_t cv_glmodels;
extern consvar_t cv_glmodelinterpolation;
......
......@@ -1225,7 +1225,8 @@ boolean HWR_DrawModel(gl_vissprite_t *spr)
if (spr->mobj->subsector)
{
sector_t *sector = spr->mobj->subsector->sector;
UINT8 lightlevel = 255;
//UINT8 lightlevel = 255;
INT32 lightlevel = 255; // rr
extracolormap_t *colormap = NULL;
if (sector->numlights)
......@@ -1257,7 +1258,11 @@ boolean HWR_DrawModel(gl_vissprite_t *spr)
colormap = sector->extra_colormap;
}
HWR_Lighting(&Surf, lightlevel, colormap);
//HWR_Lighting(&Surf, lightlevel, colormap);
// rr
//if (!lightset)
HWR_ObjectLightLevelPost(spr, sector, &lightlevel, true);
HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !R_ThingIsFullBright(spr->mobj));
}
else
Surf.PolyColor.rgba = 0xFFFFFFFF;
......
......@@ -626,6 +626,13 @@ typedef enum
gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table
gluniform_lighttable_tex, // 2d texture containing a light table
// rr
gluniform_tex,
gluniform_brightmap,
gluniform_light_dir,
gluniform_light_contrast,
gluniform_light_backlight,
// misc.
gluniform_leveltime,
......@@ -657,6 +664,13 @@ static gl_shaderstate_t gl_shaderstate;
// Shader info
static float shader_leveltime = 0;
// rr
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_CompileError(const char *message, GLuint program, INT32 shadernum);
......@@ -799,6 +813,22 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value)
case HWD_SHADERINFO_LEVELTIME:
shader_leveltime = (((float)(value-1)) + FIXED_TO_FLOAT(rendertimefrac)) / TICRATE;
break;
// rr
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;
}
......@@ -862,14 +892,17 @@ EXPORT void HWRAPI(UnSetShader) (void)
// -----------------+
// SetNoTexture : Disable texture
// -----------------+
static void SetNoTexture(void)
//static void SetNoTexture(void)
static void SetNoTexture(GLenum texture) // rr
{
// Disable texture.
if (tex_downloaded != NOTEXTURE_NUM)
{
if (NOTEXTURE_NUM == 0)
pglGenTextures(1, &NOTEXTURE_NUM);
pglActiveTexture(texture); // rr
pglBindTexture(GL_TEXTURE_2D, NOTEXTURE_NUM);
pglActiveTexture(GL_TEXTURE0); // rr
tex_downloaded = NOTEXTURE_NUM;
}
}
......@@ -1015,7 +1048,7 @@ void SetStates(void)
SetBlend(0);
tex_downloaded = 0;
SetNoTexture();
SetNoTexture(GL_TEXTURE0); // rr
pglPolygonOffset(-1.0f, -1.0f);
......@@ -1473,7 +1506,7 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags)
}
if (PolyFlags & PF_NoTexture)
{
SetNoTexture();
SetNoTexture(GL_TEXTURE0); // rr
}
}
CurrentPolyFlags = PolyFlags;
......@@ -1597,6 +1630,14 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
else
GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format);
// rr
if (!(pTexInfo->flags & TF_BRIGHTMAP))
{
tex_downloaded = 0; // force update
SetNoTexture(GL_TEXTURE1); // will be assigned later, if needed
}
pglActiveTexture(pTexInfo->flags & TF_BRIGHTMAP ? GL_TEXTURE1 : GL_TEXTURE0); // rr
pglBindTexture(GL_TEXTURE_2D, num);
tex_downloaded = num;
......@@ -1696,14 +1737,23 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo)
{
if (!pTexInfo)
{
SetNoTexture();
SetNoTexture(GL_TEXTURE0); // rr
return;
}
else if (pTexInfo->downloaded)
{
if (pTexInfo->downloaded != tex_downloaded)
{
// rr
if (!(pTexInfo->flags & TF_BRIGHTMAP))
{
tex_downloaded = 0; // force update
SetNoTexture(GL_TEXTURE1); // will be assigned later, if needed
}
pglActiveTexture(pTexInfo->flags & TF_BRIGHTMAP ? GL_TEXTURE1 : GL_TEXTURE0); // rr
pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded);
pglActiveTexture(GL_TEXTURE0); // rr
tex_downloaded = pTexInfo->downloaded;
}
}
......@@ -1775,15 +1825,33 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
function (uniform, a, b, c, d);
// polygon
UNIFORM_1(shader->uniforms[gluniform_tex], 0, pglUniform1i); // rr
UNIFORM_1(shader->uniforms[gluniform_brightmap], 1, pglUniform1i); // rr
UNIFORM_4(shader->uniforms[gluniform_poly_color], poly->red, poly->green, poly->blue, poly->alpha, pglUniform4f);
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; // rr
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; // rr
}
// rr
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);
......@@ -1911,6 +1979,13 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex");
shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex");
// rr
shader->uniforms[gluniform_tex] = GETUNI("tex");
shader->uniforms[gluniform_brightmap] = GETUNI("brightmap");
shader->uniforms[gluniform_light_dir] = GETUNI("light_dir");
shader->uniforms[gluniform_light_contrast] = GETUNI("light_contrast");
shader->uniforms[gluniform_light_backlight] = GETUNI("light_backlight");
// misc.
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
#undef GETUNI
......@@ -1923,9 +1998,14 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
pglUseProgram(shader->program);
// texture unit numbers for the samplers used for palette rendering
UNIFORM_1(shader->uniforms[gluniform_palette_tex], 2, pglUniform1i);
/*UNIFORM_1(shader->uniforms[gluniform_palette_tex], 2, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i);*/
// rr
UNIFORM_1(shader->uniforms[gluniform_palette_tex], 3, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 2, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 3, pglUniform1i);
// restore gl shader state
pglUseProgram(gl_shaderstate.program);
......@@ -1997,7 +2077,8 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD
if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded)
{
pglActiveTexture(GL_TEXTURE2);
//pglActiveTexture(GL_TEXTURE2);
pglActiveTexture(GL_TEXTURE3); // rr
pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId);
pglActiveTexture(GL_TEXTURE0);
lt_downloaded = pSurf->LightTableId;
......@@ -2564,7 +2645,8 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
if (Surface->LightTableId && Surface->LightTableId != lt_downloaded)
{
pglActiveTexture(GL_TEXTURE2);
//pglActiveTexture(GL_TEXTURE2);
pglActiveTexture(GL_TEXTURE3); // rr
pglBindTexture(GL_TEXTURE_2D, Surface->LightTableId);
pglActiveTexture(GL_TEXTURE0);
lt_downloaded = Surface->LightTableId;
......@@ -3223,7 +3305,8 @@ EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut)
}
if (!paletteLookupTex)
pglGenTextures(1, &paletteLookupTex);
pglActiveTexture(GL_TEXTURE1);
//pglActiveTexture(GL_TEXTURE1);
pglActiveTexture(GL_TEXTURE2); // rr
pglBindTexture(GL_TEXTURE_3D, paletteLookupTex);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
......@@ -3282,7 +3365,8 @@ EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette)
memcpy(screenPalette, palette, sizeof(screenPalette));
if (!screenPaletteTex)
pglGenTextures(1, &screenPaletteTex);
pglActiveTexture(GL_TEXTURE2);
//pglActiveTexture(GL_TEXTURE2);
pglActiveTexture(GL_TEXTURE3); // rr
pglBindTexture(GL_TEXTURE_1D, screenPaletteTex);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
......
// DR. ROBOTNIK'S RING RACERS
//-----------------------------------------------------------------------------
// Copyright (C) 2024 by Sally "TehRealSalt" Cochenour
// Copyright (C) 2024 by Kart Krew
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file k_brightmap.c
/// \brief Brightmap texture loading.
#include "k_brightmap.h"
#include "doomdata.h"
#include "doomdef.h"
#include "doomtype.h"
#include "fastcmp.h"
#include "r_textures.h"
#include "w_wad.h"
#include "z_zone.h"
static brightmapStorage_t *brightmapStorage = NULL;
static size_t maxBrightmapStorage = 0;
/*--------------------------------------------------
static brightmapStorage_t *K_NewBrightmap(void)
Increases the size of maxBrightmapStorage by 1.
Input Arguments:-
None
Return:-
The new brightmap storage struct.
--------------------------------------------------*/
static brightmapStorage_t *K_NewBrightmap(void)
{
maxBrightmapStorage++;
brightmapStorage = (brightmapStorage_t *)Z_Realloc(brightmapStorage, sizeof(brightmapStorage_t) * (maxBrightmapStorage + 1), PU_STATIC, &brightmapStorage);
return &brightmapStorage[ maxBrightmapStorage - 1 ];
}
/*--------------------------------------------------
static brightmapStorage_t *K_GetBrightmapStorageByIndex(size_t checkIndex)
See header file for description.
--------------------------------------------------*/
static brightmapStorage_t *K_GetBrightmapStorageByIndex(size_t checkIndex)
{
if (checkIndex >= maxBrightmapStorage)
{
return NULL;
}
return &brightmapStorage[checkIndex];
}
/*--------------------------------------------------
static brightmapStorage_t *K_GetBrightmapStorageByTextureName(const char *checkName)
See header file for description.
--------------------------------------------------*/
static brightmapStorage_t *K_GetBrightmapStorageByTextureName(const char *checkName)
{
UINT32 checkHash = quickncasehash(checkName, 8);
size_t i;
if (maxBrightmapStorage == 0)
{
return NULL;
}
for (i = 0; i < maxBrightmapStorage; i++)
{
brightmapStorage_t *bms = &brightmapStorage[i];
if (checkHash == bms->textureHash && !strncmp(checkName, bms->textureName, 8))
{
// Name matches.
return bms;
}
}
return NULL;
}
/*--------------------------------------------------
static boolean K_BRIGHTLumpParser(char *data, size_t size)
Parses inputted lump data as a BRIGHT lump.
Input Arguments:-
data - Pointer to lump data.
size - The length of the lump data.
Return:-
false if any errors occured, otherwise true.
--------------------------------------------------*/
static boolean K_BRIGHTLumpParser(char *data, size_t size)
{
char *tkn = M_GetToken((char *)data);
size_t pos = 0;
while (tkn && (pos = M_GetTokenPos()) < size)
{
boolean valid = true;
if (stricmp(tkn, "texture") == 0)
{
Z_Free(tkn);
tkn = M_GetToken(NULL);
pos = M_GetTokenPos();
if (tkn && pos < size)
{
brightmapStorage_t *bms = K_GetBrightmapStorageByTextureName(tkn);
if (bms == NULL)
{
bms = K_NewBrightmap();
strncpy(bms->textureName, tkn, 8);
bms->textureHash = quickncasehash(tkn, 8);
}
Z_Free(tkn);
tkn = M_GetToken(NULL);
pos = M_GetTokenPos();
if (tkn && pos < size)
{
strncpy(bms->brightmapName, tkn, 8);
bms->brightmapHash = quickncasehash(tkn, 8);
}
else
{
CONS_Alert(CONS_ERROR, "No brightmap for brightmap definition.\n");
valid = false;
}
}
else
{
CONS_Alert(CONS_ERROR, "No texture for brightmap definition.\n");
valid = false;
}
}
// todo: SPRITE brightmaps?!
else
{
CONS_Alert(CONS_ERROR, "Unknown keyword '%s' found in BRIGHT lump.\n", tkn);
valid = false;
}
Z_Free(tkn);
if (valid == false)
{
return false;
}
tkn = M_GetToken(NULL);
}
Z_Free(tkn);
return true;
}
/*--------------------------------------------------
void K_InitBrightmapsPwad(INT32 wadNum)
See header file for description.
--------------------------------------------------*/
void K_InitBrightmapsPwad(INT32 wadNum)
{
UINT16 lumpNum;
size_t i;
I_Assert(brightmapStorage == NULL);
// Find BRIGHT lump in the WAD
lumpNum = W_CheckNumForNamePwad("BRIGHT", wadNum, 0);
while (lumpNum != INT16_MAX)
{
UINT8 *data = (UINT8 *)W_CacheLumpNumPwad(wadNum, lumpNum, PU_CACHE);
if (data != NULL)
{
lumpinfo_t *lump_p = &wadfiles[wadNum]->lumpinfo[lumpNum];
size_t size = W_LumpLengthPwad(wadNum, lumpNum);
char *datacopy;
size_t nameLength = strlen(wadfiles[wadNum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = malloc(nameLength + 1);
sprintf(name, "%s|%s", wadfiles[wadNum]->filename, lump_p->fullname);
name[nameLength] = '\0';
size = W_LumpLengthPwad(wadNum, lumpNum);
CONS_Printf(M_GetText("Loading BRIGHT from %s\n"), name);
datacopy = (char *)Z_Malloc((size+1)*sizeof(char),PU_STATIC,NULL);
memmove(datacopy,data,size);
datacopy[size] = '\0';
Z_Free(data);
K_BRIGHTLumpParser(datacopy, size);
Z_Free(datacopy);
free(name);
}
lumpNum = W_CheckNumForNamePwad("BRIGHT", (UINT16)wadNum, lumpNum + 1);
}
if (maxBrightmapStorage == 0)
{
// No brightmaps were defined.
return;
}
for (i = 0; i < maxBrightmapStorage; i++)
{
brightmapStorage_t *bms = K_GetBrightmapStorageByIndex(i);
INT32 texNum, bmNum;
if (bms == NULL)
{
// Shouldn't happen.
break;
}
texNum = R_CheckTextureNumForName(bms->textureName);
if (texNum != -1)
{
bmNum = R_CheckTextureNumForName(bms->brightmapName);
R_UpdateTextureBrightmap(texNum, (bmNum == -1 ? 0 : bmNum));
}
}
R_ClearTextureNumCache(false);
// Clear brightmapStorage now that we're done with it.
Z_Free(brightmapStorage);
brightmapStorage = NULL;
maxBrightmapStorage = 0;
}
/*--------------------------------------------------
void K_InitBrightmaps(void)
See header file for description.
--------------------------------------------------*/
void K_InitBrightmaps(void)
{
INT32 wadNum;
for (wadNum = 0; wadNum < numwadfiles; wadNum++)
{
K_InitBrightmapsPwad(wadNum);
}
}
// DR. ROBOTNIK'S RING RACERS
//-----------------------------------------------------------------------------
// Copyright (C) 2024 by Sally "TehRealSalt" Cochenour
// Copyright (C) 2024 by Kart Krew
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file k_brightmap.h
/// \brief Brightmap texture loading.
#ifndef __K_BRIGHTMAP_H__
#define __K_BRIGHTMAP_H__
#include "doomdata.h"
#include "doomdef.h"
#include "doomtype.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
// Brightmap storage struct.
// Stores data for brightmap definitions,
// before putting them into texturebrightmaps.
char textureName[9]; // The texture's name.
UINT32 textureHash; // The texture name's hash.
char brightmapName[9]; // The brightmap's name.
UINT32 brightmapHash; // The brightmap name's hash.
} brightmapStorage_t;
/*--------------------------------------------------
void K_InitBrightmapsPwad(INT32 wadNum);
Finds all BRIGHT lumps for one WAD/PK3 and processes them.
--------------------------------------------------*/
void K_InitBrightmapsPwad(INT32 wadNum);
/*--------------------------------------------------
void K_InitBrightmaps(void);
Finds all BRIGHT lumps and processes them.
--------------------------------------------------*/
void K_InitBrightmaps(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __K_BRIGHTMAP_H__