mirror of
https://github.com/4sval/FModel.git
synced 2026-03-24 18:54:42 -05:00
well, I guess spots always points to the ground
This commit is contained in:
parent
8b072e39fc
commit
e7ff5c41a6
|
|
@ -52,9 +52,14 @@ struct Light {
|
|||
vec3 Position;
|
||||
float Intensity;
|
||||
|
||||
float Constant;
|
||||
vec3 Direction;
|
||||
float ConeAngle;
|
||||
float Attenuation;
|
||||
|
||||
float Linear;
|
||||
float Quadratic;
|
||||
|
||||
int Type; // 0 Point, 1 Spot
|
||||
};
|
||||
|
||||
uniform Parameters uParameters;
|
||||
|
|
@ -192,21 +197,24 @@ void main()
|
|||
vec3 lights = vec3(uNumLights > 0 ? 0 : 1);
|
||||
for (int i = 0; i < uNumLights; i++)
|
||||
{
|
||||
float distance = length(uLights[i].Position - fPos);
|
||||
float attenuation = 1.0 / (1.0 + uLights[i].Linear * distance + uLights[i].Quadratic * (distance * distance));
|
||||
float distanceToLight = length(uLights[i].Position - fPos);
|
||||
|
||||
float attenuation = 0.0;
|
||||
if (uLights[i].Type == 0)
|
||||
{
|
||||
attenuation = 1.0 / (1.0 + uLights[i].Linear * distanceToLight + uLights[i].Quadratic * pow(distanceToLight, 2));
|
||||
}
|
||||
else if (uLights[i].Type == 1)
|
||||
{
|
||||
float theta = dot(normalize(uLights[i].Position - fPos), normalize(-uLights[i].Direction));
|
||||
if(theta > uLights[i].ConeAngle)
|
||||
{
|
||||
attenuation = 1.0 / (1.0 + uLights[i].Attenuation * pow(distanceToLight, 2));
|
||||
}
|
||||
}
|
||||
|
||||
vec3 intensity = uLights[i].Color.rgb * uLights[i].Intensity;
|
||||
lights += result * intensity * attenuation;
|
||||
|
||||
// float attenuation = 0.0;
|
||||
// float theta = dot(normalize(uLights[i].Position - fPos), normalize(-uLights[i].Direction));
|
||||
// if(theta > uLights[i].ConeAngle)
|
||||
// {
|
||||
// float distanceToLight = length(uLights[i].Position - fPos);
|
||||
// attenuation = 1.0 / (1.0 + uLights[i].Attenuation * pow(distanceToLight, 2));
|
||||
// }
|
||||
//
|
||||
// vec3 intensity = uLights[i].Color.rgb * uLights[i].Intensity;
|
||||
// lights += result * intensity * attenuation;
|
||||
}
|
||||
result *= lights; // use * to darken the scene, + to lighten it
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using CUE4Parse.UE4.Assets.Exports;
|
||||
using CUE4Parse.UE4.Objects.Core.Math;
|
||||
|
|
@ -29,8 +29,6 @@ public abstract class Light : IDisposable
|
|||
|
||||
public readonly Vector4 Color;
|
||||
public readonly float Intensity;
|
||||
public readonly float Linear;
|
||||
public readonly float Quadratic;
|
||||
|
||||
public Light(Texture icon, UObject light, FVector position)
|
||||
{
|
||||
|
|
@ -45,10 +43,6 @@ public abstract class Light : IDisposable
|
|||
|
||||
Color = light.GetOrDefault("LightColor", new FColor(0xFF, 0xFF, 0xFF, 0xFF));
|
||||
Intensity = light.GetOrDefault("Intensity", 1.0f);
|
||||
|
||||
var radius = light.GetOrDefault("AttenuationRadius", 0.0f) * Constants.SCALE_DOWN_RATIO;
|
||||
Linear = 4.5f / radius;
|
||||
Quadratic = 75.0f / MathF.Pow(radius, 2);
|
||||
}
|
||||
|
||||
public void SetupInstances()
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
using CUE4Parse.UE4.Assets.Exports;
|
||||
using System;
|
||||
using CUE4Parse.UE4.Assets.Exports;
|
||||
using CUE4Parse.UE4.Objects.Core.Math;
|
||||
|
||||
namespace FModel.Views.Snooper;
|
||||
|
||||
public class PointLight : Light
|
||||
{
|
||||
public readonly float Linear;
|
||||
public readonly float Quadratic;
|
||||
|
||||
public PointLight(Texture icon, UObject point, FVector position) : base(icon, point, position)
|
||||
{
|
||||
|
||||
var radius = point.GetOrDefault("AttenuationRadius", 0.0f) * Constants.SCALE_DOWN_RATIO;
|
||||
Linear = 4.5f / radius;
|
||||
Quadratic = 75.0f / MathF.Pow(radius, 2);
|
||||
}
|
||||
|
||||
public override void Render(int i, Shader shader)
|
||||
|
|
@ -17,5 +23,7 @@ public class PointLight : Light
|
|||
shader.SetUniform($"uLights[{i}].Intensity", Intensity);
|
||||
shader.SetUniform($"uLights[{i}].Linear", Linear);
|
||||
shader.SetUniform($"uLights[{i}].Quadratic", Quadratic);
|
||||
|
||||
shader.SetUniform($"uLights[{i}].Type", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using CUE4Parse.UE4.Objects.Core.Math;
|
|||
|
||||
namespace FModel.Views.Snooper;
|
||||
|
||||
public class SpotLight : PointLight
|
||||
public class SpotLight : Light
|
||||
{
|
||||
public Vector3 Direction; // ???
|
||||
public float Attenuation;
|
||||
|
|
@ -13,20 +13,22 @@ public class SpotLight : PointLight
|
|||
|
||||
public SpotLight(Texture icon, UObject spot, FVector position) : base(icon, spot, position)
|
||||
{
|
||||
// var p = spot.GetOrDefault("RelativeLocation", FVector.ZeroVector);
|
||||
// var r = spot.GetOrDefault("RelativeRotation", FRotator.ZeroRotator);
|
||||
|
||||
// Direction = position + r.UnrotateVector(p.ToMapVector()) * 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 = MathF.Cos(Helper.DegreesToRadians(ConeAngle));
|
||||
}
|
||||
|
||||
public new void Render(int i, Shader shader)
|
||||
public override void Render(int i, Shader shader)
|
||||
{
|
||||
base.Render(i, shader);
|
||||
// shader.SetUniform($"uLights[{i}].Direction", Direction);
|
||||
// shader.SetUniform($"uLights[{i}].Attenuation", Attenuation);
|
||||
// shader.SetUniform($"uLights[{i}].ConeAngle", ConeAngle);
|
||||
shader.SetUniform($"uLights[{i}].Color", Color);
|
||||
shader.SetUniform($"uLights[{i}].Position", Transform.Position);
|
||||
shader.SetUniform($"uLights[{i}].Intensity", Intensity);
|
||||
shader.SetUniform($"uLights[{i}].Direction", Direction);
|
||||
shader.SetUniform($"uLights[{i}].Attenuation", Attenuation);
|
||||
shader.SetUniform($"uLights[{i}].ConeAngle", ConeAngle);
|
||||
|
||||
shader.SetUniform($"uLights[{i}].Type", 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user