Simplified some rendering code for CBaseEntity/glows
This commit is contained in:
parent
d39fb1cdc2
commit
b31ab5761a
2 changed files with 81 additions and 103 deletions
|
@ -51,36 +51,26 @@ CBaseEntity::RenderFXPass(void)
|
||||||
abslight = 255;
|
abslight = 255;
|
||||||
break;
|
break;
|
||||||
case RM_GLOW:
|
case RM_GLOW:
|
||||||
if (checkpvs(vecPlayer, this) == FALSE) {
|
if (checkpvs(vecPlayer, this) == FALSE)
|
||||||
alpha -= clframetime;
|
alpha -= clframetime;
|
||||||
}
|
|
||||||
|
|
||||||
other = world;
|
other = world;
|
||||||
traceline(this.origin, vecPlayer, MOVE_OTHERONLY, this);
|
traceline(this.origin, vecPlayer, MOVE_OTHERONLY, this);
|
||||||
|
|
||||||
/* If we can't trace against the player, or are two close, fade out */
|
/* If we can't trace against the player, or are two close, fade out */
|
||||||
if (trace_fraction < 1.0f || vlen(origin - vecPlayer) < 128) {
|
if (trace_fraction < 1.0f || vlen(origin - vecPlayer) < 128)
|
||||||
alpha -= clframetime;
|
alpha -= clframetime;
|
||||||
} else {
|
else
|
||||||
alpha += clframetime;
|
alpha += clframetime;
|
||||||
}
|
|
||||||
|
|
||||||
alpha = bound(0, alpha, 1.0f);
|
/* max alpha will be applied here to the color instead */
|
||||||
|
colormod *= m_flRenderAmt;
|
||||||
|
alpha = bound(0.0f, alpha, 1.0f);
|
||||||
effects = EF_ADDITIVE | EF_FULLBRIGHT;
|
effects = EF_ADDITIVE | EF_FULLBRIGHT;
|
||||||
|
|
||||||
if (alpha > 0) {
|
/* Scale the glow somewhat with the players distance */
|
||||||
float falpha;
|
if (alpha > 0.0f)
|
||||||
|
|
||||||
/* Scale the glow somewhat with the players distance */
|
|
||||||
scale = bound(1, vlen(vecPlayer - origin) / 256, 4);
|
scale = bound(1, vlen(vecPlayer - origin) / 256, 4);
|
||||||
|
|
||||||
/* Fade out when the player is starting to move away */
|
|
||||||
falpha = 1 - bound(0, vlen(vecPlayer - origin) / 1024, 1);
|
|
||||||
falpha *= alpha;
|
|
||||||
|
|
||||||
/* Clamp the alpha by the glows' renderamt value */
|
|
||||||
alpha = bound(0, falpha, m_flRenderAmt);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case RM_SOLID:
|
case RM_SOLID:
|
||||||
break;
|
break;
|
||||||
|
@ -223,7 +213,8 @@ CBaseEntity::Sentence(string msg)
|
||||||
m_flSentenceTime = time;
|
m_flSentenceTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseEntity::ReceiveEntity(float flChanged)
|
void
|
||||||
|
CBaseEntity::ReceiveEntity(float flChanged)
|
||||||
{
|
{
|
||||||
if (flChanged & BASEFL_CHANGED_ORIGIN) {
|
if (flChanged & BASEFL_CHANGED_ORIGIN) {
|
||||||
origin[0] = readcoord();
|
origin[0] = readcoord();
|
||||||
|
@ -306,57 +297,57 @@ void CBaseEntity::ReceiveEntity(float flChanged)
|
||||||
setsize(this, mins, maxs);
|
setsize(this, mins, maxs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseEntity::SpawnKey(string strField, string strKey)
|
void
|
||||||
|
CBaseEntity::SpawnKey(string strField, string strKey)
|
||||||
{
|
{
|
||||||
switch (strField) {
|
switch (strField) {
|
||||||
/* compiler specific stuff */
|
/* compiler specific stuff */
|
||||||
case "angle":
|
case "angle":
|
||||||
case "_minlight":
|
case "_minlight":
|
||||||
case "_cs":
|
case "_cs":
|
||||||
break;
|
break;
|
||||||
case "shadows":
|
case "shadows":
|
||||||
if (stof(strKey) == 1) {
|
if (stof(strKey) == 1)
|
||||||
effects &= ~EF_NOSHADOW;
|
effects &= ~EF_NOSHADOW;
|
||||||
}
|
break;
|
||||||
break;
|
case "targetname":
|
||||||
case "targetname":
|
targetname = strKey;
|
||||||
targetname = strKey;
|
break;
|
||||||
break;
|
case "target":
|
||||||
case "target":
|
target = strKey;
|
||||||
target = strKey;
|
break;
|
||||||
break;
|
case "origin":
|
||||||
case "origin":
|
origin = stov(strKey);
|
||||||
origin = stov(strKey);
|
setorigin(this, origin);
|
||||||
setorigin(this, origin);
|
break;
|
||||||
break;
|
case "angles":
|
||||||
case "angles":
|
angles = stov(strKey);
|
||||||
angles = stov(strKey);
|
break;
|
||||||
break;
|
case "model":
|
||||||
case "model":
|
model = strKey;
|
||||||
model = strKey;
|
break;
|
||||||
break;
|
case "style":
|
||||||
case "style":
|
style = stof(strKey);
|
||||||
style = stof(strKey);
|
break;
|
||||||
break;
|
case "color":
|
||||||
case "color":
|
color = stov(strKey);
|
||||||
color = stov(strKey);
|
break;
|
||||||
break;
|
case "movetype":
|
||||||
case "movetype":
|
movetype = stof(strKey);
|
||||||
movetype = stof(strKey);
|
break;
|
||||||
break;
|
case "solid":
|
||||||
case "solid":
|
solid = stof(strKey);
|
||||||
solid = stof(strKey);
|
break;
|
||||||
break;
|
case "scale":
|
||||||
case "scale":
|
scale = stof(strKey);
|
||||||
scale = stof(strKey);
|
break;
|
||||||
break;
|
case "spawnflags":
|
||||||
case "spawnflags":
|
spawnflags = stof(strKey);
|
||||||
spawnflags = stof(strKey);
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
|
||||||
#ifdef GS_DEVELOPER
|
#ifdef GS_DEVELOPER
|
||||||
print(sprintf("%s::SpawnKey: Unknown '%s' value '%s'\n",
|
print(sprintf("%s::SpawnKey: Unknown '%s' value '%s'\n",
|
||||||
this.classname, strField, strKey));
|
this.classname, strField, strKey));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,21 +386,25 @@ CBaseEntity::ModelEvent(float fTimeStamp, int iCode, string sData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseEntity::Init(void)
|
void
|
||||||
|
CBaseEntity::Init(void)
|
||||||
{
|
{
|
||||||
isCSQC = TRUE;
|
isCSQC = TRUE;
|
||||||
effects |= EF_NOSHADOW;
|
effects |= EF_NOSHADOW;
|
||||||
for (int i = 0; i < (tokenize(__fullspawndata) - 1); i += 2) {
|
|
||||||
|
for (int i = 0; i < (tokenize(__fullspawndata) - 1); i += 2)
|
||||||
SpawnKey(argv(i), argv(i+1));
|
SpawnKey(argv(i), argv(i+1));
|
||||||
}
|
|
||||||
Initialized();
|
Initialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseEntity::Initialized(void)
|
void
|
||||||
|
CBaseEntity::Initialized(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseEntity::CBaseEntity(void)
|
void
|
||||||
|
CBaseEntity::CBaseEntity(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ class env_glow:CBaseEntity
|
||||||
float m_flScale;
|
float m_flScale;
|
||||||
|
|
||||||
void(void) env_glow;
|
void(void) env_glow;
|
||||||
virtual void(void) customphysics;
|
|
||||||
virtual float() predraw;
|
virtual float() predraw;
|
||||||
virtual void(string, string) SpawnKey;
|
virtual void(string, string) SpawnKey;
|
||||||
};
|
};
|
||||||
|
@ -54,19 +53,24 @@ env_glow::predraw(void)
|
||||||
if (checkpvs(vecPlayer, this) == FALSE)
|
if (checkpvs(vecPlayer, this) == FALSE)
|
||||||
return PREDRAW_NEXT;
|
return PREDRAW_NEXT;
|
||||||
|
|
||||||
|
other = world;
|
||||||
|
traceline(this.origin, vecPlayer, MOVE_OTHERONLY, this);
|
||||||
|
|
||||||
|
/* If we can't trace against the player, or are two close, fade out */
|
||||||
|
if (trace_fraction < 1.0f || vlen(origin - vecPlayer) < 128)
|
||||||
|
m_flAlpha -= clframetime;
|
||||||
|
else
|
||||||
|
m_flAlpha += clframetime;
|
||||||
|
|
||||||
m_flAlpha = bound(0.0f, m_flAlpha, 1.0f);
|
m_flAlpha = bound(0.0f, m_flAlpha, 1.0f);
|
||||||
|
|
||||||
if (m_flAlpha < 0.0f)
|
if (m_flAlpha <= 0.0f)
|
||||||
return PREDRAW_NEXT;
|
return PREDRAW_NEXT;
|
||||||
|
|
||||||
/* Scale the glow somewhat with the players distance */
|
/* Scale the glow somewhat with the players distance */
|
||||||
fsize = m_vecSize * m_flScale;
|
fsize = m_vecSize * m_flScale;
|
||||||
fsize *= bound(1, vlen(vecPlayer - origin) / 256, 4);
|
fsize *= bound(1, vlen(vecPlayer - origin) / 256, 4);
|
||||||
|
|
||||||
/* Fade out when the player is starting to move away */
|
|
||||||
falpha = 1;
|
|
||||||
falpha *= m_flAlpha;
|
|
||||||
|
|
||||||
makevectors(view_angles);
|
makevectors(view_angles);
|
||||||
|
|
||||||
/* Nudge this slightly towards the camera */
|
/* Nudge this slightly towards the camera */
|
||||||
|
@ -77,40 +81,19 @@ env_glow::predraw(void)
|
||||||
makevectors(view_angles);
|
makevectors(view_angles);
|
||||||
R_BeginPolygon(m_strSprite, 1, 0);
|
R_BeginPolygon(m_strSprite, 1, 0);
|
||||||
R_PolygonVertex(forg + v_right * fsize[0] - v_up * fsize[1],
|
R_PolygonVertex(forg + v_right * fsize[0] - v_up * fsize[1],
|
||||||
[1,1], m_vecColor * m_flMaxAlpha, falpha);
|
[1,1], m_vecColor * m_flMaxAlpha, m_flAlpha);
|
||||||
R_PolygonVertex(forg - v_right * fsize[0] - v_up * fsize[1],
|
R_PolygonVertex(forg - v_right * fsize[0] - v_up * fsize[1],
|
||||||
[0,1], m_vecColor * m_flMaxAlpha, falpha);
|
[0,1], m_vecColor * m_flMaxAlpha, m_flAlpha);
|
||||||
R_PolygonVertex(forg - v_right * fsize[0] + v_up * fsize[1],
|
R_PolygonVertex(forg - v_right * fsize[0] + v_up * fsize[1],
|
||||||
[0,0], m_vecColor * m_flMaxAlpha, falpha);
|
[0,0], m_vecColor * m_flMaxAlpha, m_flAlpha);
|
||||||
R_PolygonVertex(forg + v_right * fsize[0] + v_up * fsize[1],
|
R_PolygonVertex(forg + v_right * fsize[0] + v_up * fsize[1],
|
||||||
[1,0], m_vecColor * m_flMaxAlpha, falpha);
|
[1,0], m_vecColor * m_flMaxAlpha, m_flAlpha);
|
||||||
R_EndPolygon();
|
R_EndPolygon();
|
||||||
addentity(this);
|
addentity(this);
|
||||||
|
|
||||||
return PREDRAW_NEXT;
|
return PREDRAW_NEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
env_glow::customphysics(void)
|
|
||||||
{
|
|
||||||
vector vecPlayer;
|
|
||||||
int s = (float)getproperty(VF_ACTIVESEAT);
|
|
||||||
|
|
||||||
pSeat = &g_seats[s];
|
|
||||||
vecPlayer = pSeat->m_vecPredictedOrigin;
|
|
||||||
|
|
||||||
other = world;
|
|
||||||
traceline(this.origin, vecPlayer, MOVE_OTHERONLY, this);
|
|
||||||
|
|
||||||
/* If we can't trace against the player, or are two close, fade out */
|
|
||||||
if (trace_fraction < 1.0f || vlen(origin - vecPlayer) < 128) {
|
|
||||||
m_flAlpha -= clframetime;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_flAlpha += clframetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
env_glow::SpawnKey(string strField, string strKey)
|
env_glow::SpawnKey(string strField, string strKey)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue