2021-06-18 12:32:03 +01:00
|
|
|
using System;
|
|
|
|
|
using MessagePack;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
using static Unity.Mathematics.noise;
|
|
|
|
|
using float2 = Unity.Mathematics.float2;
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class ZoneEnvironment
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public NebulaSettings Nebula;
|
|
|
|
|
[Key(1)] public FlowSettings Flow;
|
|
|
|
|
[Key(2)] public NoiseSettings Noise;
|
|
|
|
|
[Key(3)] public AmbientLightingSettings Lighting;
|
|
|
|
|
[Key(4)] public GridSettings Grid;
|
2021-06-18 12:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class NebulaSettings
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public float FillDensity;
|
|
|
|
|
[Key(1)] public float FillDistance;
|
|
|
|
|
[Key(2)] public float FillExponent;
|
|
|
|
|
[Key(12)] public float FillOffset;
|
|
|
|
|
[Key(3)] public float PatchDensity;
|
|
|
|
|
[Key(4)] public float FloorOffset;
|
|
|
|
|
[Key(5)] public float FloorBlend;
|
|
|
|
|
[Key(6)] public float PatchBlend;
|
|
|
|
|
[Key(7)] public float Luminance;
|
|
|
|
|
[Key(13)] public float Extinction;
|
|
|
|
|
//[Key(8)] public float TintExponent;
|
|
|
|
|
[Key(9)] public float TintLodExponent;
|
|
|
|
|
[Key(10)] public float SafetyDistance;
|
2022-07-21 21:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2025-01-30 01:58:05 +00:00
|
|
|
public class GridSettings
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public bool Enabled;
|
|
|
|
|
[Key(1)] public float Offset;
|
2025-01-30 01:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2022-07-21 21:40:44 +01:00
|
|
|
public class AmbientLightingSettings
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public float DynamicSkyBoost;
|
|
|
|
|
[Key(1)] public float DynamicLodHigh;
|
|
|
|
|
[Key(2)] public float DynamicLodLow;
|
|
|
|
|
[Key(3)] public float DynamicIntensity;
|
2021-06-18 12:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class FlowSettings
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public float GlobalScale;
|
|
|
|
|
[Key(1)] public float GlobalAmplitude;
|
|
|
|
|
[Key(2)] public float GlobalScrollSpeed;
|
|
|
|
|
[Key(3)] public float Period;
|
|
|
|
|
[Key(4)] public float SlopeAmplitude;
|
|
|
|
|
[Key(5)] public float SwirlAmplitude;
|
2021-06-18 12:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class NoiseSettings
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public float Scale;
|
|
|
|
|
[Key(1)] public float Amplitude;
|
|
|
|
|
[Key(2)] public float Exponent;
|
|
|
|
|
[Key(3)] public float Speed;
|
|
|
|
|
[Key(4)] public float SlopeExponent;
|
2021-06-18 12:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Union(0, typeof(PowerBrush)),
|
|
|
|
|
Union(1, typeof(SimplexBrush)),
|
|
|
|
|
Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public abstract class Brush
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(0)] public BrushLayer LayerMask;
|
|
|
|
|
[Key(1)] public float Cutoff;
|
|
|
|
|
[Key(2)] public float Depth;
|
|
|
|
|
[Key(3)] public float EnvelopeExponent;
|
|
|
|
|
|
2021-06-18 12:32:03 +01:00
|
|
|
float powerPulse( float x, float power )
|
|
|
|
|
{
|
|
|
|
|
x = saturate(abs(x))-.001f;
|
|
|
|
|
return pow((x + 1.0f) * (1.0f - x), power);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract float Evaluate(float2 world, float2 uv);
|
|
|
|
|
|
|
|
|
|
public float Evaluate(float2 world, float2 pos, float2 radius)
|
|
|
|
|
{
|
|
|
|
|
var uv = (world - pos) / radius;
|
|
|
|
|
float dist = length(uv)*2;
|
|
|
|
|
float envelope = min(Cutoff, powerPulse(dist,EnvelopeExponent)) * smoothstep(1, .95f, dist);
|
|
|
|
|
return Depth * Evaluate(world, uv) * envelope;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class PowerBrush : Brush
|
|
|
|
|
{
|
|
|
|
|
protected override float Evaluate(float2 world, float2 uv)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public abstract class TextureBrush : Brush
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(4)] public float2 Frequency;
|
|
|
|
|
[Key(5)] public float2 Phase;
|
2021-06-18 12:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public abstract class AnimatedBrush : TextureBrush
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(6)] public float AnimationSpeed;
|
|
|
|
|
|
2021-06-18 12:32:03 +01:00
|
|
|
[IgnoreMember]
|
|
|
|
|
public float Time { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class SimplexBrush : TextureBrush
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(6)] public bool AbsoluteValue;
|
|
|
|
|
|
2021-06-18 12:32:03 +01:00
|
|
|
protected override float Evaluate(float2 world, float2 uv)
|
|
|
|
|
{
|
|
|
|
|
var noise = snoise(world * Frequency + Phase);
|
|
|
|
|
return AbsoluteValue ? abs(noise) : noise;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class AnimatedSimplexBrush : AnimatedBrush
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(7)] public bool AbsoluteValue;
|
|
|
|
|
|
2021-06-18 12:32:03 +01:00
|
|
|
protected override float Evaluate(float2 world, float2 uv)
|
|
|
|
|
{
|
|
|
|
|
var noise = snoise(float3(float2(world * Frequency + Phase), AnimationSpeed * Time));
|
|
|
|
|
return AbsoluteValue ? abs(noise) : noise;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Serializable, MessagePackObject]
|
2021-06-18 12:32:03 +01:00
|
|
|
public class RadialWaveBrush : TextureBrush
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Key(7)] public float WaveExponent;
|
|
|
|
|
|
2021-06-18 12:32:03 +01:00
|
|
|
protected override float Evaluate(float2 world, float2 uv)
|
|
|
|
|
{
|
|
|
|
|
float dist = length(uv);
|
|
|
|
|
float ang = atan2(uv.y,uv.x);
|
|
|
|
|
return cos((ang + Phase.x) * Frequency.x * PI + (pow(dist, WaveExponent) + Phase.y) * Frequency.y);
|
|
|
|
|
}
|
|
|
|
|
}
|