Merge commit '67e3106254e987f5acb9534e725d4f5c3eaa82b2'

# Conflicts:
#	src/doomdata.h
#	src/namedef.h
#	src/p_udmf.cpp
This commit is contained in:
Christoph Oelckers 2018-01-20 19:07:54 +01:00
commit dbf0a68b02
13 changed files with 358 additions and 15 deletions

View file

@ -372,6 +372,8 @@ struct FMapThing
uint32_t RenderStyle;
int FloatbobPhase;
int friendlyseeblocks;
double SpotInnerAngle = 10;
double SpotOuterAngle = 25;
};

View file

@ -114,6 +114,9 @@ DEFINE_CLASS_PROPERTY(type, S, DynamicLight)
//==========================================================================
IMPLEMENT_CLASS(ADynamicLight, false, false)
DEFINE_FIELD(ADynamicLight, SpotInnerAngle)
DEFINE_FIELD(ADynamicLight, SpotOuterAngle)
static FRandom randLight;
//==========================================================================
@ -134,7 +137,9 @@ void ADynamicLight::Serialize(FSerializer &arc)
arc("lightflags", lightflags, def->lightflags)
("lighttype", lighttype, def->lighttype)
("tickcount", m_tickCount, def->m_tickCount)
("currentradius", m_currentRadius, def->m_currentRadius);
("currentradius", m_currentRadius, def->m_currentRadius)
("spotinnerangle", SpotInnerAngle, def->SpotInnerAngle)
("spotouterangle", SpotOuterAngle, def->SpotOuterAngle);
if (lighttype == PulseLight)
arc("lastupdate", m_lastUpdate, def->m_lastUpdate)

View file

@ -28,7 +28,8 @@ enum LightFlag
LF_DONTLIGHTSELF = 4,
LF_ATTENUATE = 8,
LF_NOSHADOWMAP = 16,
LF_DONTLIGHTACTORS = 32
LF_DONTLIGHTACTORS = 32,
LF_SPOT = 64
};
typedef TFlags<LightFlag> LightFlags;
@ -42,7 +43,7 @@ enum ELightType
FlickerLight,
RandomFlickerLight,
SectorLight,
SpotLight,
DummyLight,
ColorPulseLight,
ColorFlickerLight,
RandomColorFlickerLight
@ -100,6 +101,7 @@ public:
bool IsActive() const { return !(flags2&MF2_DORMANT); }
bool IsSubtractive() { return !!(lightflags & LF_SUBTRACTIVE); }
bool IsAdditive() { return !!(lightflags & LF_ADDITIVE); }
bool IsSpot() { return !!(lightflags & LF_SPOT); }
FState *targetState;
FLightNode * touching_sides;
FLightNode * touching_subsectors;
@ -127,6 +129,7 @@ public:
bool shadowmapped;
int bufferindex;
LightFlags lightflags;
DAngle SpotInnerAngle = 10.0;
DAngle SpotOuterAngle = 25.0;
};

View file

@ -128,6 +128,9 @@ public:
void SetAttenuate(bool on) { m_attenuate = on; }
void SetHalo(bool halo) { m_halo = halo; }
void SetDontLightActors(bool on) { m_dontlightactors = on; }
void SetSpot(bool spot) { m_spot = spot; }
void SetSpotInnerAngle(double angle) { m_spotInnerAngle = angle; }
void SetSpotOuterAngle(double angle) { m_spotOuterAngle = angle; }
void OrderIntensities()
{
@ -151,6 +154,9 @@ protected:
bool m_dontlightself = false;
bool m_dontlightactors = false;
bool m_swapped = false;
bool m_spot = false;
double m_spotInnerAngle = 10.0;
double m_spotOuterAngle = 25.0;
};
TDeletingArray<FLightDefaults *> LightDefaults;
@ -183,6 +189,10 @@ void FLightDefaults::ApplyProperties(ADynamicLight * light) const
if (m_additive) light->lightflags |= LF_ADDITIVE;
if (m_dontlightself) light->lightflags |= LF_DONTLIGHTSELF;
if (m_dontlightactors) light->lightflags |= LF_DONTLIGHTACTORS;
if (m_spot)
light->lightflags |= LF_SPOT;
light->SpotInnerAngle = m_spotInnerAngle;
light->SpotOuterAngle = m_spotOuterAngle;
light->m_tickCount = 0;
if (m_type == PulseLight)
{
@ -233,7 +243,8 @@ static const char *LightTags[]=
"dontlightself",
"attenuate",
"dontlightactors",
NULL
"spot",
nullptr
};
@ -255,6 +266,7 @@ enum {
LIGHTTAG_DONTLIGHTSELF,
LIGHTTAG_ATTENUATE,
LIGHTTAG_DONTLIGHTACTORS,
LIGHTTAG_SPOT
};
@ -395,6 +407,15 @@ static void ParsePointLight(FScanner &sc)
case LIGHTTAG_DONTLIGHTACTORS:
defaults->SetDontLightActors(ParseInt(sc) != 0);
break;
case LIGHTTAG_SPOT:
{
float innerAngle = ParseFloat(sc);
float outerAngle = ParseFloat(sc);
defaults->SetSpot(true);
defaults->SetSpotInnerAngle(innerAngle);
defaults->SetSpotOuterAngle(outerAngle);
}
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
@ -480,6 +501,15 @@ static void ParsePulseLight(FScanner &sc)
case LIGHTTAG_DONTLIGHTACTORS:
defaults->SetDontLightActors(ParseInt(sc) != 0);
break;
case LIGHTTAG_SPOT:
{
float innerAngle = ParseFloat(sc);
float outerAngle = ParseFloat(sc);
defaults->SetSpot(true);
defaults->SetSpotInnerAngle(innerAngle);
defaults->SetSpotOuterAngle(outerAngle);
}
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
@ -567,6 +597,15 @@ void ParseFlickerLight(FScanner &sc)
case LIGHTTAG_DONTLIGHTACTORS:
defaults->SetDontLightActors(ParseInt(sc) != 0);
break;
case LIGHTTAG_SPOT:
{
float innerAngle = ParseFloat(sc);
float outerAngle = ParseFloat(sc);
defaults->SetSpot(true);
defaults->SetSpotInnerAngle(innerAngle);
defaults->SetSpotOuterAngle(outerAngle);
}
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
@ -653,6 +692,15 @@ void ParseFlickerLight2(FScanner &sc)
case LIGHTTAG_DONTLIGHTACTORS:
defaults->SetDontLightActors(ParseInt(sc) != 0);
break;
case LIGHTTAG_SPOT:
{
float innerAngle = ParseFloat(sc);
float outerAngle = ParseFloat(sc);
defaults->SetSpot(true);
defaults->SetSpotInnerAngle(innerAngle);
defaults->SetSpotOuterAngle(outerAngle);
}
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}
@ -736,6 +784,15 @@ static void ParseSectorLight(FScanner &sc)
case LIGHTTAG_DONTLIGHTACTORS:
defaults->SetDontLightActors(ParseInt(sc) != 0);
break;
case LIGHTTAG_SPOT:
{
float innerAngle = ParseFloat(sc);
float outerAngle = ParseFloat(sc);
defaults->SetSpot(true);
defaults->SetSpotInnerAngle(innerAngle);
defaults->SetSpotOuterAngle(outerAngle);
}
break;
default:
sc.ScriptError("Unknown tag: %s\n", sc.String);
}

View file

@ -128,7 +128,26 @@ void gl_AddLightToList(int group, ADynamicLight * light, FDynLightData &ldata)
if (attenuate) shadowIndex = -shadowIndex;
float *data = &ldata.arrays[i][ldata.arrays[i].Reserve(8)];
float lightType = 0.0f;
float spotInnerAngle = 0.0f;
float spotOuterAngle = 0.0f;
float spotDirX = 0.0f;
float spotDirY = 0.0f;
float spotDirZ = 0.0f;
if (light->IsSpot())
{
lightType = 1.0f;
spotInnerAngle = light->SpotInnerAngle.Cos();
spotOuterAngle = light->SpotOuterAngle.Cos();
DAngle negPitch = -light->Angles.Pitch;
double xzLen = negPitch.Cos();
spotDirX = -light->Angles.Yaw.Cos() * xzLen;
spotDirY = -negPitch.Sin();
spotDirZ = -light->Angles.Yaw.Sin() * xzLen;
}
float *data = &ldata.arrays[i][ldata.arrays[i].Reserve(16)];
data[0] = pos.X;
data[1] = pos.Z;
data[2] = pos.Y;
@ -137,5 +156,13 @@ void gl_AddLightToList(int group, ADynamicLight * light, FDynLightData &ldata)
data[5] = g;
data[6] = b;
data[7] = shadowIndex;
data[8] = spotDirX;
data[9] = spotDirY;
data[10] = spotDirZ;
data[11] = lightType;
data[12] = spotInnerAngle;
data[13] = spotOuterAngle;
data[14] = 0.0f; // unused
data[15] = 0.0f; // unused
}

