Graphics Settings + Disabling Minimap Asteroids
Created graphics settings data structure Added nebula quality option to graphics settings Added option to display asteroids in minimap (expensive)
This commit is contained in:
parent
bbf1d53d1c
commit
b93d2d213b
25 changed files with 1733 additions and 257 deletions
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 55
|
||||
executionOrder: 58
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ void UpdateParticles(uint3 id : SV_DispatchThreadID, int3 groupID : SV_GroupThre
|
|||
particles[id.x].position.y = gravHeight + floorHeight + headroom *
|
||||
pow(RandomValue(), heightExponent) +
|
||||
perlinNoise1D(RandomValue()*1024)*spacing/2;
|
||||
float noise;
|
||||
const float3 flowVec = flow(particles[id.x].position, noise);
|
||||
const float3 flowVec = flow(particles[id.x].position);
|
||||
particles[id.x].position -= flowVec * lifetime * period;
|
||||
const float fade = smoothstep(0,ceilingHeight, particles[id.x].position.y);
|
||||
const float d = pow(density(particles[id.x].position) + .01, 0.1);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ MonoImporter:
|
|||
- HueTexture: {instanceID: 0}
|
||||
- Heightmap: {fileID: 8400000, guid: 55786e8a3fda620489070358940e3c04, type: 2}
|
||||
- Target: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
executionOrder: -5
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
|||
|
|
@ -55,27 +55,6 @@ Texture2D<float2> X2_in;
|
|||
Texture2D<float2> B2_in;
|
||||
RWTexture2D<float2> X2_out;
|
||||
|
||||
// Adjust step (translate & fade towards global velocity field)
|
||||
[numthreads(8, 8, 1)]
|
||||
void Adjust(uint2 tid : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 dim;
|
||||
W_out.GetDimensions(dim.x, dim.y);
|
||||
|
||||
float2 uv = (tid + 0.5) / dim;
|
||||
float2 globalUV = (uv - .5) * _FluidTransform.z + _FluidTransform.xy;
|
||||
float2 gravUV = getUV(globalUV);
|
||||
float3 globalPos = float3(globalUV.x, -tex2Dlod(_NebulaSurfaceHeight, float4(gravUV, 0, 0)).x, globalUV.x);
|
||||
float noise;
|
||||
float3 f = flow(globalPos, noise);
|
||||
|
||||
float2 prevUV = uv - Delta;
|
||||
|
||||
if(any(prevUV<0)||any(prevUV>1))
|
||||
W_out[tid] = f.xz;
|
||||
else W_out[tid] = lerp(U_in.SampleLevel(samplerU_in, prevUV, 0), f.xz, Damping);
|
||||
}
|
||||
|
||||
// Advect step
|
||||
[numthreads(8, 8, 1)]
|
||||
void Advect(uint2 tid : SV_DispatchThreadID)
|
||||
|
|
@ -154,3 +133,23 @@ void Jacobi2(uint2 tid : SV_DispatchThreadID)
|
|||
X2_out[tid] = (X2_in[tid - int2(1, 0)] + X2_in[tid + int2(1, 0)] +
|
||||
X2_in[tid - int2(0, 1)] + X2_in[tid + int2(0, 1)] + Alpha * B2_in[tid]) / Beta;
|
||||
}
|
||||
|
||||
// Adjust step (translate & fade towards global velocity field)
|
||||
[numthreads(8, 8, 1)]
|
||||
void Adjust(uint2 tid : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 dim;
|
||||
W_out.GetDimensions(dim.x, dim.y);
|
||||
|
||||
float2 uv = (tid + float2(.5,.5)) / dim;
|
||||
float2 globalPosXZ = (uv - .5) * _FluidTransform.z + _FluidTransform.xy;
|
||||
float2 gravUV = getUV(globalPosXZ);
|
||||
float3 globalPos = float3(globalPosXZ.x, -tex2Dlod(_NebulaSurfaceHeight, float4(gravUV, 0, 0)).x, globalPosXZ.y);
|
||||
float2 f = flow(globalPos).xz * (_FluidTransform.z / dim.x);
|
||||
|
||||
float2 prevUV = uv - Delta;
|
||||
|
||||
//if(any(prevUV<0)||any(prevUV>1))
|
||||
W_out[tid] = f;
|
||||
//else W_out[tid] = lerp(U_in.SampleLevel(samplerU_in, prevUV, 0), f, Damping);
|
||||
}
|
||||
|
|
@ -8,215 +8,213 @@ using static Unity.Mathematics.math;
|
|||
using int2 = Unity.Mathematics.int2;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace StableFluids
|
||||
public class Fluid : MonoBehaviour
|
||||
{
|
||||
public class Fluid : MonoBehaviour
|
||||
#region Editable attributes
|
||||
|
||||
[SerializeField] int _resolution = 512;
|
||||
[SerializeField] float _viscosity = 1e-6f;
|
||||
[SerializeField] float _damping = .05f;
|
||||
[SerializeField] float _range = 512;
|
||||
[SerializeField] Transform _camera;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal resources
|
||||
|
||||
[SerializeField, HideInInspector] ComputeShader _compute;
|
||||
[SerializeField, HideInInspector] Shader _shader;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private members
|
||||
|
||||
Material _shaderSheet;
|
||||
int2 _previousCameraIntPosition = int2.zero;
|
||||
private List<Force> _forces = new List<Force>();
|
||||
|
||||
struct Force
|
||||
{
|
||||
#region Editable attributes
|
||||
|
||||
[SerializeField] int _resolution = 512;
|
||||
[SerializeField] float _viscosity = 1e-6f;
|
||||
[SerializeField] float _damping = .05f;
|
||||
[SerializeField] float _range = 512;
|
||||
[SerializeField] Transform _camera;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal resources
|
||||
|
||||
[SerializeField, HideInInspector] ComputeShader _compute;
|
||||
[SerializeField, HideInInspector] Shader _shader;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private members
|
||||
|
||||
Material _shaderSheet;
|
||||
int2 _previousCameraIntPosition = int2.zero;
|
||||
private List<Force> _forces = new List<Force>();
|
||||
|
||||
struct Force
|
||||
{
|
||||
public float2 Position;
|
||||
public float2 Vector;
|
||||
public float Exponent;
|
||||
}
|
||||
|
||||
static class Kernels
|
||||
{
|
||||
public const int Advect = 0;
|
||||
public const int Force = 1;
|
||||
public const int PSetup = 2;
|
||||
public const int PFinish = 3;
|
||||
public const int Jacobi1 = 4;
|
||||
public const int Jacobi2 = 5;
|
||||
public const int Adjust = 6;
|
||||
}
|
||||
|
||||
int ThreadCount { get { return (_resolution + 7) / 8; } }
|
||||
|
||||
int Resolution { get { return ThreadCount * 8; } }
|
||||
|
||||
// Vector field buffers
|
||||
static class VFB
|
||||
{
|
||||
public static RenderTexture V1;
|
||||
public static RenderTexture V2;
|
||||
public static RenderTexture V3;
|
||||
public static RenderTexture P1;
|
||||
public static RenderTexture P2;
|
||||
}
|
||||
|
||||
RenderTexture AllocateBuffer(int componentCount)
|
||||
{
|
||||
var format = RenderTextureFormat.ARGBHalf;
|
||||
if (componentCount == 1) format = RenderTextureFormat.RHalf;
|
||||
if (componentCount == 2) format = RenderTextureFormat.RGHalf;
|
||||
|
||||
var rt = new RenderTexture(Resolution, Resolution, 0, format);
|
||||
rt.enableRandomWrite = true;
|
||||
rt.Create();
|
||||
return rt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour implementation
|
||||
|
||||
public void AddForce(float2 position, float2 vector, float exponent)
|
||||
{
|
||||
_forces.Add(new Force { Position = position, Vector = vector, Exponent = exponent });
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
_resolution = Mathf.Max(_resolution, 8);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_shaderSheet = new Material(_shader);
|
||||
|
||||
VFB.V1 = AllocateBuffer(2);
|
||||
VFB.V2 = AllocateBuffer(2);
|
||||
VFB.V3 = AllocateBuffer(2);
|
||||
VFB.P1 = AllocateBuffer(1);
|
||||
VFB.P2 = AllocateBuffer(1);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Destroy(_shaderSheet);
|
||||
|
||||
Destroy(VFB.V1);
|
||||
Destroy(VFB.V2);
|
||||
Destroy(VFB.V3);
|
||||
Destroy(VFB.P1);
|
||||
Destroy(VFB.P2);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var dt = Time.deltaTime;
|
||||
var dx = 1.0f / Resolution;
|
||||
|
||||
var snapLength = _range / _resolution;
|
||||
|
||||
// Input point
|
||||
var cameraIntPosition = int2(
|
||||
(int)(_camera.position.x / snapLength),
|
||||
(int)(_camera.position.z / snapLength)
|
||||
);
|
||||
var cameraPosition = float2(
|
||||
cameraIntPosition.x * snapLength,
|
||||
cameraIntPosition.y * snapLength
|
||||
);
|
||||
Shader.SetGlobalVector("_FluidTransform", new Vector4(cameraPosition.x, cameraPosition.y, _range));
|
||||
|
||||
var delta = (float2)(cameraIntPosition - _previousCameraIntPosition) / Resolution;
|
||||
_compute.SetVector("Delta", new Vector4(delta.x,delta.y));
|
||||
_compute.SetFloat("Damping", _damping);
|
||||
_compute.SetTexture(Kernels.Adjust, "U_in", VFB.V1);
|
||||
_compute.SetTexture(Kernels.Adjust, "W_out", VFB.V3);
|
||||
_compute.Dispatch(Kernels.Adjust, ThreadCount, ThreadCount, 1);
|
||||
|
||||
// Common variables
|
||||
_compute.SetFloat("Time", Time.time);
|
||||
_compute.SetFloat("DeltaTime", dt);
|
||||
|
||||
// Advection
|
||||
_compute.SetTexture(Kernels.Advect, "U_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.Advect, "W_out", VFB.V2);
|
||||
_compute.Dispatch(Kernels.Advect, ThreadCount, ThreadCount, 1);
|
||||
|
||||
// Diffuse setup
|
||||
var dif_alpha = dx * dx / (_viscosity * dt);
|
||||
_compute.SetFloat("Alpha", dif_alpha);
|
||||
_compute.SetFloat("Beta", 4 + dif_alpha);
|
||||
Graphics.CopyTexture(VFB.V2, VFB.V1);
|
||||
_compute.SetTexture(Kernels.Jacobi2, "B2_in", VFB.V1);
|
||||
|
||||
// Jacobi iteration
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_in", VFB.V2);
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_out", VFB.V3);
|
||||
_compute.Dispatch(Kernels.Jacobi2, ThreadCount, ThreadCount, 1);
|
||||
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_out", VFB.V2);
|
||||
_compute.Dispatch(Kernels.Jacobi2, ThreadCount, ThreadCount, 1);
|
||||
}
|
||||
|
||||
float2 getUV(float2 pos, float2 camPos, float scale)
|
||||
{
|
||||
return -(pos-camPos)/scale + float2(.5f,.5f);
|
||||
}
|
||||
|
||||
// Add external forces
|
||||
foreach(var force in _forces)
|
||||
{
|
||||
var uv = getUV(force.Position, cameraIntPosition, _range);
|
||||
_compute.SetVector("ForceOrigin", new Vector4(uv.x,uv.y));
|
||||
_compute.SetFloat("ForceExponent", force.Exponent);
|
||||
_compute.SetTexture(Kernels.Force, "W_in", VFB.V2);
|
||||
_compute.SetTexture(Kernels.Force, "W_out", VFB.V3);
|
||||
_compute.SetVector("ForceVector", new Vector4(force.Vector.x,force.Vector.y));
|
||||
|
||||
_compute.Dispatch(Kernels.Force, ThreadCount, ThreadCount, 1);
|
||||
}
|
||||
|
||||
// Projection setup
|
||||
_compute.SetTexture(Kernels.PSetup, "W_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.PSetup, "DivW_out", VFB.V2);
|
||||
_compute.SetTexture(Kernels.PSetup, "P_out", VFB.P1);
|
||||
_compute.Dispatch(Kernels.PSetup, ThreadCount, ThreadCount, 1);
|
||||
|
||||
// Jacobi iteration
|
||||
_compute.SetFloat("Alpha", -dx * dx);
|
||||
_compute.SetFloat("Beta", 4);
|
||||
_compute.SetTexture(Kernels.Jacobi1, "B1_in", VFB.V2);
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_in", VFB.P1);
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_out", VFB.P2);
|
||||
_compute.Dispatch(Kernels.Jacobi1, ThreadCount, ThreadCount, 1);
|
||||
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_in", VFB.P2);
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_out", VFB.P1);
|
||||
_compute.Dispatch(Kernels.Jacobi1, ThreadCount, ThreadCount, 1);
|
||||
}
|
||||
|
||||
// Projection finish
|
||||
_compute.SetTexture(Kernels.PFinish, "W_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.PFinish, "P_in", VFB.P1);
|
||||
_compute.SetTexture(Kernels.PFinish, "U_out", VFB.V1);
|
||||
_compute.Dispatch(Kernels.PFinish, ThreadCount, ThreadCount, 1);
|
||||
|
||||
_previousCameraIntPosition = cameraIntPosition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public float2 Position;
|
||||
public float2 Vector;
|
||||
public float Exponent;
|
||||
}
|
||||
}
|
||||
|
||||
static class Kernels
|
||||
{
|
||||
public const int Advect = 0;
|
||||
public const int Force = 1;
|
||||
public const int PSetup = 2;
|
||||
public const int PFinish = 3;
|
||||
public const int Jacobi1 = 4;
|
||||
public const int Jacobi2 = 5;
|
||||
public const int Adjust = 6;
|
||||
}
|
||||
|
||||
int ThreadCount { get { return (_resolution + 7) / 8; } }
|
||||
|
||||
int Resolution { get { return ThreadCount * 8; } }
|
||||
|
||||
// Vector field buffers
|
||||
static class VFB
|
||||
{
|
||||
public static RenderTexture V1;
|
||||
public static RenderTexture V2;
|
||||
public static RenderTexture V3;
|
||||
public static RenderTexture P1;
|
||||
public static RenderTexture P2;
|
||||
}
|
||||
|
||||
RenderTexture AllocateBuffer(int componentCount)
|
||||
{
|
||||
var format = RenderTextureFormat.ARGBHalf;
|
||||
if (componentCount == 1) format = RenderTextureFormat.RHalf;
|
||||
if (componentCount == 2) format = RenderTextureFormat.RGHalf;
|
||||
|
||||
var rt = new RenderTexture(Resolution, Resolution, 0, format);
|
||||
rt.enableRandomWrite = true;
|
||||
rt.Create();
|
||||
return rt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour implementation
|
||||
|
||||
public void AddForce(float2 position, float2 vector, float exponent)
|
||||
{
|
||||
_forces.Add(new Force { Position = position, Vector = vector, Exponent = exponent });
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
_resolution = Mathf.Max(_resolution, 8);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_shaderSheet = new Material(_shader);
|
||||
|
||||
VFB.V1 = AllocateBuffer(2);
|
||||
VFB.V2 = AllocateBuffer(2);
|
||||
VFB.V3 = AllocateBuffer(2);
|
||||
VFB.P1 = AllocateBuffer(1);
|
||||
VFB.P2 = AllocateBuffer(1);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Destroy(_shaderSheet);
|
||||
|
||||
Destroy(VFB.V1);
|
||||
Destroy(VFB.V2);
|
||||
Destroy(VFB.V3);
|
||||
Destroy(VFB.P1);
|
||||
Destroy(VFB.P2);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var dt = max(Time.deltaTime, .01f);
|
||||
var dx = 1.0f / Resolution;
|
||||
|
||||
var snapLength = _range / _resolution;
|
||||
|
||||
// Input point
|
||||
var cameraIntPosition = int2(
|
||||
(int)(_camera.position.x / snapLength),
|
||||
(int)(_camera.position.z / snapLength)
|
||||
);
|
||||
var cameraPosition = float2(
|
||||
cameraIntPosition.x * snapLength,
|
||||
cameraIntPosition.y * snapLength
|
||||
);
|
||||
Shader.SetGlobalVector("_FluidTransform", new Vector4(cameraPosition.x, cameraPosition.y, _range));
|
||||
Shader.SetGlobalTexture("_FluidVelocity", VFB.V1);
|
||||
|
||||
var delta = (float2)(cameraIntPosition - _previousCameraIntPosition) / Resolution;
|
||||
_compute.SetVector("Delta", new Vector4(delta.x,delta.y));
|
||||
_compute.SetFloat("Damping", _damping);
|
||||
_compute.SetTexture(Kernels.Adjust, "U_in", VFB.V1);
|
||||
_compute.SetTexture(Kernels.Adjust, "W_out", VFB.V3);
|
||||
_compute.Dispatch(Kernels.Adjust, ThreadCount, ThreadCount, 1);
|
||||
|
||||
// Common variables
|
||||
_compute.SetFloat("Time", Time.time);
|
||||
_compute.SetFloat("DeltaTime", dt);
|
||||
|
||||
// Advection
|
||||
_compute.SetTexture(Kernels.Advect, "U_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.Advect, "W_out", VFB.V2);
|
||||
_compute.Dispatch(Kernels.Advect, ThreadCount, ThreadCount, 1);
|
||||
|
||||
// Diffuse setup
|
||||
var dif_alpha = dx * dx / (_viscosity * dt);
|
||||
_compute.SetFloat("Alpha", dif_alpha);
|
||||
_compute.SetFloat("Beta", 4 + dif_alpha);
|
||||
Graphics.CopyTexture(VFB.V2, VFB.V1);
|
||||
_compute.SetTexture(Kernels.Jacobi2, "B2_in", VFB.V1);
|
||||
|
||||
// Jacobi iteration
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_in", VFB.V2);
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_out", VFB.V3);
|
||||
_compute.Dispatch(Kernels.Jacobi2, ThreadCount, ThreadCount, 1);
|
||||
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.Jacobi2, "X2_out", VFB.V2);
|
||||
_compute.Dispatch(Kernels.Jacobi2, ThreadCount, ThreadCount, 1);
|
||||
}
|
||||
|
||||
float2 getUV(float2 pos, float2 camPos, float scale)
|
||||
{
|
||||
return -(pos-camPos)/scale + float2(.5f,.5f);
|
||||
}
|
||||
|
||||
// Add external forces
|
||||
foreach(var force in _forces)
|
||||
{
|
||||
var uv = getUV(force.Position, cameraIntPosition, _range);
|
||||
_compute.SetVector("ForceOrigin", new Vector4(uv.x,uv.y));
|
||||
_compute.SetFloat("ForceExponent", force.Exponent);
|
||||
_compute.SetTexture(Kernels.Force, "W_in", VFB.V2);
|
||||
_compute.SetTexture(Kernels.Force, "W_out", VFB.V3);
|
||||
_compute.SetVector("ForceVector", new Vector4(force.Vector.x,force.Vector.y));
|
||||
|
||||
_compute.Dispatch(Kernels.Force, ThreadCount, ThreadCount, 1);
|
||||
}
|
||||
|
||||
// Projection setup
|
||||
_compute.SetTexture(Kernels.PSetup, "W_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.PSetup, "DivW_out", VFB.V2);
|
||||
_compute.SetTexture(Kernels.PSetup, "P_out", VFB.P1);
|
||||
_compute.Dispatch(Kernels.PSetup, ThreadCount, ThreadCount, 1);
|
||||
|
||||
// Jacobi iteration
|
||||
_compute.SetFloat("Alpha", -dx * dx);
|
||||
_compute.SetFloat("Beta", 4);
|
||||
_compute.SetTexture(Kernels.Jacobi1, "B1_in", VFB.V2);
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_in", VFB.P1);
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_out", VFB.P2);
|
||||
_compute.Dispatch(Kernels.Jacobi1, ThreadCount, ThreadCount, 1);
|
||||
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_in", VFB.P2);
|
||||
_compute.SetTexture(Kernels.Jacobi1, "X1_out", VFB.P1);
|
||||
_compute.Dispatch(Kernels.Jacobi1, ThreadCount, ThreadCount, 1);
|
||||
}
|
||||
|
||||
// Projection finish
|
||||
_compute.SetTexture(Kernels.PFinish, "W_in", VFB.V3);
|
||||
_compute.SetTexture(Kernels.PFinish, "P_in", VFB.P1);
|
||||
_compute.SetTexture(Kernels.PFinish, "U_out", VFB.V1);
|
||||
_compute.Dispatch(Kernels.PFinish, ThreadCount, ThreadCount, 1);
|
||||
|
||||
_previousCameraIntPosition = cameraIntPosition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ uniform sampler2D _NebulaPatch;
|
|||
uniform sampler2D _NebulaPatchHeight;
|
||||
uniform sampler2D _NebulaTint;
|
||||
float4 _NebulaTint_TexelSize;
|
||||
uniform sampler2D _FluidVelocity;
|
||||
|
||||
uniform float3 _GridTransform;
|
||||
uniform float3 _FluidTransform;
|
||||
|
|
@ -105,6 +106,11 @@ float2 getUV(float2 pos)
|
|||
return -(pos-_GridTransform.xy)/_GridTransform.z + float2(.5,.5);
|
||||
}
|
||||
|
||||
float2 getUVFluid(float2 pos)
|
||||
{
|
||||
return (pos-_FluidTransform.xy)/_FluidTransform.z + float2(.5,.5);
|
||||
}
|
||||
|
||||
float cloudDensity(float3 pos, float surfaceDisp)
|
||||
{
|
||||
float2 uv = getUV(pos.xz);
|
||||
|
|
@ -118,11 +124,20 @@ float cloudDensity(float3 pos, float surfaceDisp)
|
|||
return patchDensity + max(0,floorDensity);
|
||||
}
|
||||
|
||||
float3 flow(float3 pos, out float noise)
|
||||
// TODO: Get this working?
|
||||
float2 flowTex(float3 pos)
|
||||
{
|
||||
const float2 fluidUv = getUVFluid(pos.xz);
|
||||
if(any(fluidUv<0)||any(fluidUv>1)) return 0;
|
||||
const float2 fluidSample = tex2Dlod(_FluidVelocity, half4(fluidUv, 0, 0)).xy;
|
||||
// TODO: remove magic number for fluid texture dimensions
|
||||
return float3(fluidSample.x,0,fluidSample.y) * (512 / _FluidTransform.z);
|
||||
}
|
||||
|
||||
float3 flow(float3 pos)
|
||||
{
|
||||
const float4 noiseSample1 = Value3D_Deriv( pos / _FlowScale - float3(0,_FlowScroll,0) );
|
||||
const float4 noiseSample2 = Value3D_Deriv( pos / (_FlowScale * 1.61803398875) - float3(0,_FlowScroll,0) ); // make it golden
|
||||
noise = noiseSample1.x;
|
||||
return cross(normalize(noiseSample2.yzw), normalize(noiseSample1.yzw)) * _FlowAmplitude;
|
||||
}
|
||||
|
||||
|
|
@ -138,17 +153,16 @@ float density(float3 pos)
|
|||
if(dist < _SafetyDistance)
|
||||
{
|
||||
const float heightFade = smoothstep(_SafetyDistance,_SafetyDistance*.75,dist);
|
||||
float noise;
|
||||
const float3 fl = flow(pos, noise);
|
||||
const float lerp1 = frac(_Time.y / _FlowPeriod + noise);
|
||||
const float lerp2 = frac(_Time.y / _FlowPeriod + .5 + noise);
|
||||
const float noise1 = pow(triNoise3d((pos+fl * lerp1 * _FlowPeriod) / _NebulaNoiseScale),_NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp1);
|
||||
const float noise2 = pow(triNoise3d((pos+fl * lerp2 * _FlowPeriod) / _NebulaNoiseScale),_NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp2);
|
||||
const float3 fl = flow(pos);
|
||||
const float lerp1 = frac(_Time.y / _FlowPeriod);
|
||||
const float lerp2 = frac(_Time.y / _FlowPeriod + .5);
|
||||
const float noise1 = pow(triNoise3d((pos+fl * (lerp1 - .5) * _FlowPeriod) / _NebulaNoiseScale),_NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp1);
|
||||
const float noise2 = pow(triNoise3d((pos+fl * (lerp2 - .5) * _FlowPeriod) / _NebulaNoiseScale),_NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp2);
|
||||
pos.y += (noise1 + noise2) * heightFade;
|
||||
const float lerp3 = frac(_Time.y / _FlowPeriod * 2);
|
||||
const float lerp4 = frac(_Time.y / _FlowPeriod * 2 + .5);
|
||||
const float noise3 = pow(triNoise3d((pos+fl * lerp3 * _FlowPeriod / 2) / _NebulaNoiseScale * 8), _NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp3) / 2;
|
||||
const float noise4 = pow(triNoise3d((pos+fl * lerp4 * _FlowPeriod / 2) / _NebulaNoiseScale * 8), _NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp4) / 2;
|
||||
const float lerp3 = frac(_Time.y / _FlowPeriod * 2 + .25);
|
||||
const float lerp4 = frac(_Time.y / _FlowPeriod * 2 + .75);
|
||||
const float noise3 = pow(triNoise3d((pos+fl * (lerp3 - .5) * _FlowPeriod / 2) / _NebulaNoiseScale * 8), _NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp3) / 2;
|
||||
const float noise4 = pow(triNoise3d((pos+fl * (lerp4 - .5) * _FlowPeriod / 2) / _NebulaNoiseScale * 8), _NebulaNoiseExponent) * _NebulaNoiseAmplitude * tri2(lerp4) / 2;
|
||||
pos.y -= (noise3 + noise4) * heightFade;
|
||||
d += cloudDensity(pos, surfaceDisp);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue