Skip to content

Intensity property for GLDEFS and A_AttachLights #3085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/playsim/a_dynlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void AttachLight(AActor *self)

light->pSpotInnerAngle = &self->AngleVar(NAME_SpotInnerAngle);
light->pSpotOuterAngle = &self->AngleVar(NAME_SpotOuterAngle);
light->lightDefIntensity = 1.0;
light->pPitch = &self->Angles.Pitch;
light->pLightFlags = (LightFlags*)&self->IntVar(NAME_lightflags);
light->pArgs = self->args;
Expand Down Expand Up @@ -863,7 +864,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_AttachLightDef, AttachLightDef)
//
//==========================================================================

int AttachLightDirect(AActor *self, int _lightid, int type, int color, int radius1, int radius2, int flags, double ofs_x, double ofs_y, double ofs_z, double param, double spoti, double spoto, double spotp)
int AttachLightDirect(AActor *self, int _lightid, int type, int color, int radius1, int radius2, int flags, double ofs_x, double ofs_y, double ofs_z, double param, double spoti, double spoto, double spotp, double intensity)
{
FName lightid = FName(ENamedName(_lightid));
auto userlight = self->UserLights[FindUserLight(self, lightid, true)];
Expand All @@ -879,6 +880,7 @@ int AttachLightDirect(AActor *self, int _lightid, int type, int color, int radiu
userlight->SetParameter(type == PulseLight? param*TICRATE : param*360.);
userlight->SetSpotInnerAngle(spoti);
userlight->SetSpotOuterAngle(spoto);
userlight->SetLightDefIntensity(intensity);
if (spotp >= -90. && spotp <= 90.)
{
userlight->SetSpotPitch(spotp);
Expand Down Expand Up @@ -908,7 +910,8 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_AttachLight, AttachLightDirect)
PARAM_FLOAT(spoti);
PARAM_FLOAT(spoto);
PARAM_FLOAT(spotp);
ACTION_RETURN_BOOL(AttachLightDirect(self, lightid.GetIndex(), type, color, radius1, radius2, flags, ofs_x, ofs_y, ofs_z, parami, spoti, spoto, spotp));
PARAM_FLOAT(intensity);
ACTION_RETURN_BOOL(AttachLightDirect(self, lightid.GetIndex(), type, color, radius1, radius2, flags, ofs_x, ofs_y, ofs_z, parami, spoti, spoto, spotp, intensity));
}

//==========================================================================
Expand Down
5 changes: 5 additions & 0 deletions src/playsim/a_dynlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FLightDefaults
void SetDontLightOthers(bool on) { if (on) m_lightFlags |= LF_DONTLIGHTOTHERS; else m_lightFlags &= ~LF_DONTLIGHTOTHERS; }
void SetDontLightMap(bool on) { if (on) m_lightFlags |= LF_DONTLIGHTMAP; else m_lightFlags &= ~LF_DONTLIGHTMAP; }
void SetNoShadowmap(bool on) { if (on) m_lightFlags |= LF_NOSHADOWMAP; else m_lightFlags &= ~LF_NOSHADOWMAP; }
void SetLightDefIntensity(double i) { m_LightDefIntensity = i; }
void SetSpot(bool spot) { if (spot) m_lightFlags |= LF_SPOT; else m_lightFlags &= ~LF_SPOT; }
void SetSpotInnerAngle(double angle) { m_spotInnerAngle = DAngle::fromDeg(angle); }
void SetSpotOuterAngle(double angle) { m_spotOuterAngle = DAngle::fromDeg(angle); }
Expand Down Expand Up @@ -128,6 +129,7 @@ class FLightDefaults
DAngle m_spotInnerAngle = DAngle::fromDeg(10.0);
DAngle m_spotOuterAngle = DAngle::fromDeg(25.0);
DAngle m_pitch = nullAngle;
double m_LightDefIntensity = 1.0; // Light over/underbright multiplication for GLDEFS-defined lights

friend FSerializer &Serialize(FSerializer &arc, const char *key, FLightDefaults &value, FLightDefaults *def);
};
Expand Down Expand Up @@ -231,6 +233,7 @@ struct FDynamicLight
int GetBlue() const { return pArgs[LIGHT_BLUE]; }
int GetIntensity() const { return pArgs[LIGHT_INTENSITY]; }
int GetSecondaryIntensity() const { return pArgs[LIGHT_SECONDARY_INTENSITY]; }
double GetLightDefIntensity() const { return lightDefIntensity; }

bool IsSubtractive() const { return !!((*pLightFlags) & LF_SUBTRACTIVE); }
bool IsAdditive() const { return !!((*pLightFlags) & LF_ADDITIVE); }
Expand Down Expand Up @@ -293,6 +296,8 @@ struct FDynamicLight
bool swapped;
bool explicitpitch;

double lightDefIntensity;

FDynamicLightTouchLists touchlists;
};

Expand Down
2 changes: 2 additions & 0 deletions src/r_data/a_dynlightdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FLightDefaults &value,
("spotinner", value.m_spotInnerAngle)
("spotouter", value.m_spotOuterAngle)
("pitch", value.m_pitch)
("lightdefintensity", value.m_LightDefIntensity)
.EndObject();
}
return arc;
Expand Down Expand Up @@ -125,6 +126,7 @@ void FLightDefaults::ApplyProperties(FDynamicLight * light) const
light->m_active = true;
light->lighttype = m_type;
light->specialf1 = m_Param;
light->lightDefIntensity = m_LightDefIntensity;
light->pArgs = m_Args;
light->pLightFlags = &m_lightFlags;
if (m_lightFlags & LF_SPOT)
Expand Down
17 changes: 17 additions & 0 deletions src/r_data/gldefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ static const char *LightTags[]=
"noshadowmap",
"dontlightothers",
"dontlightmap",
"intensity",
nullptr
};

Expand All @@ -226,6 +227,7 @@ enum {
LIGHTTAG_NOSHADOWMAP,
LIGHTTAG_DONTLIGHTOTHERS,
LIGHTTAG_DONTLIGHTMAP,
LIGHTTAG_INTENSITY,
};

//==========================================================================
Expand Down Expand Up @@ -541,6 +543,9 @@ class GLDefsParser
defaults->SetSpotOuterAngle(outerAngle);
}
break;
case LIGHTTAG_INTENSITY:
defaults->SetLightDefIntensity(ParseFloat(sc));
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
Expand Down Expand Up @@ -643,6 +648,9 @@ class GLDefsParser
defaults->SetSpotOuterAngle(outerAngle);
}
break;
case LIGHTTAG_INTENSITY:
defaults->SetLightDefIntensity(ParseFloat(sc));
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
Expand Down Expand Up @@ -748,6 +756,9 @@ class GLDefsParser
defaults->SetSpotOuterAngle(outerAngle);
}
break;
case LIGHTTAG_INTENSITY:
defaults->SetLightDefIntensity(ParseFloat(sc));
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
Expand Down Expand Up @@ -852,6 +863,9 @@ class GLDefsParser
defaults->SetSpotOuterAngle(outerAngle);
}
break;
case LIGHTTAG_INTENSITY:
defaults->SetLightDefIntensity(ParseFloat(sc));
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
Expand Down Expand Up @@ -953,6 +967,9 @@ class GLDefsParser
defaults->SetSpotOuterAngle(outerAngle);
}
break;
case LIGHTTAG_INTENSITY:
defaults->SetLightDefIntensity(ParseFloat(sc));
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
Expand Down
3 changes: 3 additions & 0 deletions src/rendering/hwrenderer/hw_dynlightdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool f
if (light->target && (light->target->renderflags2 & RF2_LIGHTMULTALPHA))
cs *= (float)light->target->Alpha;

// Multiply intensity from GLDEFS
cs *= (float)light->GetLightDefIntensity();

float r = light->GetRed() / 255.0f * cs;
float g = light->GetGreen() / 255.0f * cs;
float b = light->GetBlue() / 255.0f * cs;
Expand Down
5 changes: 5 additions & 0 deletions src/rendering/hwrenderer/scene/hw_spritelight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FSec
lb *= alpha;
}

// Get GLDEFS intensity
lr *= light->GetLightDefIntensity();
lg *= light->GetLightDefIntensity();
lb *= light->GetLightDefIntensity();

if (light->IsSubtractive())
{
float bright = (float)FVector3(lr, lg, lb).Length();
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/actors/actor.zs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ class Actor : Thinker native
action native void A_OverlayTranslation(int layer, name trname);

native bool A_AttachLightDef(Name lightid, Name lightdef);
native bool A_AttachLight(Name lightid, int type, Color lightcolor, int radius1, int radius2, int flags = 0, Vector3 ofs = (0,0,0), double param = 0, double spoti = 10, double spoto = 25, double spotp = 0);
native bool A_AttachLight(Name lightid, int type, Color lightcolor, int radius1, int radius2, int flags = 0, Vector3 ofs = (0,0,0), double param = 0, double spoti = 10, double spoto = 25, double spotp = 0, double intensity = 1.0);
native bool A_RemoveLight(Name lightid);

//================================================
Expand Down