Unified Volumetric Flow
Fixed towing system Tweaked Nebula Flow (a lot) Extracted environment appearance settings into ZoneEnvironment data structure Stardust particles now follow global flow field
This commit is contained in:
parent
f3df2ba4cf
commit
00f752edf7
39 changed files with 812 additions and 341 deletions
|
|
@ -774,7 +774,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
true);
|
||||
// EntitySerializer.Unpack(ItemManager, Zone, Loadouts.First(x => x.Name == StarterShipTemplate), true);
|
||||
((Ship) ship).IsPlayerShip = true;
|
||||
((Ship) ship).CanTow = true;
|
||||
ship.Position = float3.zero;
|
||||
ship.Zone = Zone;
|
||||
Zone.Entities.Add(ship);
|
||||
|
|
@ -874,7 +873,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (ZoneRenderer.Planets.ContainsKey(parentOrbitPlanet))
|
||||
DockCamera.LookAt = ZoneRenderer.Planets[parentOrbitPlanet].Body.transform;
|
||||
else DockCamera.LookAt = ZoneRenderer.ZoneRoot;
|
||||
if (dockingBay.DockedShip.CanTow)
|
||||
if (entity is OrbitalEntity {CanTow: true})
|
||||
TowingStation = entity;
|
||||
Menu.ShowTab(MenuTab.Inventory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public class GameSettings : ScriptableObject
|
|||
public Color GearHitColor;
|
||||
public Gradient ArmorGradient;
|
||||
public Gradient DurabilityGradient;
|
||||
public ZoneEnvironment DefaultEnvironment;
|
||||
[HideInInspector] public Sprite[] ItemIcons;
|
||||
[HideInInspector] public Sprite[] WeaponTypeIcons;
|
||||
[HideInInspector] public Sprite[] WeaponCaliberIcons;
|
||||
|
|
|
|||
|
|
@ -228,4 +228,14 @@ public enum MusicType
|
|||
Overworld,
|
||||
Combat,
|
||||
Boss
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BrushLayer
|
||||
{
|
||||
Gravity = 1 << 0,
|
||||
Displacement = 1 << 1,
|
||||
FogHeight = 1 << 2,
|
||||
CloudHeight = 1 << 3,
|
||||
CloudDepth = 1 << 4
|
||||
}
|
||||
135
Assets/Scripts/ServerShared/Environment.cs
Normal file
135
Assets/Scripts/ServerShared/Environment.cs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
using System;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ZoneEnvironment
|
||||
{
|
||||
[JsonProperty("nebula"), Key(0)] public NebulaSettings Nebula;
|
||||
[JsonProperty("flow"), Key(1)] public FlowSettings Flow;
|
||||
[JsonProperty("noise"), Key(2)] public NoiseSettings Noise;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class NebulaSettings
|
||||
{
|
||||
[JsonProperty("fillDensity"), Key(0)] public float FillDensity;
|
||||
[JsonProperty("fillDistance"), Key(1)] public float FillDistance;
|
||||
[JsonProperty("fogDensity"), Key(2)] public float FloorDensity;
|
||||
[JsonProperty("cloudDensity"), Key(3)] public float PatchDensity;
|
||||
[JsonProperty("fogOffset"), Key(4)] public float FloorOffset;
|
||||
[JsonProperty("fogBlend"), Key(5)] public float FloorBlend;
|
||||
[JsonProperty("cloudBlend"), Key(6)] public float PatchBlend;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class FlowSettings
|
||||
{
|
||||
[JsonProperty("scale"), Key(0)] public float Scale;
|
||||
[JsonProperty("amplitude"), Key(1)] public float Amplitude;
|
||||
[JsonProperty("scrollSpeed"), Key(2)] public float ScrollSpeed;
|
||||
[JsonProperty("velocity"), Key(3)] public float Speed;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class NoiseSettings
|
||||
{
|
||||
[JsonProperty("scale"), Key(0)] public float Scale;
|
||||
[JsonProperty("amplitude"), Key(1)] public float Amplitude;
|
||||
[JsonProperty("exponent"), Key(2)] public float Exponent;
|
||||
[JsonProperty("speed"), Key(3)] public float Speed;
|
||||
}
|
||||
|
||||
[Union(0, typeof(PowerBrush)),
|
||||
Union(1, typeof(SimplexBrush)),
|
||||
Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class Brush
|
||||
{
|
||||
[JsonProperty("layerMask"), Key(0)] public BrushLayer LayerMask;
|
||||
[JsonProperty("cutoff"), Key(1)] public float Cutoff;
|
||||
[JsonProperty("depth"), Key(2)] public float Depth;
|
||||
[JsonProperty("envelopeExponent"), Key(3)] public float EnvelopeExponent;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class PowerBrush : Brush
|
||||
{
|
||||
protected override float Evaluate(float2 world, float2 uv)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class TextureBrush : Brush
|
||||
{
|
||||
[JsonProperty("frequency"), Key(4)] public float2 Frequency;
|
||||
[JsonProperty("phase"), Key(5)] public float2 Phase;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class AnimatedBrush : TextureBrush
|
||||
{
|
||||
[JsonProperty("animationSpeed"), Key(6)] public float AnimationSpeed;
|
||||
|
||||
[IgnoreMember]
|
||||
public float Time { get; set; }
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class SimplexBrush : TextureBrush
|
||||
{
|
||||
[JsonProperty("absolute"), Key(6)] public bool AbsoluteValue;
|
||||
|
||||
protected override float Evaluate(float2 world, float2 uv)
|
||||
{
|
||||
var noise = snoise(world * Frequency + Phase);
|
||||
return AbsoluteValue ? abs(noise) : noise;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class AnimatedSimplexBrush : AnimatedBrush
|
||||
{
|
||||
[JsonProperty("absolute"), Key(7)] public bool AbsoluteValue;
|
||||
|
||||
protected override float Evaluate(float2 world, float2 uv)
|
||||
{
|
||||
var noise = snoise(float3(float2(world * Frequency + Phase), AnimationSpeed * Time));
|
||||
return AbsoluteValue ? abs(noise) : noise;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class RadialWaveBrush : TextureBrush
|
||||
{
|
||||
[JsonProperty("waveExponent"), Key(7)] public float WaveExponent;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/ServerShared/Environment.cs.meta
Normal file
3
Assets/Scripts/ServerShared/Environment.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4fc7c09c95c487baeffbd139abe89b9
|
||||
timeCreated: 1622614593
|
||||
|
|
@ -520,6 +520,9 @@ public class HullData : EquippableItemData
|
|||
|
||||
[Inspectable, JsonProperty("drag"), Key(28)]
|
||||
public float Drag;
|
||||
|
||||
[Inspectable, JsonProperty("canTow"), Key(29)]
|
||||
public bool CanTow;
|
||||
|
||||
[IgnoreMember]
|
||||
public Shape InteriorCells
|
||||
|
|
|
|||
|
|
@ -95,6 +95,8 @@ public class LoadoutGenerator
|
|||
var instance = ItemManager.CreateInstance(item);
|
||||
cargo.TryStore(instance);
|
||||
}
|
||||
|
||||
entity.CanTow = hullData.CanTow;
|
||||
|
||||
return EntitySerializer.Pack(entity) as OrbitalEntityPack;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class OrbitalEntity : Entity
|
|||
public SecurityLevel SecurityLevel;
|
||||
public float SecurityRadius;
|
||||
public LocationStory Story;
|
||||
public bool CanTow;
|
||||
|
||||
public OrbitalEntity(ItemManager itemManager, Zone zone, EquippableItem hull, Guid orbit, EntitySettings settings) : base(itemManager, zone, hull, settings)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ public class Ship : Entity
|
|||
public Entity HomeEntity;
|
||||
public float2 MovementDirection;
|
||||
public bool IsPlayerShip;
|
||||
public bool CanTow;
|
||||
|
||||
private HashSet<EquippedItem> _thrusterItems;
|
||||
private Thruster[] _allThrusters;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System;
|
|||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Serialization;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
|
||||
|
|
@ -16,15 +17,23 @@ using static Unity.Mathematics.noise;
|
|||
[RequireComponent( typeof( Camera ) ), ImageEffectAllowedInSceneView]
|
||||
public class VolumeSampling : MonoBehaviour
|
||||
{
|
||||
public Material _volMaterial;
|
||||
[FormerlySerializedAs("_volMaterial")] public Material VolMaterial;
|
||||
public Transform GridTransform;
|
||||
public GameSettings Settings;
|
||||
//public int DownsampleBlurMask = 2;
|
||||
private Camera _camera;
|
||||
private RenderBuffer[] _mrt;
|
||||
private RenderTexture _blurMask;
|
||||
private Texture2D _disabledBlurMask;
|
||||
private float _flowScroll;
|
||||
|
||||
public RenderTexture NebulaSurfaceHeight;
|
||||
public RenderTexture NebulaPatchHeight;
|
||||
public RenderTexture NebulaPatch;
|
||||
public RenderTexture NebulaTint;
|
||||
|
||||
public bool EnableDepth { get; set; } = true;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
|
@ -39,19 +48,19 @@ public class VolumeSampling : MonoBehaviour
|
|||
void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
// check for no shader / shader compile error
|
||||
if( _volMaterial == null )
|
||||
if( VolMaterial == null )
|
||||
{
|
||||
Graphics.Blit(source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shader needs this matrix to generate world space rays
|
||||
_volMaterial.SetMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
_volMaterial.SetMatrix("_CamInvProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
VolMaterial.SetMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
VolMaterial.SetMatrix("_CamInvProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
|
||||
// Shader needs to know the position and scale of cameras used to render input textures
|
||||
if(GridTransform != null)
|
||||
_volMaterial.SetVector("_GridTransform", new Vector4(GridTransform.position.x,GridTransform.position.z,GridTransform.localScale.x));
|
||||
VolMaterial.SetVector("_GridTransform", new Vector4(GridTransform.position.x,GridTransform.position.z,GridTransform.localScale.x));
|
||||
|
||||
_mrt[0] = destination.colorBuffer;
|
||||
_mrt[1] = _blurMask.colorBuffer;
|
||||
|
|
@ -59,7 +68,7 @@ public class VolumeSampling : MonoBehaviour
|
|||
// Blit with a MRT.
|
||||
Graphics.SetRenderTarget(_mrt, source.depthBuffer);
|
||||
|
||||
Graphics.Blit( source, _volMaterial, 0 );
|
||||
Graphics.Blit( source, VolMaterial, 0 );
|
||||
|
||||
//Graphics.Blit(rt1, destination);
|
||||
|
||||
|
|
@ -67,5 +76,29 @@ public class VolumeSampling : MonoBehaviour
|
|||
Shader.SetGlobalTexture("_DoFBlurTex", _blurMask);
|
||||
else
|
||||
Shader.SetGlobalTexture("_DoFBlurTex", _disabledBlurMask);
|
||||
|
||||
Shader.SetGlobalTexture("_NebulaSurfaceHeight", NebulaSurfaceHeight);
|
||||
Shader.SetGlobalTexture("_NebulaPatchHeight", NebulaPatchHeight);
|
||||
Shader.SetGlobalTexture("_NebulaPatch", NebulaPatch);
|
||||
Shader.SetGlobalTexture("_NebulaTint", NebulaTint);
|
||||
|
||||
Shader.SetGlobalFloat("_NebulaFillDensity", Settings.DefaultEnvironment.Nebula.FillDensity);
|
||||
Shader.SetGlobalFloat("_SafetyDistance", Settings.DefaultEnvironment.Nebula.FillDistance);
|
||||
Shader.SetGlobalFloat("_NebulaFloorDensity", Settings.DefaultEnvironment.Nebula.FloorDensity);
|
||||
Shader.SetGlobalFloat("_NebulaPatchDensity", Settings.DefaultEnvironment.Nebula.PatchDensity);
|
||||
Shader.SetGlobalFloat("_NebulaFloorOffset", Settings.DefaultEnvironment.Nebula.FloorOffset);
|
||||
Shader.SetGlobalFloat("_NebulaFloorBlend", Settings.DefaultEnvironment.Nebula.FloorBlend);
|
||||
Shader.SetGlobalFloat("_NebulaPatchBlend", Settings.DefaultEnvironment.Nebula.PatchBlend);
|
||||
// Shader.SetGlobalFloat("_TintExponent", Settings.DefaultEnvironment.);
|
||||
Shader.SetGlobalFloat("_NoiseScale", Settings.DefaultEnvironment.Noise.Scale);
|
||||
Shader.SetGlobalFloat("_NoiseExponent", Settings.DefaultEnvironment.Noise.Exponent);
|
||||
Shader.SetGlobalFloat("_NoiseAmplitude", Settings.DefaultEnvironment.Noise.Amplitude);
|
||||
Shader.SetGlobalFloat("_NoiseSpeed", Settings.DefaultEnvironment.Noise.Speed);
|
||||
Shader.SetGlobalFloat("_FlowScale", Settings.DefaultEnvironment.Flow.Scale);
|
||||
Shader.SetGlobalFloat("_FlowAmplitude", Settings.DefaultEnvironment.Flow.Amplitude);
|
||||
_flowScroll += Settings.DefaultEnvironment.Flow.ScrollSpeed * Time.deltaTime;
|
||||
Shader.SetGlobalFloat("_FlowScroll", _flowScroll);
|
||||
Shader.SetGlobalFloat("_FlowSpeed", Settings.DefaultEnvironment.Flow.Speed);
|
||||
// Shader.SetGlobalFloat("_SafetyDistance", Settings.DefaultEnvironment.);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue