Skip to content

Commit b44f8f0

Browse files
nashmuhandesRicardoLuis0
authored andcommitted
- Add "Intensity" property for dynamic lights in GLDEFS that will multiply the brightness of the light, useful for overbrightening/underbrightening a light.
- Also add an "intensity" parameter for A_AttachLight in ZScript. Note that for any kind of light overbrightening to do anything at all, one of the unclamped LightBlendModes in MAPINFO must be enabled.
1 parent b56d184 commit b44f8f0

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

src/playsim/a_dynlight.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void AttachLight(AActor *self)
113113

114114
light->pSpotInnerAngle = &self->AngleVar(NAME_SpotInnerAngle);
115115
light->pSpotOuterAngle = &self->AngleVar(NAME_SpotOuterAngle);
116+
light->lightDefIntensity = 1.0;
116117
light->pPitch = &self->Angles.Pitch;
117118
light->pLightFlags = (LightFlags*)&self->IntVar(NAME_lightflags);
118119
light->pArgs = self->args;
@@ -863,7 +864,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_AttachLightDef, AttachLightDef)
863864
//
864865
//==========================================================================
865866

866-
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)
867+
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)
867868
{
868869
FName lightid = FName(ENamedName(_lightid));
869870
auto userlight = self->UserLights[FindUserLight(self, lightid, true)];
@@ -879,6 +880,7 @@ int AttachLightDirect(AActor *self, int _lightid, int type, int color, int radiu
879880
userlight->SetParameter(type == PulseLight? param*TICRATE : param*360.);
880881
userlight->SetSpotInnerAngle(spoti);
881882
userlight->SetSpotOuterAngle(spoto);
883+
userlight->SetLightDefIntensity(intensity);
882884
if (spotp >= -90. && spotp <= 90.)
883885
{
884886
userlight->SetSpotPitch(spotp);
@@ -908,7 +910,8 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_AttachLight, AttachLightDirect)
908910
PARAM_FLOAT(spoti);
909911
PARAM_FLOAT(spoto);
910912
PARAM_FLOAT(spotp);
911-
ACTION_RETURN_BOOL(AttachLightDirect(self, lightid.GetIndex(), type, color, radius1, radius2, flags, ofs_x, ofs_y, ofs_z, parami, spoti, spoto, spotp));
913+
PARAM_FLOAT(intensity);
914+
ACTION_RETURN_BOOL(AttachLightDirect(self, lightid.GetIndex(), type, color, radius1, radius2, flags, ofs_x, ofs_y, ofs_z, parami, spoti, spoto, spotp, intensity));
912915
}
913916

914917
//==========================================================================

src/playsim/a_dynlight.h

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class FLightDefaults
7777
void SetDontLightOthers(bool on) { if (on) m_lightFlags |= LF_DONTLIGHTOTHERS; else m_lightFlags &= ~LF_DONTLIGHTOTHERS; }
7878
void SetDontLightMap(bool on) { if (on) m_lightFlags |= LF_DONTLIGHTMAP; else m_lightFlags &= ~LF_DONTLIGHTMAP; }
7979
void SetNoShadowmap(bool on) { if (on) m_lightFlags |= LF_NOSHADOWMAP; else m_lightFlags &= ~LF_NOSHADOWMAP; }
80+
void SetLightDefIntensity(double i) { m_LightDefIntensity = i; }
8081
void SetSpot(bool spot) { if (spot) m_lightFlags |= LF_SPOT; else m_lightFlags &= ~LF_SPOT; }
8182
void SetSpotInnerAngle(double angle) { m_spotInnerAngle = DAngle::fromDeg(angle); }
8283
void SetSpotOuterAngle(double angle) { m_spotOuterAngle = DAngle::fromDeg(angle); }
@@ -128,6 +129,7 @@ class FLightDefaults
128129
DAngle m_spotInnerAngle = DAngle::fromDeg(10.0);
129130
DAngle m_spotOuterAngle = DAngle::fromDeg(25.0);
130131
DAngle m_pitch = nullAngle;
132+
double m_LightDefIntensity = 1.0; // Light over/underbright multiplication for GLDEFS-defined lights
131133

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

235238
bool IsSubtractive() const { return !!((*pLightFlags) & LF_SUBTRACTIVE); }
236239
bool IsAdditive() const { return !!((*pLightFlags) & LF_ADDITIVE); }
@@ -293,6 +296,8 @@ struct FDynamicLight
293296
bool swapped;
294297
bool explicitpitch;
295298

299+
double lightDefIntensity;
300+
296301
FDynamicLightTouchLists touchlists;
297302
};
298303

