_wipshit
This commit is contained in:
@@ -49,7 +49,7 @@ namespace Game
|
||||
public string mapPath;// = @"C:\dev\Goake\maps\aerowalk\aerowalk.map";
|
||||
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\problematic.map";
|
||||
|
||||
public bool importLights = false;
|
||||
public bool importLights = true;
|
||||
private bool generateSdf = true;
|
||||
private bool childModelSdf = true;
|
||||
|
||||
@@ -116,6 +116,19 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
public bool LoadCollidersOnly
|
||||
{
|
||||
get => collidersOnly;
|
||||
set
|
||||
{
|
||||
if (collidersOnly == value)
|
||||
return;
|
||||
collidersOnly = value;
|
||||
dirtyLights = true;
|
||||
dirtyMap = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void QuickHull(Float3[] points, out Float3[] outVertices)
|
||||
{
|
||||
@@ -333,6 +346,7 @@ namespace Game
|
||||
private bool sceneLighting = false;
|
||||
private bool sceneShadows = false;
|
||||
private bool staticBatching = false;
|
||||
private bool collidersOnly = false;
|
||||
private bool globalIllumination = false;
|
||||
public override void OnUpdate()
|
||||
{
|
||||
@@ -457,6 +471,9 @@ namespace Game
|
||||
|
||||
private void LoadMap(bool forceLoad)
|
||||
{
|
||||
if (string.IsNullOrEmpty(mapPath))
|
||||
return;
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
|
||||
@@ -492,9 +509,10 @@ namespace Game
|
||||
// FlaxEngine.Debug.Log("No WorldSpawn, loading map");
|
||||
|
||||
bool oneMesh = false;
|
||||
bool useStaticBatching = StaticBatching;
|
||||
bool useStaticBatching = StaticBatching && !LoadCollidersOnly;
|
||||
bool convexMesh = true;
|
||||
|
||||
|
||||
FlaxEngine.Debug.Log("Loading map, static batching: " + useStaticBatching);
|
||||
{
|
||||
string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials");
|
||||
@@ -743,14 +761,24 @@ namespace Game
|
||||
brushIndex = 0;
|
||||
foreach (BrushGeometry geom in brushGeometries)
|
||||
{
|
||||
StaticModel childModel = worldSpawnActor.AddChild<StaticModel>();
|
||||
childModel.Name = "Brush_" + brushIndex;
|
||||
childModel.Model = geom.model;
|
||||
childModel.Position = geom.offset;
|
||||
//childModel.DrawModes = DrawPass.None;
|
||||
Actor childModel;
|
||||
if (LoadCollidersOnly)
|
||||
{
|
||||
childModel = worldSpawnActor.AddChild<EmptyActor>();
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticModel staticModel = worldSpawnActor.AddChild<StaticModel>();
|
||||
staticModel.Model = geom.model;
|
||||
//staticModel.DrawModes = DrawPass.None;
|
||||
|
||||
for (int i = 0; i < geom.meshes.Length; i++)
|
||||
childModel.SetMaterial(i, geom.meshes[i].material);
|
||||
for (int i = 0; i < geom.meshes.Length; i++)
|
||||
staticModel.SetMaterial(i, geom.meshes[i].material);
|
||||
|
||||
childModel = staticModel;
|
||||
}
|
||||
childModel.Name = "Brush_" + brushIndex;
|
||||
childModel.Position = geom.offset;
|
||||
|
||||
BrushScript brushScript = childModel.AddScript<BrushScript>();
|
||||
|
||||
@@ -760,16 +788,17 @@ namespace Game
|
||||
|
||||
bool isClipMaterial = false;
|
||||
bool isMissingMaterial = false;
|
||||
if (geom.meshes.Length == 1)
|
||||
if (geom.meshes.Length == 1 && !LoadCollidersOnly)
|
||||
{
|
||||
MaterialParameter info = geom.meshes[0].material.GetParameter("IsClipMaterial");
|
||||
if (info != null && (bool)info.Value)
|
||||
{
|
||||
var entries = childModel.Entries;
|
||||
StaticModel staticModel = childModel.As<StaticModel>();
|
||||
var entries = staticModel.Entries;
|
||||
entries[0].Visible = false;
|
||||
entries[0].ShadowsMode = ShadowsCastingMode.None;
|
||||
entries[0].ReceiveDecals = false;
|
||||
childModel.Entries = entries;
|
||||
staticModel.Entries = entries;
|
||||
isClipMaterial = true;
|
||||
}
|
||||
|
||||
@@ -777,14 +806,17 @@ namespace Game
|
||||
isMissingMaterial = true;
|
||||
}
|
||||
|
||||
/*{
|
||||
var entries = childModel.Entries;
|
||||
/*
|
||||
if (!LoadCollidersOnly)
|
||||
{
|
||||
StaticModel staticModel = childModel.As<StaticModel>();
|
||||
var entries = staticModel.Entries;
|
||||
for (int i=0; i < entries.Length; i++)
|
||||
entries[i].Visible = false;
|
||||
childModel.Entries = entries;
|
||||
staticModel.Entries = entries;
|
||||
}*/
|
||||
|
||||
if (!isClipMaterial && !isMissingMaterial)
|
||||
if (!isClipMaterial && !isMissingMaterial && !LoadCollidersOnly)
|
||||
sdfModels.Add(geom.model);
|
||||
|
||||
CollisionData collisionData = Content.CreateVirtualAsset<CollisionData>();
|
||||
@@ -1286,11 +1318,9 @@ namespace Game
|
||||
|
||||
private void ParseLight(MapEntity entity, ref int lightIndex)
|
||||
{
|
||||
LightWithShadow light;
|
||||
Actor actor;
|
||||
Float3? lightTargetPosition = null;
|
||||
|
||||
|
||||
|
||||
if (entity.properties.TryGetValue("target", out string targetName))
|
||||
{
|
||||
var target = root.entities.FirstOrDefault(x =>
|
||||
@@ -1300,148 +1330,155 @@ namespace Game
|
||||
lightTargetPosition = ParseOrigin(target.properties["origin"]);
|
||||
}
|
||||
|
||||
if (!lightTargetPosition.HasValue)
|
||||
light = worldSpawnActor.AddChild<PointLight>();
|
||||
if (LoadCollidersOnly)
|
||||
actor = worldSpawnActor.AddChild<EmptyActor>();
|
||||
else if (!lightTargetPosition.HasValue)
|
||||
actor = worldSpawnActor.AddChild<PointLight>();
|
||||
else
|
||||
light = worldSpawnActor.AddChild<SpotLight>();
|
||||
actor = worldSpawnActor.AddChild<SpotLight>();
|
||||
|
||||
if (!lightTargetPosition.HasValue)
|
||||
actor.Name = "Light_" + lightIndex;
|
||||
else
|
||||
actor.Name = "SpotLight_" + lightIndex;
|
||||
|
||||
//Console.Print("light");
|
||||
//PointLight light = worldSpawnActor.AddChild<PointLight>();
|
||||
//LightWithShadow light = new PointLight();
|
||||
var pointLight = light as PointLight;
|
||||
var spotLight = light as SpotLight;
|
||||
//var light = actor as LightWithShadow;
|
||||
|
||||
if (spotLight != null)
|
||||
light.Name = "SpotLight_" + lightIndex;
|
||||
else
|
||||
light.Name = "Light_" + lightIndex;
|
||||
light.IsActive = sceneLighting;
|
||||
light.LocalPosition = ParseOrigin(entity.properties["origin"]);
|
||||
actor.IsActive = sceneLighting;
|
||||
actor.LocalPosition = ParseOrigin(entity.properties["origin"]);
|
||||
actor.Layer = 1;
|
||||
|
||||
if (lightTargetPosition.HasValue)
|
||||
light.Orientation = Quaternion.LookAt(light.LocalPosition, lightTargetPosition.Value);
|
||||
actor.Orientation = Quaternion.LookAt(actor.LocalPosition, lightTargetPosition.Value);
|
||||
|
||||
if (entity.properties.TryGetValue("_color", out string colorStr))
|
||||
light.Color = ParseColor(colorStr);
|
||||
|
||||
float lightamm = 300f;
|
||||
if (entity.properties.TryGetValue("light", out string lightStr))
|
||||
lightamm = float.Parse(lightStr);
|
||||
|
||||
float radamm = 64f;
|
||||
if (entity.properties.TryGetValue("radius", out string radStr))
|
||||
radamm = float.Parse(radStr);
|
||||
|
||||
bool castShadows = true;
|
||||
if (entity.properties.TryGetValue("castshadows", out string castShadowsStr))
|
||||
castShadows = int.Parse(castShadowsStr) != 0;
|
||||
|
||||
|
||||
light.Layer = 1;
|
||||
if (pointLight != null)
|
||||
if (actor is LightWithShadow light)
|
||||
{
|
||||
pointLight.UseInverseSquaredFalloff = false;
|
||||
pointLight.FallOffExponent = 8;
|
||||
pointLight.ShadowsStrength = sceneShadows && castShadows ? 1.0f : 0.0f;
|
||||
}
|
||||
if (spotLight != null)
|
||||
{
|
||||
spotLight.UseInverseSquaredFalloff = false;
|
||||
spotLight.FallOffExponent = 8;
|
||||
spotLight.ShadowsStrength = sceneShadows && castShadows ? 1.0f : 0.0f;
|
||||
spotLight.InnerConeAngle = 65f;
|
||||
spotLight.OuterConeAngle = 80f;
|
||||
}
|
||||
var pointLight = light as PointLight;
|
||||
var spotLight = light as SpotLight;
|
||||
|
||||
light.ShadowsDistance = 500f;
|
||||
light.ShadowsDepthBias = 0.027f;//0.005f;
|
||||
if (entity.properties.TryGetValue("_color", out string colorStr))
|
||||
light.Color = ParseColor(colorStr);
|
||||
|
||||
int preset = 3;
|
||||
if (preset == 0) // most accurate?, huge radius and low performance
|
||||
{
|
||||
light.Brightness = lightamm / 93f;
|
||||
float lightamm = 300f;
|
||||
if (entity.properties.TryGetValue("light", out string lightStr))
|
||||
lightamm = float.Parse(lightStr);
|
||||
|
||||
light.ShadowsDepthBias = 0.0565f;
|
||||
float radamm = 64f;
|
||||
if (entity.properties.TryGetValue("radius", out string radStr))
|
||||
radamm = float.Parse(radStr);
|
||||
|
||||
light.Brightness *= 0.7837f;
|
||||
bool castShadows = true;
|
||||
if (entity.properties.TryGetValue("castshadows", out string castShadowsStr))
|
||||
castShadows = int.Parse(castShadowsStr) != 0;
|
||||
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.Radius = radamm * 12.5f;
|
||||
pointLight.FallOffExponent = 3.33f;
|
||||
pointLight.Radius *= 0.83375f;
|
||||
pointLight.UseInverseSquaredFalloff = false;
|
||||
pointLight.FallOffExponent = 8;
|
||||
pointLight.ShadowsStrength = sceneShadows && castShadows ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
var hsv = light.Color.ToHSV();
|
||||
hsv.Y *= 0.8f;
|
||||
light.Color = Color.FromHSV(hsv);
|
||||
}
|
||||
else if (preset == 1) //
|
||||
{
|
||||
if (pointLight != null)
|
||||
if (spotLight != null)
|
||||
{
|
||||
pointLight.Radius = 250f;
|
||||
pointLight.FallOffExponent = 2f;
|
||||
spotLight.UseInverseSquaredFalloff = false;
|
||||
spotLight.FallOffExponent = 8;
|
||||
spotLight.ShadowsStrength = sceneShadows && castShadows ? 1.0f : 0.0f;
|
||||
spotLight.InnerConeAngle = 65f;
|
||||
spotLight.OuterConeAngle = 80f;
|
||||
}
|
||||
|
||||
light.Brightness = (lightamm / 128f) * 1.25f;
|
||||
}
|
||||
else if (preset == 2)
|
||||
{
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.Radius = 200f;
|
||||
pointLight.FallOffExponent = 2f;
|
||||
}
|
||||
|
||||
light.Brightness = (lightamm / 128f) * 1.6f;
|
||||
}
|
||||
else //if (preset == 3)
|
||||
{
|
||||
bool inverse = false;
|
||||
float finalRadius = radamm * LightRadiusMultiplier;
|
||||
|
||||
|
||||
light.Brightness = (lightamm / 128f) * BrightnessMultiplier;
|
||||
|
||||
light.ShadowsNormalOffsetScale = 10f;
|
||||
|
||||
light.ShadowsFadeDistance = 100f; // for debugging
|
||||
light.ShadowsDistance = 500f;
|
||||
light.ShadowsDepthBias = 0.027f;//0.005f;
|
||||
|
||||
var hsv = light.Color.ToHSV();
|
||||
hsv.Y *= SaturationMultiplier;
|
||||
light.Color = Color.FromHSV(hsv);
|
||||
|
||||
light.IndirectLightingIntensity = IndirectLightMultiplier;
|
||||
|
||||
light.ShadowsDepthBias = 0.0565f;
|
||||
// if low quality shadows
|
||||
//light.ShadowsDepthBias = 0.2492f;
|
||||
|
||||
if (spotLight != null)
|
||||
int preset = 3;
|
||||
if (preset == 0) // most accurate?, huge radius and low performance
|
||||
{
|
||||
// huge aliasing with spot lights for some reason?
|
||||
light.ShadowsDepthBias = 0.7f;
|
||||
light.Brightness = lightamm / 93f;
|
||||
|
||||
light.ShadowsDepthBias = 0.0565f;
|
||||
|
||||
light.Brightness *= 0.7837f;
|
||||
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.Radius = radamm * 12.5f;
|
||||
pointLight.FallOffExponent = 3.33f;
|
||||
pointLight.Radius *= 0.83375f;
|
||||
}
|
||||
|
||||
var hsv = light.Color.ToHSV();
|
||||
hsv.Y *= 0.8f;
|
||||
light.Color = Color.FromHSV(hsv);
|
||||
}
|
||||
else if (preset == 1) //
|
||||
{
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.Radius = 250f;
|
||||
pointLight.FallOffExponent = 2f;
|
||||
}
|
||||
|
||||
if (inverse)
|
||||
{
|
||||
light.Brightness *= 20000f;
|
||||
finalRadius *= 0.7f;
|
||||
light.Brightness = (lightamm / 128f) * 1.25f;
|
||||
}
|
||||
else if (preset == 2)
|
||||
{
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.Radius = 200f;
|
||||
pointLight.FallOffExponent = 2f;
|
||||
}
|
||||
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.UseInverseSquaredFalloff = inverse;
|
||||
pointLight.Radius = finalRadius;
|
||||
pointLight.FallOffExponent = FallOffExponent;
|
||||
light.Brightness = (lightamm / 128f) * 1.6f;
|
||||
}
|
||||
if (spotLight != null)
|
||||
else //if (preset == 3)
|
||||
{
|
||||
spotLight.UseInverseSquaredFalloff = inverse;
|
||||
spotLight.Radius = finalRadius;
|
||||
spotLight.FallOffExponent = FallOffExponent;
|
||||
bool inverse = false;
|
||||
float finalRadius = radamm * LightRadiusMultiplier;
|
||||
|
||||
|
||||
light.Brightness = (lightamm / 128f) * BrightnessMultiplier;
|
||||
|
||||
light.ShadowsNormalOffsetScale = 10f;
|
||||
|
||||
light.ShadowsFadeDistance = 100f; // for debugging
|
||||
light.ShadowsDistance = 500f;
|
||||
|
||||
var hsv = light.Color.ToHSV();
|
||||
hsv.Y *= SaturationMultiplier;
|
||||
light.Color = Color.FromHSV(hsv);
|
||||
|
||||
light.IndirectLightingIntensity = IndirectLightMultiplier;
|
||||
|
||||
light.ShadowsDepthBias = 0.0565f;
|
||||
// if low quality shadows
|
||||
//light.ShadowsDepthBias = 0.2492f;
|
||||
|
||||
if (spotLight != null)
|
||||
{
|
||||
// huge aliasing with spot lights for some reason?
|
||||
light.ShadowsDepthBias = 0.7f;
|
||||
}
|
||||
|
||||
if (inverse)
|
||||
{
|
||||
light.Brightness *= 20000f;
|
||||
finalRadius *= 0.7f;
|
||||
}
|
||||
|
||||
if (pointLight != null)
|
||||
{
|
||||
pointLight.UseInverseSquaredFalloff = inverse;
|
||||
pointLight.Radius = finalRadius;
|
||||
pointLight.FallOffExponent = FallOffExponent;
|
||||
}
|
||||
if (spotLight != null)
|
||||
{
|
||||
spotLight.UseInverseSquaredFalloff = inverse;
|
||||
spotLight.Radius = finalRadius;
|
||||
spotLight.FallOffExponent = FallOffExponent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user