Finished adding Prey's material tokens.

This commit is contained in:
Justin Marshall
2026-05-05 17:57:38 -07:00
parent d06356e042
commit a51e42f312
2 changed files with 409 additions and 213 deletions
+155 -5
View File
@@ -1159,6 +1159,10 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
textureDepth_t td; textureDepth_t td;
cubeFiles_t cubeMap; cubeFiles_t cubeMap;
bool allowPicmip; bool allowPicmip;
#ifdef PREY
bool highres;
bool preyTokenOnlyStage;
#endif
char imageName[MAX_IMAGE_NAME]; char imageName[MAX_IMAGE_NAME];
int a, b; int a, b;
int matrix[2][3]; int matrix[2][3];
@@ -1173,6 +1177,10 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
trp = trpDefault; trp = trpDefault;
td = TD_DEFAULT; td = TD_DEFAULT;
allowPicmip = true; allowPicmip = true;
#ifdef PREY
highres = false;
preyTokenOnlyStage = false;
#endif
cubeMap = CF_2D; cubeMap = CF_2D;
imageName[0] = 0; imageName[0] = 0;
@@ -1183,6 +1191,16 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
ts = &ss->texture; ts = &ss->texture;
ClearStage(ss); ClearStage(ss);
#ifdef PREY
ss->isGlow = false;
ss->isScopeView = false;
ss->isShuttleView = false;
ss->isNotScopeView = false;
ss->isSpiritWalk = false;
ss->isNotSpiritWalk = false;
ss->specular.exponent = 22.0f;
ss->specular.brightness = 1.4f;
#endif
while (1) { while (1) {
if (TestMaterialFlag(MF_DEFAULTED)) { // we have a parse error if (TestMaterialFlag(MF_DEFAULTED)) { // we have a parse error
@@ -1230,6 +1248,22 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
ts->texgen = TG_SCREEN; ts->texgen = TG_SCREEN;
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("portalRenderMap")) {
ts->dynamic = DI_PORTAL_RENDER;
ts->width = src.ParseInt();
ts->height = src.ParseInt();
ts->texgen = TG_SCREEN;
continue;
}
if (!token.Icmp("skyboxRenderMap")) {
ts->dynamic = DI_SKYBOX_RENDER;
ts->width = src.ParseInt();
ts->height = src.ParseInt();
ts->texgen = TG_SCREEN;
continue;
}
#endif
if (!token.Icmp("xrayRenderMap")) { if (!token.Icmp("xrayRenderMap")) {
ts->dynamic = DI_XRAY_RENDER; ts->dynamic = DI_XRAY_RENDER;
@@ -1280,6 +1314,18 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
ts->cinematic->InitFromFile(token.c_str(), true); ts->cinematic->InitFromFile(token.c_str(), true);
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("profilemap")) {
if (!src.ReadToken(&token)) {
common->Warning("missing parameter for 'profilemap' keyword in material '%s'", GetName());
continue;
}
// Prey creates an hhProfilerGraph cinematic here. Consume the token so
// retail Prey materials parse even in builds without that runtime class.
preyTokenOnlyStage = true;
continue;
}
#endif
if (!token.Icmp("cubeMap")) { if (!token.Icmp("cubeMap")) {
str = R_ParsePastImageProgram(src); str = R_ParsePastImageProgram(src);
@@ -1337,6 +1383,14 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
allowPicmip = false; allowPicmip = false;
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("highres")) {
// The Hex-Rays build records this and passes it to Prey's image manager.
// This Doom 3-side patch only needs to accept the token safely.
highres = true;
continue;
}
#endif
if (!token.Icmp("vertexColor")) { if (!token.Icmp("vertexColor")) {
ss->vertexColor = SVC_MODULATE; ss->vertexColor = SVC_MODULATE;
continue; continue;
@@ -1358,21 +1412,57 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("glowStage")) {
ss->isGlow = true;
continue;
}
if (!token.Icmp("scopeView")) {
ss->isScopeView = true;
continue;
}
if (!token.Icmp("shuttleView")) {
ss->isShuttleView = true;
continue;
}
if (!token.Icmp("notScopeView")) {
ss->isNotScopeView = true;
continue;
}
if (!token.Icmp("spiritWalk")) {
ss->isSpiritWalk = true;
continue;
}
if (!token.Icmp("notSpiritWalk")) {
ss->isNotSpiritWalk = true;
continue;
}
#endif
// texture coordinate generation // texture coordinate generation
if (!token.Icmp("texGen")) { if (!token.Icmp("texGen")) {
src.ExpectAnyToken(&token); src.ExpectAnyToken(&token);
if (!token.Icmp("normal")) { if (!token.Icmp("normal")) {
ts->texgen = TG_DIFFUSE_CUBE; ts->texgen = TG_DIFFUSE_CUBE;
} else if ( !token.Icmp( "reflect" ) ) { }
else if (!token.Icmp("reflect")) {
ts->texgen = TG_REFLECT_CUBE; ts->texgen = TG_REFLECT_CUBE;
} else if ( !token.Icmp( "skybox" ) ) { }
else if (!token.Icmp("skybox")) {
ts->texgen = TG_SKYBOX_CUBE; ts->texgen = TG_SKYBOX_CUBE;
} else if ( !token.Icmp( "wobbleSky" ) ) { }
else if (!token.Icmp("wobbleSky")) {
ts->texgen = TG_WOBBLESKY_CUBE; ts->texgen = TG_WOBBLESKY_CUBE;
texGenRegisters[0] = ParseExpression(src); texGenRegisters[0] = ParseExpression(src);
texGenRegisters[1] = ParseExpression(src); texGenRegisters[1] = ParseExpression(src);
texGenRegisters[2] = ParseExpression(src); texGenRegisters[2] = ParseExpression(src);
} else { #ifdef PREY
}
else if (!token.Icmp("screen")) {
ts->texgen = TG_SCREEN;
#endif
}
else {
common->Warning("bad texGen '%s' in material %s", token.c_str(), GetName()); common->Warning("bad texGen '%s' in material %s", token.c_str(), GetName());
SetMaterialFlag(MF_DEFAULTED); SetMaterialFlag(MF_DEFAULTED);
} }
@@ -1555,12 +1645,64 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
ss->color.registers[2] = ss->color.registers[3] = ParseExpression(src); ss->color.registers[2] = ss->color.registers[3] = ParseExpression(src);
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("specularExp")) {
ss->specular.exponent = src.ParseFloat();
MatchToken(src, ",");
ss->specular.brightness = src.ParseFloat();
continue;
}
#endif
if (!token.Icmp("if")) { if (!token.Icmp("if")) {
ss->conditionRegister = ParseExpression(src); ss->conditionRegister = ParseExpression(src);
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("program")) {
if (!src.ReadTokenOnLine(&token)) {
common->Warning("missing parameter for 'program' keyword in material '%s'", GetName());
}
preyTokenOnlyStage = true;
continue;
}
if (!token.Icmp("fragmentProgram")) {
if (!src.ReadTokenOnLine(&token)) {
common->Warning("missing parameter for 'fragmentProgram' keyword in material '%s'", GetName());
}
preyTokenOnlyStage = true;
continue;
}
if (!token.Icmp("vertexProgram")) {
if (!src.ReadTokenOnLine(&token)) {
common->Warning("missing parameter for 'vertexProgram' keyword in material '%s'", GetName());
}
preyTokenOnlyStage = true;
continue;
}
if (!token.Icmp("megaTexture")) {
// Full Prey allocates idMegaTexture and binds megaTexture.vfp.
// Keep this parser-only path dependency-free.
if (!src.ReadTokenOnLine(&token)) {
common->Warning("missing parameter for 'megaTexture' keyword in material '%s'", GetName());
}
preyTokenOnlyStage = true;
continue;
}
if (!token.Icmp("vertexParm") || !token.Icmp("fragmentParm") || !token.Icmp("fragmentMap")) {
// These are all single-line shader-program directives in the dump.
src.SkipRestOfLine();
preyTokenOnlyStage = true;
continue;
}
if (!token.Icmp("shaderLevel1") || !token.Icmp("shaderLevel2") || !token.Icmp("shaderLevel3") ||
!token.Icmp("shaderFallback1") || !token.Icmp("shaderFallback2") || !token.Icmp("shaderFallback3")) {
preyTokenOnlyStage = true;
continue;
}
#endif
common->Warning("unknown token '%s' in material '%s'", token.c_str(), GetName()); common->Warning("unknown token '%s' in material '%s'", token.c_str(), GetName());
SetMaterialFlag(MF_DEFAULTED); SetMaterialFlag(MF_DEFAULTED);
@@ -1595,12 +1737,20 @@ void idMaterial::ParseStage( idLexer &src, const textureRepeat_t trpDefault ) {
} }
// now load the image with all the parms we parsed // now load the image with all the parms we parsed
#ifdef PREY
(void)highres; // parsed for Prey material compatibility; Doom 3 ImageFromFile has no highres arg.
#endif
if (imageName[0]) { if (imageName[0]) {
ts->image = globalImages->ImageFromFile(imageName, tf, allowPicmip, trp, td, cubeMap); ts->image = globalImages->ImageFromFile(imageName, tf, allowPicmip, trp, td, cubeMap);
if (!ts->image) { if (!ts->image) {
ts->image = globalImages->defaultImage; ts->image = globalImages->defaultImage;
} }
} else if ( !ts->cinematic && !ts->dynamic && !ss->newStage ) { }
else if (!ts->cinematic && !ts->dynamic && !ss->newStage
#ifdef PREY
&& !preyTokenOnlyStage
#endif
) {
common->Warning("material '%s' had stage with no image", GetName()); common->Warning("material '%s' had stage with no image", GetName());
ts->image = globalImages->defaultImage; ts->image = globalImages->defaultImage;
} }
+46
View File
@@ -95,6 +95,10 @@ typedef enum {
DI_CUBE_RENDER, DI_CUBE_RENDER,
DI_MIRROR_RENDER, DI_MIRROR_RENDER,
DI_XRAY_RENDER, DI_XRAY_RENDER,
#ifdef PREY
DI_PORTAL_RENDER, // HUMANHEAD
DI_SKYBOX_RENDER, // HUMANHEAD tmj
#endif
DI_REMOTE_RENDER DI_REMOTE_RENDER
} dynamicidImage_t; } dynamicidImage_t;
@@ -115,6 +119,9 @@ typedef enum {
OP_TYPE_AND, OP_TYPE_AND,
OP_TYPE_OR, OP_TYPE_OR,
OP_TYPE_SOUND OP_TYPE_SOUND
#ifdef PREY
, OP_TYPE_FRAGMENTPROGRAMS // HUMANHEAD CJR: fragment program support toggle
#endif
} expOpType_t; } expOpType_t;
typedef enum { typedef enum {
@@ -188,6 +195,9 @@ typedef enum {
SL_BUMP, SL_BUMP,
SL_DIFFUSE, SL_DIFFUSE,
SL_SPECULAR SL_SPECULAR
#ifdef PREY
, SL_SHADER
#endif
} stageLighting_t; } stageLighting_t;
// cross-blended terrain textures need to modulate the color by // cross-blended terrain textures need to modulate the color by
@@ -199,12 +209,21 @@ typedef enum {
} stageVertexColor_t; } stageVertexColor_t;
static const int MAX_FRAGMENT_IMAGES = 8; static const int MAX_FRAGMENT_IMAGES = 8;
#ifdef PREY
static const int MAX_VERTEX_PARMS = 8;
static const int MAX_FRAGMENT_PARMS = 8;
#else
static const int MAX_VERTEX_PARMS = 4; static const int MAX_VERTEX_PARMS = 4;
#endif
typedef struct { typedef struct {
int vertexProgram; int vertexProgram;
int numVertexParms; int numVertexParms;
int vertexParms[MAX_VERTEX_PARMS][4]; // evaluated register indexes int vertexParms[MAX_VERTEX_PARMS][4]; // evaluated register indexes
#ifdef PREY
int numFragmentParms;
int fragmentParms[MAX_FRAGMENT_PARMS][4]; // evaluated register indexes
#endif
int fragmentProgram; int fragmentProgram;
int numFragmentProgramImages; int numFragmentProgramImages;
@@ -213,6 +232,14 @@ typedef struct {
idMegaTexture* megaTexture; // handles all the binding and parameter setting idMegaTexture* megaTexture; // handles all the binding and parameter setting
} newShaderStage_t; } newShaderStage_t;
#ifdef PREY
// HUMANHEAD bjk: specular exponent/brightness parsed by specularExp.
typedef struct {
float exponent;
float brightness;
} specData_t;
#endif
typedef struct { typedef struct {
int conditionRegister; // if registers[conditionRegister] == 0, skip stage int conditionRegister; // if registers[conditionRegister] == 0, skip stage
stageLighting_t lighting; // determines which passes interact with lights stageLighting_t lighting; // determines which passes interact with lights
@@ -225,8 +252,20 @@ typedef struct {
bool ignoreAlphaTest; // this stage should act as translucent, even bool ignoreAlphaTest; // this stage should act as translucent, even
// if the surface is alpha tested // if the surface is alpha tested
float privatePolygonOffset; // a per-stage polygon offset float privatePolygonOffset; // a per-stage polygon offset
#ifdef PREY
bool isGlow; // HUMANHEAD CJR: Glow overlay
bool isScopeView; // HUMANHEAD CJR: Scope view
bool isShuttleView; // HUMANHEAD pdm: shuttle view
bool isNotScopeView; // HUMANHEAD CJR
bool isSpiritWalk; // HUMANHEAD CJR
bool isNotSpiritWalk; // HUMANHEAD CJR
#endif
newShaderStage_t* newStage; // vertex / fragment program based stage newShaderStage_t* newStage; // vertex / fragment program based stage
#ifdef PREY
specData_t specular; // HUMANHEAD bjk
#endif
} shaderStage_t; } shaderStage_t;
typedef enum { typedef enum {
@@ -268,7 +307,11 @@ const int MAX_SHADER_STAGES = 256;
const int MAX_TEXGEN_REGISTERS = 4; const int MAX_TEXGEN_REGISTERS = 4;
#ifdef PREY
const int MAX_ENTITY_SHADER_PARMS = 13; // HUMANHEAD pdm: increased from 12
#else
const int MAX_ENTITY_SHADER_PARMS = 12; const int MAX_ENTITY_SHADER_PARMS = 12;
#endif
// material flags // material flags
typedef enum { typedef enum {
@@ -675,6 +718,9 @@ private:
void ParseSort(idLexer& src); void ParseSort(idLexer& src);
void ParseBlend(idLexer& src, shaderStage_t* stage); void ParseBlend(idLexer& src, shaderStage_t* stage);
void ParseVertexParm(idLexer& src, newShaderStage_t* newStage); void ParseVertexParm(idLexer& src, newShaderStage_t* newStage);
#ifdef PREY
void ParseFragmentParm(idLexer& src, newShaderStage_t* newStage);
#endif
void ParseFragmentMap(idLexer& src, newShaderStage_t* newStage); void ParseFragmentMap(idLexer& src, newShaderStage_t* newStage);
void ParseStage(idLexer& src, const textureRepeat_t trpDefault = TR_REPEAT); void ParseStage(idLexer& src, const textureRepeat_t trpDefault = TR_REPEAT);
void ParseDeform(idLexer& src); void ParseDeform(idLexer& src);