View file

@ -49,6 +49,13 @@
FDynLightData modellightdata;
int modellightindex = -1;
template<class T>
T smoothstep(const T edge0, const T edge1, const T x)
{
auto t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}
//==========================================================================
//
// Sets a single light value from all dynamic lights affecting the specified location
@ -70,6 +77,7 @@ void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t *
if (light->visibletoplayer && !(light->flags2&MF2_DORMANT) && (!(light->lightflags&LF_DONTLIGHTSELF) || light->target != self) && !(light->lightflags&LF_DONTLIGHTACTORS))
{
float dist;
FVector3 L;
// This is a performance critical section of code where we cannot afford to let the compiler decide whether to inline the function or not.
// This will do the calculations explicitly rather than calling one of AActor's utility functions.
@ -80,14 +88,15 @@ void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t *
if (fromgroup == togroup || fromgroup == 0 || togroup == 0) goto direct;
DVector2 offset = Displacements.getOffset(fromgroup, togroup);
dist = FVector3(x - light->X() - offset.X, y - light->Y() - offset.Y, z - light->Z()).LengthSquared();
L = FVector3(x - light->X() - offset.X, y - light->Y() - offset.Y, z - light->Z());
}
else
{
direct:
dist = FVector3(x - light->X(), y - light->Y(), z - light->Z()).LengthSquared();
L = FVector3(x - light->X(), y - light->Y(), z - light->Z());
}
dist = L.LengthSquared();
radius = light->GetRadius();
if (dist < radius * radius)
@ -96,6 +105,18 @@ void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t *
frac = 1.0f - (dist / radius);
if (light->IsSpot())
{
L *= -1.0f / dist;
DAngle negPitch = -light->Angles.Pitch;
double xyLen = negPitch.Cos();
double spotDirX = -light->Angles.Yaw.Cos() * xyLen;
double spotDirY = -light->Angles.Yaw.Sin() * xyLen;
double spotDirZ = -negPitch.Sin();
double cosDir = L.X * spotDirX + L.Y * spotDirY + L.Z * spotDirZ;
frac *= (float)smoothstep(light->SpotOuterAngle.Cos(), light->SpotInnerAngle.Cos(), cosDir);
}
if (frac > 0 && GLRenderer->mShadowMap.ShadowTest(light, { x, y, z }))
{
lr = light->GetRed() / 255.0f;

View file

@ -503,6 +503,8 @@ xx(Scale)
xx(ScaleX)
xx(ScaleY)
xx(FriendlySeeBlocks)
xx(SpotInnerAngle)
xx(SpotOuterAngle)
xx(Floatbobphase)
xx(Floatbobstrength)
xx(Target)

View file

@ -108,6 +108,7 @@
#include "a_morph.h"
#include "events.h"
#include "actorinlines.h"
#include "a_dynlight.h"
// MACROS ------------------------------------------------------------------
@ -6003,6 +6004,8 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
}
}
// spawn it
double sz;
@ -6091,6 +6094,12 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
mobj->fillcolor = (mthing->fillcolor & 0xffffff) | (ColorMatcher.Pick((mthing->fillcolor & 0xff0000) >> 16,
(mthing->fillcolor & 0xff00) >> 8, (mthing->fillcolor & 0xff)) << 24);
if (i->IsDescendantOf(RUNTIME_CLASS(ADynamicLight)))
{
((ADynamicLight*)mobj)->SpotInnerAngle = mthing->SpotInnerAngle;
((ADynamicLight*)mobj)->SpotOuterAngle = mthing->SpotOuterAngle;
}
mobj->CallBeginPlay ();
if (!(mobj->ObjectFlags & OF_EuthanizeMe))
{

View file

@ -799,6 +799,14 @@ public:
th->Scale.X = th->Scale.Y = CheckFloat(key);
break;
case NAME_SpotInnerAngle:
th->SpotInnerAngle = CheckFloat(key);
break;
case NAME_SpotOuterAngle:
th->SpotOuterAngle = CheckFloat(key);
break;
case NAME_FriendlySeeBlocks:
CHECK_N(Zd | Zdt)
th->friendlyseeblocks = CheckInt(key);

View file

@ -494,6 +494,7 @@ static FFlagDef DynLightFlagDefs[] =
DEFINE_FLAG(LF, ATTENUATE, ADynamicLight, lightflags),
DEFINE_FLAG(LF, NOSHADOWMAP, ADynamicLight, lightflags),
DEFINE_FLAG(LF, DONTLIGHTACTORS, ADynamicLight, lightflags),
DEFINE_FLAG(LF, SPOT, ADynamicLight, lightflags),
};
static FFlagDef PowerSpeedFlagDefs[] =

View file

@ -109,6 +109,26 @@ DoomEdNums
9832 = PointLightFlickerAttenuated
9833 = SectorPointLightAttenuated
9834 = PointLightFlickerRandomAttenuated
9840 = SpotLight
9841 = SpotLightPulse
9842 = SpotLightFlicker
9843 = SectorSpotLight
9844 = SpotLightFlickerRandom
9850 = SpotLightAdditive
9851 = SpotLightPulseAdditive
9852 = SpotLightFlickerAdditive
9853 = SectorSpotLightAdditive
9854 = SpotLightFlickerRandomSubtractive
9860 = SpotLightSubtractive
9861 = SpotLightPulseSubtractive
9862 = SpotLightFlickerSubtractive
9863 = SectorSpotLightSubtractive
9864 = SpotLightFlickerRandomSubtractive
9870 = SpotLightAttenuated
9871 = SpotLightPulseAttenuated
9872 = SpotLightFlickerAttenuated
9873 = SectorSpotLightAttenuated
9874 = SpotLightFlickerRandomAttenuated
9982 = SecActEyesAboveC
9983 = SecActEyesBelowC
9988 = CustomSprite

View file

@ -278,6 +278,13 @@ float pointLightAttenuation(vec4 lightpos, float lightcolorA)
}
}
float spotLightAttenuation(vec4 lightpos, vec3 spotdir, float lightCosInnerAngle, float lightCosOuterAngle)
{
vec3 lightDirection = normalize(lightpos.xyz - pixelpos.xyz);
float cosDir = dot(lightDirection, spotdir);
return smoothstep(lightCosOuterAngle, lightCosInnerAngle, cosDir);
}
//===========================================================================
//
// Calculate light
@ -348,23 +355,33 @@ vec4 getLightColor(float fogdist, float fogfactor)
//
// modulated lights
//
for(int i=lightRange.x; i<lightRange.y; i+=2)
for(int i=lightRange.x; i<lightRange.y; i+=4)
{
vec4 lightpos = lights[i];
vec4 lightcolor = lights[i+1];
vec4 lightspot1 = lights[i+2];
vec4 lightspot2 = lights[i+3];
lightcolor.rgb *= pointLightAttenuation(lightpos, lightcolor.a);
float attenuation = pointLightAttenuation(lightpos, lightcolor.a);
if (lightspot1.w == 1.0)
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
lightcolor.rgb *= attenuation;
dynlight.rgb += lightcolor.rgb;
}
//
// subtractive lights
//
for(int i=lightRange.y; i<lightRange.z; i+=2)
for(int i=lightRange.y; i<lightRange.z; i+=4)
{
vec4 lightpos = lights[i];
vec4 lightcolor = lights[i+1];
vec4 lightspot1 = lights[i+2];
vec4 lightspot2 = lights[i+3];
lightcolor.rgb *= pointLightAttenuation(lightpos, lightcolor.a);
float attenuation = pointLightAttenuation(lightpos, lightcolor.a);
if (lightspot1.w == 1.0)
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
lightcolor.rgb *= attenuation;
dynlight.rgb -= lightcolor.rgb;
}
}
@ -467,12 +484,17 @@ void main()
//
// additive lights - these can be done after the alpha test.
//
for(int i=lightRange.z; i<lightRange.w; i+=2)
for(int i=lightRange.z; i<lightRange.w; i+=4)
{
vec4 lightpos = lights[i];
vec4 lightcolor = lights[i+1];
vec4 lightspot1 = lights[i+2];
vec4 lightspot2 = lights[i+3];
lightcolor.rgb *= pointLightAttenuation(lightpos, lightcolor.a);
float attenuation = pointLightAttenuation(lightpos, lightcolor.a);
if (lightspot1.w == 1.0)
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
lightcolor.rgb *= attenuation;
addlight.rgb += lightcolor.rgb;
}
frag.rgb = clamp(frag.rgb + desaturate(addlight).rgb, 0.0, 1.0);

View file

@ -1,5 +1,11 @@
class DynamicLight : Actor native
{
native double SpotInnerAngle;
native double SpotOuterAngle;
property SpotInnerAngle: SpotInnerAngle;
property SpotOuterAngle: SpotOuterAngle;
enum EArgs
{
LIGHT_RED = 0,
@ -17,7 +23,7 @@ class DynamicLight : Actor native
FlickerLight,
RandomFlickerLight,
SectorLight,
SpotLight,
DummyLight,
ColorPulseLight,
ColorFlickerLight,
RandomColorFlickerLight
@ -199,6 +205,166 @@ class PointLightFlickerRandomAttenuated :PointLightFlickerRandom
}
}
class SpotLight : DynamicLight
{
Default
{
DynamicLight.Type "Point";
+DYNAMICLIGHT.SPOT
}
}
class SpotLightPulse : SpotLight
{
Default
{
DynamicLight.Type "Pulse";
}
}
class SpotLightFlicker : SpotLight
{
Default
{
DynamicLight.Type "Flicker";
}
}
class SectorSpotLight : SpotLight
{
Default
{
DynamicLight.Type "Sector";
}
}
class SpotLightFlickerRandom : SpotLight
{
Default
{
DynamicLight.Type "RandomFlicker";
}
}
class SpotLightAdditive : SpotLight
{
Default
{
+DYNAMICLIGHT.ADDITIVE
}
}
class SpotLightPulseAdditive : SpotLightPulse
{
Default
{
+DYNAMICLIGHT.ADDITIVE
}
}
class SpotLightFlickerAdditive : SpotLightFlicker
{
Default
{
+DYNAMICLIGHT.ADDITIVE
}
}
class SectorSpotLightAdditive : SectorSpotLight
{
Default
{
+DYNAMICLIGHT.ADDITIVE
}
}
class SpotLightFlickerRandomAdditive : SpotLightFlickerRandom
{
Default
{
+DYNAMICLIGHT.ADDITIVE
}
}
class SpotLightSubtractive : SpotLight
{
Default
{
+DYNAMICLIGHT.SUBTRACTIVE
}
}
class SpotLightPulseSubtractive : SpotLightPulse
{
Default
{
+DYNAMICLIGHT.SUBTRACTIVE
}
}
class SpotLightFlickerSubtractive : SpotLightFlicker
{
Default
{
+DYNAMICLIGHT.SUBTRACTIVE
}
}
class SectorSpotLightSubtractive : SectorSpotLight
{
Default
{
+DYNAMICLIGHT.SUBTRACTIVE
}
}
class SpotLightFlickerRandomSubtractive : SpotLightFlickerRandom
{
Default
{
+DYNAMICLIGHT.SUBTRACTIVE
}
}
class SpotLightAttenuated : SpotLight
{
Default
{
+DYNAMICLIGHT.ATTENUATE
}
}
class SpotLightPulseAttenuated : SpotLightPulse
{
Default
{
+DYNAMICLIGHT.ATTENUATE
}
}
class SpotLightFlickerAttenuated : SpotLightFlicker
{
Default
{
+DYNAMICLIGHT.ATTENUATE
}
}
class SectorSpotLightAttenuated : SectorSpotLight
{
Default
{
+DYNAMICLIGHT.ATTENUATE
}
}
class SpotLightFlickerRandomAttenuated : SpotLightFlickerRandom
{
Default
{
+DYNAMICLIGHT.ATTENUATE
}
}
class VavoomLight : DynamicLight
{