Model Zyphos nested domains and Umbros binary
This commit is contained in:
parent
db8f767c4a
commit
61c3bd4ecc
19 changed files with 291 additions and 62 deletions
|
|
@ -24,6 +24,10 @@ public readonly record struct AquariumFractalKey
|
|||
|
||||
public enum AquariumFractalDomainKind
|
||||
{
|
||||
Solar,
|
||||
Orbital,
|
||||
Planetary,
|
||||
LatLong,
|
||||
CubeSphereTile,
|
||||
Surface2D,
|
||||
Object3D,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@ public static class FractalDebugDump
|
|||
ArgumentNullException.ThrowIfNull(selectedCut);
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine($"domain {tree.Domain.Key} kind={tree.Domain.Kind}");
|
||||
foreach (var domain in tree.Domains)
|
||||
{
|
||||
builder.AppendLine($"domain {domain.Key} kind={domain.Kind} parent={domain.ParentKey}");
|
||||
}
|
||||
|
||||
builder.AppendLine($"nodes {tree.Nodes.Count} claims {tree.Claims.Count} summaries {summaries.Count} cut {selectedCut.Count}");
|
||||
foreach (var node in tree.Nodes)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public static class FractalDslCompiler
|
|||
var lines = source.Replace("\r\n", "\n", StringComparison.Ordinal).Split('\n');
|
||||
AquariumFractalDomain? domain = null;
|
||||
AquariumFractalKey rootKey = default;
|
||||
var domains = new List<AquariumFractalDomain>();
|
||||
var claims = new List<AquariumBrushClaim>();
|
||||
|
||||
for (var lineIndex = 0; lineIndex < lines.Length; lineIndex++)
|
||||
|
|
@ -26,17 +27,23 @@ public static class FractalDslCompiler
|
|||
var tokens = line.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
switch (tokens[0])
|
||||
{
|
||||
case "domain":
|
||||
EnsureTokenCount(tokens, 4, lineIndex);
|
||||
domains.Add(ParseDomain(tokens, lineIndex));
|
||||
break;
|
||||
case "tile":
|
||||
EnsureTokenCount(tokens, 6, lineIndex);
|
||||
var tile = new CubeTileKey(ParseFace(tokens[1], lineIndex), ParseInt(tokens[2], lineIndex), ParseInt(tokens[3], lineIndex), ParseInt(tokens[4], lineIndex));
|
||||
var domainKey = FractalStableKeyBuilder.ForCubeTile(tile, tokens[5]);
|
||||
var parentKey = tokens.Length >= 7 ? new AquariumFractalKey(tokens[6]) : default;
|
||||
rootKey = FractalStableKeyBuilder.Child(domainKey, "root");
|
||||
domain = new AquariumFractalDomain(
|
||||
domainKey,
|
||||
AquariumFractalDomainKind.CubeSphereTile,
|
||||
default,
|
||||
parentKey,
|
||||
new Vector4((float)tile.Face, tile.Level, tile.X, tile.Y),
|
||||
Vector4.Zero);
|
||||
domains.Add(domain.Value);
|
||||
break;
|
||||
case "height":
|
||||
EnsureDomain(domain, lineIndex);
|
||||
|
|
@ -58,7 +65,29 @@ public static class FractalDslCompiler
|
|||
throw new FormatException("Fractal DSL must declare a `tile <face> <level> <x> <y> <path>` line before claims.");
|
||||
}
|
||||
|
||||
return FractalOwnershipTreeBuilder.BuildFlatUnion(domain.Value, rootKey, claims);
|
||||
return FractalOwnershipTreeBuilder.BuildFlatUnion(domain.Value, domains, rootKey, claims);
|
||||
}
|
||||
|
||||
private static AquariumFractalDomain ParseDomain(string[] tokens, int lineIndex)
|
||||
{
|
||||
if (!Enum.TryParse<AquariumFractalDomainKind>(tokens[1], ignoreCase: true, out var kind))
|
||||
{
|
||||
throw new FormatException($"Invalid domain kind `{tokens[1]}` at line {lineIndex + 1}.");
|
||||
}
|
||||
|
||||
var parent = tokens[3] == "-" ? default : new AquariumFractalKey(tokens[3]);
|
||||
var parameters = new float[8];
|
||||
for (var index = 4; index < tokens.Length && index < 12; index++)
|
||||
{
|
||||
parameters[index - 4] = ParseFloat(tokens[index], lineIndex);
|
||||
}
|
||||
|
||||
return new AquariumFractalDomain(
|
||||
new AquariumFractalKey(tokens[2]),
|
||||
kind,
|
||||
parent,
|
||||
new Vector4(parameters[0], parameters[1], parameters[2], parameters[3]),
|
||||
new Vector4(parameters[4], parameters[5], parameters[6], parameters[7]));
|
||||
}
|
||||
|
||||
private static AquariumBrushClaim ParseHeight(string[] tokens, AquariumFractalKey rootKey, int lineIndex, int claimIndex)
|
||||
|
|
|
|||
|
|
@ -8,14 +8,26 @@ public sealed class FractalOwnershipTree
|
|||
AquariumFractalDomain domain,
|
||||
IReadOnlyList<AquariumFractalNode> nodes,
|
||||
IReadOnlyList<AquariumBrushClaim> claims)
|
||||
: this(domain, [domain], nodes, claims)
|
||||
{
|
||||
}
|
||||
|
||||
public FractalOwnershipTree(
|
||||
AquariumFractalDomain domain,
|
||||
IReadOnlyList<AquariumFractalDomain> domains,
|
||||
IReadOnlyList<AquariumFractalNode> nodes,
|
||||
IReadOnlyList<AquariumBrushClaim> claims)
|
||||
{
|
||||
Domain = domain;
|
||||
Domains = domains;
|
||||
Nodes = nodes;
|
||||
Claims = claims;
|
||||
}
|
||||
|
||||
public AquariumFractalDomain Domain { get; }
|
||||
|
||||
public IReadOnlyList<AquariumFractalDomain> Domains { get; }
|
||||
|
||||
public IReadOnlyList<AquariumFractalNode> Nodes { get; }
|
||||
|
||||
public IReadOnlyList<AquariumBrushClaim> Claims { get; }
|
||||
|
|
|
|||
|
|
@ -9,8 +9,18 @@ public static class FractalOwnershipTreeBuilder
|
|||
AquariumFractalDomain domain,
|
||||
AquariumFractalKey rootKey,
|
||||
IReadOnlyList<AquariumBrushClaim> claims)
|
||||
{
|
||||
return BuildFlatUnion(domain, [domain], rootKey, claims);
|
||||
}
|
||||
|
||||
public static FractalOwnershipTree BuildFlatUnion(
|
||||
AquariumFractalDomain domain,
|
||||
IReadOnlyList<AquariumFractalDomain> domains,
|
||||
AquariumFractalKey rootKey,
|
||||
IReadOnlyList<AquariumBrushClaim> claims)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(claims);
|
||||
ArgumentNullException.ThrowIfNull(domains);
|
||||
|
||||
var bounds = BoundsForClaims(claims);
|
||||
var root = new AquariumFractalNode(
|
||||
|
|
@ -25,7 +35,7 @@ public static class FractalOwnershipTreeBuilder
|
|||
bounds,
|
||||
Seed: 0);
|
||||
|
||||
return new FractalOwnershipTree(domain, [root], claims);
|
||||
return new FractalOwnershipTree(domain, domains, [root], claims);
|
||||
}
|
||||
|
||||
private static Vector4 BoundsForClaims(IReadOnlyList<AquariumBrushClaim> claims)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,18 @@ float3 zyPlanetDir(float3 local, SdfObject sdfObject)
|
|||
return normalize(zyRotateZ(local, -sdfObject.state.y));
|
||||
}
|
||||
|
||||
float3 zyPrimaryStarDirectionLocal(SdfObject sdfObject)
|
||||
{
|
||||
return normalize(float3(cos(sdfObject.state.w), sin(sdfObject.state.w), 0.18));
|
||||
}
|
||||
|
||||
float zyUmbrosEclipse(float3 starDirectionLocal)
|
||||
{
|
||||
const float umbrosAngularRadius = 0.1127;
|
||||
float alignment = dot(normalize(starDirectionLocal), float3(1.0, 0.0, 0.0));
|
||||
return smoothstep(cos(umbrosAngularRadius * 1.45), cos(umbrosAngularRadius * 0.45), alignment);
|
||||
}
|
||||
|
||||
float zySphericalField(float3 dir)
|
||||
{
|
||||
float latitude = asin(saturate(abs(dir.z)) * 2.0 - 1.0);
|
||||
|
|
@ -80,17 +92,19 @@ float3 shadeSdf(float2 uv, float travel, float3 p, float3 normal, int sdfIndex,
|
|||
SdfObject sdfObject = sdfObjects[sdfIndex];
|
||||
float3 dir = zyPlanetDir(p - sdfObject.centerRadius.xyz, sdfObject);
|
||||
float3 viewDirection = normalize(cameraPosition - p);
|
||||
float3 sunDirection = normalize(float3(-0.46, -0.72, 0.52));
|
||||
float daylight = saturate(dot(normal, sunDirection) * 0.74 + 0.34);
|
||||
float night = saturate(-dot(normal, sunDirection) * 1.7 - 0.20);
|
||||
float3 starDirectionLocal = zyPrimaryStarDirectionLocal(sdfObject);
|
||||
float eclipse = zyUmbrosEclipse(starDirectionLocal);
|
||||
float daylight = saturate(dot(dir, starDirectionLocal) * 0.74 + 0.24) * (1.0 - eclipse * 0.86);
|
||||
float night = saturate(-dot(dir, starDirectionLocal) * 1.7 - 0.20 + eclipse * 0.55);
|
||||
float citySeed = sin(dir.x * 43.0 + sin(dir.y * 19.0) * 4.0 + dir.z * 31.0);
|
||||
float cityWeb = smoothstep(0.82, 0.96, citySeed * 0.5 + 0.5);
|
||||
float coast = 1.0 - smoothstep(0.020, 0.070, abs(zySphericalField(dir) - sdfObject.state.z));
|
||||
float fresnel = pow(1.0 - saturate(dot(normal, viewDirection)), 3.2);
|
||||
float3 city = float3(1.0, 0.54, 0.14) * cityWeb * coast * night * 1.25;
|
||||
float3 eclipseTint = float3(0.15, 0.19, 0.26) * eclipse * saturate(dot(dir, starDirectionLocal) * 0.5 + 0.5);
|
||||
float3 atmosphere = float3(0.07, 0.38, 0.78) * (fresnel * 1.35 + pow(fresnel, 6.0) * 2.6);
|
||||
|
||||
return shadeSdfPbr(p, normal, surface) * daylight + city + atmosphere;
|
||||
return shadeSdfPbr(p, normal, surface) * daylight + city + atmosphere + eclipseTint;
|
||||
}
|
||||
|
||||
#include "D3D12SdfProxy.hlsli"
|
||||
|
|
|
|||
|
|
@ -3,15 +3,20 @@ static const int SDF_INDEX = 1;
|
|||
#include "D3D12SdfCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
|
||||
float zyMoonRelief(float3 dir)
|
||||
float zyUmbrosRelief(float3 dir)
|
||||
{
|
||||
float ridges =
|
||||
sin(dir.x * 15.0 + dir.y * 4.0) * 0.018 +
|
||||
sin(dir.y * 21.0 - dir.z * 7.0) * 0.012 +
|
||||
sin((dir.x + dir.y + dir.z) * 34.0) * 0.006;
|
||||
float craterA = 1.0 - smoothstep(0.055, 0.115, abs(length(dir.xy - float2(0.22, -0.18)) - 0.32));
|
||||
float craterB = 1.0 - smoothstep(0.040, 0.090, abs(length(dir.yz - float2(0.30, 0.24)) - 0.22));
|
||||
return ridges - (craterA * 0.035 + craterB * 0.026);
|
||||
float basinA = 1.0 - smoothstep(0.055, 0.115, abs(length(dir.xy - float2(0.22, -0.18)) - 0.32));
|
||||
float basinB = 1.0 - smoothstep(0.040, 0.090, abs(length(dir.yz - float2(0.30, 0.24)) - 0.22));
|
||||
return ridges - (basinA * 0.035 + basinB * 0.026);
|
||||
}
|
||||
|
||||
float3 zyPrimaryStarDirection(float phase)
|
||||
{
|
||||
return normalize(float3(cos(phase), sin(phase), 0.18));
|
||||
}
|
||||
|
||||
float sdfDistance(float3 p, int sdfIndex)
|
||||
|
|
@ -20,18 +25,18 @@ float sdfDistance(float3 p, int sdfIndex)
|
|||
float radius = max(sdfObject.state.x, 0.001);
|
||||
float3 local = p - sdfObject.centerRadius.xyz;
|
||||
float3 dir = normalize(local);
|
||||
return length(local) - (radius + zyMoonRelief(dir));
|
||||
return length(local) - (radius + zyUmbrosRelief(dir));
|
||||
}
|
||||
|
||||
SdfSurface sdfSurface(float3 p, int sdfIndex)
|
||||
{
|
||||
SdfObject sdfObject = sdfObjects[sdfIndex];
|
||||
float3 dir = normalize(p - sdfObject.centerRadius.xyz);
|
||||
float relief = zyMoonRelief(dir);
|
||||
float relief = zyUmbrosRelief(dir);
|
||||
float dust = sin(dir.x * 31.0 + dir.y * 17.0 - dir.z * 11.0) * 0.5 + 0.5;
|
||||
SdfSurface surface;
|
||||
surface.baseColor = lerp(float3(0.31, 0.30, 0.28), float3(0.66, 0.62, 0.54), dust);
|
||||
surface.baseColor = lerp(surface.baseColor, float3(0.20, 0.20, 0.19), saturate(-relief * 18.0));
|
||||
surface.baseColor = lerp(float3(0.18, 0.19, 0.20), float3(0.44, 0.42, 0.38), dust);
|
||||
surface.baseColor = lerp(surface.baseColor, float3(0.10, 0.11, 0.12), saturate(-relief * 18.0));
|
||||
surface.metallic = 0.0;
|
||||
surface.roughness = 0.92;
|
||||
surface.emission = 0.0;
|
||||
|
|
@ -40,8 +45,9 @@ SdfSurface sdfSurface(float3 p, int sdfIndex)
|
|||
|
||||
float3 shadeSdf(float2 uv, float travel, float3 p, float3 normal, int sdfIndex, SdfSurface surface)
|
||||
{
|
||||
float3 sunDirection = normalize(float3(-0.46, -0.72, 0.52));
|
||||
float daylight = saturate(dot(normal, sunDirection) * 0.82 + 0.24);
|
||||
SdfObject sdfObject = sdfObjects[sdfIndex];
|
||||
float3 starDirection = zyPrimaryStarDirection(sdfObject.state.y);
|
||||
float daylight = saturate(dot(normal, starDirection) * 0.74 + 0.16);
|
||||
return shadeSdfPbr(p, normal, surface) * daylight;
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,10 @@
|
|||
# Zyphos first Aquarium fractal terrain DSL proof.
|
||||
tile PositiveZ 0 0 0 zyphos/first-fractal-terrain
|
||||
domain Solar zyphos/parent-star - 0.25 0.006 0.077 16
|
||||
domain Orbital zyphos/zyphos-umbros-orbit zyphos/parent-star 8 1.0 12.9 52
|
||||
domain Planetary zyphos/planet zyphos/zyphos-umbros-orbit 1.0 0.56 0 0
|
||||
domain Planetary zyphos/umbros zyphos/zyphos-umbros-orbit 0.9 8 12.9 0
|
||||
domain LatLong zyphos/planet-latlong zyphos/planet -90 90 -180 180
|
||||
tile PositiveZ 0 0 0 zyphos/first-fractal-terrain zyphos/planet-latlong
|
||||
height basin 0 0 30 30 0 3 1 -0.12 7 basin
|
||||
ifs crater 3 2 -5 3 6 2.5 0.48 2.6 0.42 4 0.85 -0.10 19 crater
|
||||
ifs ridge 2 3 6 -4 5 1.35 0.45 3.2 -0.27 3.6 0.72 0.075 31 ridge
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace Aquarium.Zyphos;
|
|||
public static class ZyphosRenderPlan
|
||||
{
|
||||
public const int PlanetIndex = 0;
|
||||
public const int MoonIndex = 1;
|
||||
public const int UmbrosIndex = 1;
|
||||
public const int SdfObjectCount = 2;
|
||||
|
||||
public static AquariumRenderPlan Create()
|
||||
|
|
@ -14,7 +14,7 @@ public static class ZyphosRenderPlan
|
|||
app.Shaders
|
||||
.Core("D3D12HeightField.hlsl", "D3D12Scene.hlsl", "D3D12Post.hlsl")
|
||||
.SdfShader("D3D12ZyphosPlanet.hlsl")
|
||||
.SdfShader("D3D12ZyphosMoon.hlsl");
|
||||
.SdfShader("D3D12ZyphosUmbros.hlsl");
|
||||
|
||||
var heightField = app.RenderTargets.Create("height-field")
|
||||
.FixedSize(128, 128)
|
||||
|
|
|
|||
|
|
@ -48,10 +48,12 @@ public sealed class ZyphosRuntime : IAquariumRuntime
|
|||
panel.Readout("Runtime", () => $"{timeSeconds:0.0}s");
|
||||
panel.Readout("Camera", () => $"{orbitDistance:0.0} wu / yaw {orbitYaw:0.00}");
|
||||
panel.Readout("Terrain DSL", () => ZyphosFractalTerrain.Summary);
|
||||
panel.Readout("Objects", () => "fractal height DSL, atmosphere, moon");
|
||||
panel.Readout("Binary", () => $"Umbros {ZyphosUmbrosSystem.UmbrosAngularDiameterDegrees:0.0} deg / {ZyphosUmbrosSystem.SeparationInZyphosRadii:0.0} Rz");
|
||||
panel.Readout("Objects", () => "fractal height DSL, atmosphere, Umbros");
|
||||
})
|
||||
.Command("zyphos", _ => $"Zyphos: {ZyphosFractalTerrain.Summary}", "Report Zyphos demo status.")
|
||||
.Command("zyphos-fractal", _ => ZyphosFractalTerrain.DebugDump, "Dump the compiled Zyphos fractal terrain grammar.");
|
||||
.Command("zyphos-fractal", _ => ZyphosFractalTerrain.DebugDump, "Dump the compiled Zyphos fractal terrain grammar.")
|
||||
.Command("zyphos-system", _ => $"Zyphos-Umbros: separation {ZyphosUmbrosSystem.SeparationInZyphosRadii:0.0} Zyphos radii, Umbros radius {ZyphosUmbrosSystem.UmbrosRadiusRatio:0.00} Zyphos, apparent diameter {ZyphosUmbrosSystem.UmbrosAngularDiameterDegrees:0.0} degrees.", "Report the modeled Zyphos/Umbros/star baseline.");
|
||||
}
|
||||
|
||||
public AquariumFrame ComposeFrame(AquariumFrame frame, AquariumFrameInput input)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,6 @@ namespace Aquarium.Zyphos;
|
|||
|
||||
public static class ZyphosSceneBuilder
|
||||
{
|
||||
private const float PlanetSurfaceRadius = 3.8f;
|
||||
private const float PlanetBoundRadius = 4.52f;
|
||||
private const float MoonSurfaceRadius = 0.54f;
|
||||
private const float MoonBoundRadius = 0.70f;
|
||||
|
||||
public static AquariumSceneState Build(float timeSeconds, float previousTimeSeconds)
|
||||
{
|
||||
return new AquariumSceneState
|
||||
|
|
@ -27,50 +22,35 @@ public static class ZyphosSceneBuilder
|
|||
|
||||
private static AquariumSdfObject[] BuildSdfObjects(float timeSeconds, float previousTimeSeconds)
|
||||
{
|
||||
var planetCenter = new Vector3(0.0f, 0.0f, PlanetSurfaceRadius + 0.48f);
|
||||
var rotation = timeSeconds * 0.032f;
|
||||
var previousRotation = previousTimeSeconds * 0.032f;
|
||||
var moonCenter = MoonCenter(timeSeconds);
|
||||
var previousMoonCenter = MoonCenter(previousTimeSeconds);
|
||||
var planetCenter = ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var rotation = ZyphosUmbrosSystem.MutualPhase(timeSeconds);
|
||||
var umbrosCenter = ZyphosUmbrosSystem.UmbrosCenter(timeSeconds);
|
||||
var previousUmbrosCenter = ZyphosUmbrosSystem.UmbrosCenter(previousTimeSeconds);
|
||||
|
||||
var objects = new AquariumSdfObject[ZyphosRenderPlan.SdfObjectCount];
|
||||
objects[ZyphosRenderPlan.PlanetIndex] = new AquariumSdfObject(
|
||||
new Vector4(planetCenter, PlanetBoundRadius),
|
||||
new Vector4(planetCenter, ZyphosUmbrosSystem.ZyphosBoundRadius),
|
||||
new Vector4(planetCenter, 0.0f),
|
||||
new Vector4(PlanetSurfaceRadius, rotation, 0.56f, previousRotation));
|
||||
objects[ZyphosRenderPlan.MoonIndex] = new AquariumSdfObject(
|
||||
new Vector4(moonCenter, MoonBoundRadius),
|
||||
new Vector4(previousMoonCenter, 0.0f),
|
||||
new Vector4(MoonSurfaceRadius, timeSeconds * 0.11f, PlanetSurfaceRadius, 0.0f));
|
||||
new Vector4(ZyphosUmbrosSystem.ZyphosSurfaceRadius, rotation, ZyphosUmbrosSystem.SeaLevel, rotation));
|
||||
objects[ZyphosRenderPlan.UmbrosIndex] = new AquariumSdfObject(
|
||||
new Vector4(umbrosCenter, ZyphosUmbrosSystem.UmbrosBoundRadius),
|
||||
new Vector4(previousUmbrosCenter, 0.0f),
|
||||
new Vector4(ZyphosUmbrosSystem.UmbrosSurfaceRadius, rotation, ZyphosUmbrosSystem.CenterSeparation, 0.0f));
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
private static AquariumSdfLight[] BuildSdfLights(float timeSeconds)
|
||||
{
|
||||
var sunPhase = timeSeconds * 0.015f;
|
||||
var sunCenter = new Vector3(
|
||||
-12.0f + MathF.Sin(sunPhase) * 2.4f,
|
||||
-18.0f,
|
||||
11.0f + MathF.Cos(sunPhase * 0.7f) * 1.3f);
|
||||
var starCenter = ZyphosUmbrosSystem.PrimaryStarCenter(timeSeconds);
|
||||
return
|
||||
[
|
||||
new AquariumSdfLight(
|
||||
new Vector4(sunCenter, 5.5f),
|
||||
new Vector4(8.6f, 7.9f, 6.7f, -100.0f)),
|
||||
new Vector4(starCenter, 5.5f),
|
||||
new Vector4(3.2f, 2.5f, 1.8f, -100.0f)),
|
||||
new AquariumSdfLight(
|
||||
new Vector4(0.0f, 0.0f, PlanetSurfaceRadius + 0.48f, 4.0f),
|
||||
new Vector4(0.10f, 0.18f, 0.28f, -101.0f))
|
||||
new Vector4(ZyphosUmbrosSystem.UmbrosCenter(timeSeconds), ZyphosUmbrosSystem.UmbrosSurfaceRadius),
|
||||
new Vector4(0.06f, 0.08f, 0.11f, -101.0f))
|
||||
];
|
||||
}
|
||||
|
||||
private static Vector3 MoonCenter(float timeSeconds)
|
||||
{
|
||||
var orbit = timeSeconds * 0.075f + 1.3f;
|
||||
var radius = 6.35f;
|
||||
return new Vector3(
|
||||
MathF.Cos(orbit) * radius,
|
||||
MathF.Sin(orbit) * radius * 0.62f,
|
||||
PlanetSurfaceRadius + 0.62f + MathF.Sin(orbit * 0.73f) * 1.2f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
52
src/Aquarium.Zyphos/ZyphosUmbrosSystem.cs
Normal file
52
src/Aquarium.Zyphos/ZyphosUmbrosSystem.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace Aquarium.Zyphos;
|
||||
|
||||
public static class ZyphosUmbrosSystem
|
||||
{
|
||||
public const float ZyphosSurfaceRadius = 3.8f;
|
||||
public const float ZyphosBoundRadius = 4.52f;
|
||||
public const float UmbrosRadiusRatio = 0.9f;
|
||||
public const float SeparationInZyphosRadii = 8.0f;
|
||||
public const float SeaLevel = 0.56f;
|
||||
public const float MutualPhaseRate = 0.032f;
|
||||
|
||||
public static float UmbrosSurfaceRadius => ZyphosSurfaceRadius * UmbrosRadiusRatio;
|
||||
|
||||
public static float UmbrosBoundRadius => UmbrosSurfaceRadius + 0.42f;
|
||||
|
||||
public static float CenterSeparation => ZyphosSurfaceRadius * SeparationInZyphosRadii;
|
||||
|
||||
public static float UmbrosAngularDiameterDegrees =>
|
||||
MathF.Asin(Math.Clamp(UmbrosSurfaceRadius / CenterSeparation, -1.0f, 1.0f)) * 2.0f * 180.0f / MathF.PI;
|
||||
|
||||
public static Vector3 ZyphosCenter => new(0.0f, 0.0f, ZyphosSurfaceRadius + 0.48f);
|
||||
|
||||
public static float MutualPhase(float timeSeconds)
|
||||
{
|
||||
return timeSeconds * MutualPhaseRate;
|
||||
}
|
||||
|
||||
public static Vector3 UmbrosDirection(float timeSeconds)
|
||||
{
|
||||
// Zyphos renders in the mutually locked local frame: Umbros is fixed in the sky while the primary star phase moves.
|
||||
_ = timeSeconds;
|
||||
return Vector3.UnitX;
|
||||
}
|
||||
|
||||
public static Vector3 UmbrosCenter(float timeSeconds)
|
||||
{
|
||||
return ZyphosCenter + UmbrosDirection(timeSeconds) * CenterSeparation;
|
||||
}
|
||||
|
||||
public static Vector3 PrimaryStarDirection(float timeSeconds)
|
||||
{
|
||||
var phase = MutualPhase(timeSeconds);
|
||||
return Vector3.Normalize(new Vector3(MathF.Cos(phase), MathF.Sin(phase), 0.18f));
|
||||
}
|
||||
|
||||
public static Vector3 PrimaryStarCenter(float timeSeconds)
|
||||
{
|
||||
return ZyphosCenter + PrimaryStarDirection(timeSeconds) * (CenterSeparation * 3.2f);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue