meow lights

This commit is contained in:
4sval 2022-11-27 22:19:39 +01:00
parent 2173ac01fb
commit 9926d0de7c
5 changed files with 28 additions and 22 deletions

@ -1 +1 @@
Subproject commit f15b00003f4eb304ee3b85944c2ae93a27f1208b
Subproject commit bd6b84eac5dc4c852afe330be2c286dd4b48d626

View File

@ -30,10 +30,10 @@ public abstract class Light : IDisposable
public readonly Vector4 Color;
public readonly float Intensity;
public Light(Texture icon, UObject light, FVector position)
public Light(Texture icon, UObject parent, UObject light, FVector position)
{
var p = light.GetOrDefault("RelativeLocation", FVector.ZeroVector);
var r = light.GetOrDefault("RelativeRotation", FRotator.ZeroRotator);
var p = light.GetOrDefault("RelativeLocation", parent.GetOrDefault("RelativeLocation", FVector.ZeroVector));
var r = light.GetOrDefault("RelativeRotation", parent.GetOrDefault("RelativeRotation", FRotator.ZeroRotator));
Transform = Transform.Identity;
Transform.Scale = new FVector(0.25f);
@ -41,8 +41,8 @@ public abstract class Light : IDisposable
Icon = icon;
Color = light.GetOrDefault("LightColor", new FColor(0xFF, 0xFF, 0xFF, 0xFF));
Intensity = light.GetOrDefault("Intensity", 1.0f);
Color = light.GetOrDefault("LightColor", parent.GetOrDefault("LightColor", new FColor(0xFF, 0xFF, 0xFF, 0xFF)));
Intensity = light.GetOrDefault("Intensity", parent.GetOrDefault("Intensity", 1.0f));
}
public void SetupInstances()

View File

@ -9,11 +9,14 @@ public class PointLight : Light
public readonly float Linear;
public readonly float Quadratic;
public PointLight(Texture icon, UObject point, FVector position) : base(icon, point, position)
public PointLight(Texture icon, UObject parent, UObject point, FVector position) : base(icon, parent, point, position)
{
var radius = point.GetOrDefault("AttenuationRadius", 0.0f) * Constants.SCALE_DOWN_RATIO;
if (!point.TryGetValue(out float radius, "AttenuationRadius", "SourceRadius"))
radius = 1.0f;
radius *= Constants.SCALE_DOWN_RATIO;
Linear = 4.5f / radius;
Quadratic = 75.0f / MathF.Pow(radius, 2);
Quadratic = 75.0f / MathF.Pow(radius, 2.0f);
}
public override void Render(int i, Shader shader)

View File

@ -226,15 +226,15 @@ public class Renderer : IDisposable
private void WorldLight(UObject actor)
{
if (!actor.TryGetValue(out FPackageIndex lightComponent, "LightComponent") ||
lightComponent.Load() is not { } lightObject) return;
Cache.Lights.Add(new PointLight(Cache.Icons["pointlight"], lightObject, FVector.ZeroVector));
// if (!actor.TryGetValue(out FPackageIndex lightComponent, "LightComponent") ||
// lightComponent.Load() is not { } lightObject) return;
//
// Cache.Lights.Add(new PointLight(Cache.Icons["pointlight"], lightObject, FVector.ZeroVector));
}
private void WorldMesh(UObject actor, Transform transform)
{
if (!actor.TryGetValue(out FPackageIndex staticMeshComponent, "StaticMeshComponent", "Mesh") ||
if (!actor.TryGetValue(out FPackageIndex staticMeshComponent, "StaticMeshComponent", "Mesh", "LightMesh") ||
staticMeshComponent.Load() is not { } staticMeshComp) return;
if (!staticMeshComp.TryGetValue(out FPackageIndex staticMesh, "StaticMesh") && actor.Class is UBlueprintGeneratedClass)
@ -242,7 +242,7 @@ public class Renderer : IDisposable
if (actorExp.TryGetValue(out staticMesh, "StaticMesh"))
break;
if (staticMesh?.Load() is not UStaticMesh m)
if (staticMesh?.Load() is not UStaticMesh m || m.Materials.Length < 1)
return;
var guid = m.LightingGuid;
@ -299,14 +299,14 @@ public class Renderer : IDisposable
}
if (actor.TryGetValue(out FPackageIndex treasureLight, "TreasureLight", "PointLight") &&
treasureLight.TryLoad(out var tl) && tl.Template.TryLoad(out tl))
treasureLight.TryLoad(out var tl1) && tl1.Template.TryLoad(out var tl2))
{
Cache.Lights.Add(new PointLight(Cache.Icons["pointlight"], tl, t.Position));
Cache.Lights.Add(new PointLight(Cache.Icons["pointlight"], tl1, tl2, t.Position));
}
if (actor.TryGetValue(out FPackageIndex spotLight, "SpotLight") &&
spotLight.TryLoad(out var sl) && sl.Template.TryLoad(out sl))
spotLight.TryLoad(out var sl1) && sl1.Template.TryLoad(out var sl2))
{
Cache.Lights.Add(new SpotLight(Cache.Icons["spotlight"], sl, t.Position));
Cache.Lights.Add(new SpotLight(Cache.Icons["spotlight"], sl1, sl2, t.Position));
}
}

View File

@ -11,12 +11,15 @@ public class SpotLight : Light
public float Attenuation;
public float ConeAngle;
public SpotLight(Texture icon, UObject spot, FVector position) : base(icon, spot, position)
public SpotLight(Texture icon, UObject parent, UObject spot, FVector position) : base(icon, parent, spot, position)
{
if (!spot.TryGetValue(out Attenuation, "AttenuationRadius", "SourceRadius"))
Attenuation = 1.0f;
Attenuation *= Constants.SCALE_DOWN_RATIO;
Direction = Vector3.Zero;
Attenuation = spot.GetOrDefault("AttenuationRadius", 0.0f) * Constants.SCALE_DOWN_RATIO;
Direction.Y -= Attenuation;
ConeAngle = (spot.GetOrDefault("InnerConeAngle", 50f) + spot.GetOrDefault("OuterConeAngle", 60f)) / 2f;
ConeAngle = (spot.GetOrDefault("InnerConeAngle", 50.0f) + spot.GetOrDefault("OuterConeAngle", 60.0f)) / 2.0f;
ConeAngle = MathF.Cos(Helper.DegreesToRadians(ConeAngle));
}