src/r_data/a_dynlightdata.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FLightDefaults &value,
8181
("spotinner", value.m_spotInnerAngle)
8282
("spotouter", value.m_spotOuterAngle)
8383
("pitch", value.m_pitch)
84+
("lightdefintensity", value.m_LightDefIntensity)
8485
.EndObject();
8586
}
8687
return arc;
@@ -125,6 +126,7 @@ void FLightDefaults::ApplyProperties(FDynamicLight * light) const
125126
light->m_active = true;
126127
light->lighttype = m_type;
127128
light->specialf1 = m_Param;
129+
light->lightDefIntensity = m_LightDefIntensity;
128130
light->pArgs = m_Args;
129131
light->pLightFlags = &m_lightFlags;
130132
if (m_lightFlags & LF_SPOT)

src/r_data/gldefs.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static const char *LightTags[]=
200200
"noshadowmap",
201201
"dontlightothers",
202202
"dontlightmap",
203+
"intensity",
203204
nullptr
204205
};
205206

@@ -226,6 +227,7 @@ enum {
226227
LIGHTTAG_NOSHADOWMAP,
227228
LIGHTTAG_DONTLIGHTOTHERS,
228229
LIGHTTAG_DONTLIGHTMAP,
230+
LIGHTTAG_INTENSITY,
229231
};
230232

231233
//==========================================================================
@@ -541,6 +543,9 @@ class GLDefsParser
541543
defaults->SetSpotOuterAngle(outerAngle);
542544
}
543545
break;
546+
case LIGHTTAG_INTENSITY:
547+
defaults->SetLightDefIntensity(ParseFloat(sc));
548+
break;
544549
default:
545550
sc.ScriptError("Unknown tag: %s\n", sc.String);
546551
}
@@ -643,6 +648,9 @@ class GLDefsParser
643648
defaults->SetSpotOuterAngle(outerAngle);
644649
}
645650
break;
651+
case LIGHTTAG_INTENSITY:
652+
defaults->SetLightDefIntensity(ParseFloat(sc));
653+
break;
646654
default:
647655
sc.ScriptError("Unknown tag: %s\n", sc.String);
648656
}
@@ -748,6 +756,9 @@ class GLDefsParser
748756
defaults->SetSpotOuterAngle(outerAngle);
749757
}
750758
break;
759+
case LIGHTTAG_INTENSITY:
760+
defaults->SetLightDefIntensity(ParseFloat(sc));
761+
break;
751762
default:
752763
sc.ScriptError("Unknown tag: %s\n", sc.String);
753764
}
@@ -852,6 +863,9 @@ class GLDefsParser
852863
defaults->SetSpotOuterAngle(outerAngle);
853864
}
854865
break;
866+
case LIGHTTAG_INTENSITY:
867+
defaults->SetLightDefIntensity(ParseFloat(sc));
868+
break;
855869
default:
856870
sc.ScriptError("Unknown tag: %s\n", sc.String);
857871
}
@@ -953,6 +967,9 @@ class GLDefsParser
953967
defaults->SetSpotOuterAngle(outerAngle);
954968
}
955969
break;
970+
case LIGHTTAG_INTENSITY:
971+
defaults->SetLightDefIntensity(ParseFloat(sc));
972+
break;
956973
default:
957974
sc.ScriptError("Unknown tag: %s\n", sc.String);
958975
}

src/rendering/hwrenderer/hw_dynlightdata.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool f
9595
if (light->target && (light->target->renderflags2 & RF2_LIGHTMULTALPHA))
9696
cs *= (float)light->target->Alpha;
9797

98+
// Multiply intensity from GLDEFS
99+
cs *= (float)light->GetLightDefIntensity();
100+
98101
float r = light->GetRed() / 255.0f * cs;
99102
float g = light->GetGreen() / 255.0f * cs;
100103
float b = light->GetBlue() / 255.0f * cs;

src/rendering/hwrenderer/scene/hw_spritelight.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FSec
194194
lb *= alpha;
195195
}
196196

197+
// Get GLDEFS intensity
198+
lr *= light->GetLightDefIntensity();
199+
lg *= light->GetLightDefIntensity();
200+
lb *= light->GetLightDefIntensity();
201+
197202
if (light->IsSubtractive())
198203
{
199204
float bright = (float)FVector3(lr, lg, lb).Length();

wadsrc/static/zscript/actors/actor.zs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ class Actor : Thinker native
13561356
action native void A_OverlayTranslation(int layer, name trname);
13571357

13581358
native bool A_AttachLightDef(Name lightid, Name lightdef);
1359-
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);
1359+
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);
13601360
native bool A_RemoveLight(Name lightid);
13611361

13621362
//================================================

0 commit comments

Comments
 (0)