From 7a9af46820e2d4ecfe694eb2c12f193b8e724e9a Mon Sep 17 00:00:00 2001 From: Reinier Vens Date: Sun, 28 Mar 2021 03:17:55 +0100 Subject: [PATCH] Gravity Slime Adjusted the "slime" particles to adjust their parameters according to the current gravitational potential and gradient! --- Assets/Materials/Brushes/Fog Tint.mat | 4 +- Assets/Materials/Brushes/Gravity Waves.mat | 4 +- Assets/Materials/Brushes/Sector Tint Test.mat | 2 +- Assets/Scenes/TestScene.unity | 569 +++++++++++++++++- Assets/Scripts/ServerShared/Extensions.cs | 9 + Assets/Shaders/Compute/Slime/Slime.compute | 154 +++-- Assets/Shaders/Compute/Slime/Slime.cs | 79 ++- .../Compute/Slime/SlimeParticles.shader | 8 +- Assets/Shaders/Compute/Slime/SlimeTrails.mat | 4 +- .../Shaders/Compute/Slime/SlimeVertex.cginc | 1 + 10 files changed, 753 insertions(+), 81 deletions(-) diff --git a/Assets/Materials/Brushes/Fog Tint.mat b/Assets/Materials/Brushes/Fog Tint.mat index 06bd02ee6..bcf7c4eac 100644 --- a/Assets/Materials/Brushes/Fog Tint.mat +++ b/Assets/Materials/Brushes/Fog Tint.mat @@ -58,7 +58,7 @@ Material: m_Floats: - _BumpScale: 1 - _Cutoff: 0.5 - - _Depth: 0.33 + - _Depth: 1.3 - _DetailNormalMapScale: 1 - _DstBlend: 0 - _Frequency: 6.2832 @@ -70,7 +70,7 @@ Material: - _OcclusionStrength: 1 - _Parallax: 0.02 - _Phase: 0 - - _Power: 3 + - _Power: 8 - _SinePower: 1.25 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 diff --git a/Assets/Materials/Brushes/Gravity Waves.mat b/Assets/Materials/Brushes/Gravity Waves.mat index b36af0af8..a45dfed21 100644 --- a/Assets/Materials/Brushes/Gravity Waves.mat +++ b/Assets/Materials/Brushes/Gravity Waves.mat @@ -58,10 +58,10 @@ Material: m_Floats: - _BumpScale: 1 - _Cutoff: 0.5 - - _Depth: 20 + - _Depth: 3.5 - _DetailNormalMapScale: 1 - _DstBlend: 0 - - _Frequency: 6.2832 + - _Frequency: 27.43 - _GlossMapScale: 1 - _Glossiness: 0.5 - _GlossyReflections: 1 diff --git a/Assets/Materials/Brushes/Sector Tint Test.mat b/Assets/Materials/Brushes/Sector Tint Test.mat index ef2c3da21..e4543bf69 100644 --- a/Assets/Materials/Brushes/Sector Tint Test.mat +++ b/Assets/Materials/Brushes/Sector Tint Test.mat @@ -58,7 +58,7 @@ Material: m_Floats: - _BumpScale: 1 - _Cutoff: 0.5 - - _Depth: 0.25 + - _Depth: 0.4 - _DetailNormalMapScale: 1 - _DstBlend: 0 - _Frequency: 6.2832 diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index e64082f0f..14ac91b43 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -1474,6 +1474,115 @@ Transform: m_Father: {fileID: 1183010124} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &556481138 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 7852221720480299766, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_Name + value: Sun + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_RootOrder + value: 13 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.x + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.y + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.z + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.x + value: 250 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720741322892, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.x + value: 40 + objectReference: {fileID: 0} + - target: {fileID: 7852221720741322892, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.y + value: 40 + objectReference: {fileID: 0} + - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.x + value: 20 + objectReference: {fileID: 0} + - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.y + value: 20 + objectReference: {fileID: 0} + - target: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.y + value: -4 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 046dde0f4600bce41ad33c476f99b309, type: 3} --- !u!1 &652433663 GameObject: m_ObjectHideFlags: 0 @@ -3436,13 +3545,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1314993065} - m_LocalRotation: {x: 0.15998425, y: 0.38291913, z: -0.06751901, w: 0.9073143} - m_LocalPosition: {x: -57, y: -66, z: -289} + m_LocalRotation: {x: 0.17364816, y: 0, z: 0, w: 0.9848078} + m_LocalPosition: {x: 0, y: -65, z: -300} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 9 - m_LocalEulerAnglesHint: {x: 20, y: 45.763, z: 0} + m_LocalEulerAnglesHint: {x: 20, y: 0, z: 0} --- !u!1 &1328848282 GameObject: m_ObjectHideFlags: 0 @@ -4359,6 +4468,115 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1584275845} m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1001 &1673244484 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 7852221720480299766, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_Name + value: Sun (1) + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_RootOrder + value: 14 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.x + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.y + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.z + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.x + value: -250 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720480299767, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7852221720741322892, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.x + value: 40 + objectReference: {fileID: 0} + - target: {fileID: 7852221720741322892, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.y + value: 40 + objectReference: {fileID: 0} + - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.x + value: 20 + objectReference: {fileID: 0} + - target: {fileID: 7852221720969441490, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalScale.y + value: 20 + objectReference: {fileID: 0} + - target: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, + type: 3} + propertyPath: m_LocalPosition.y + value: -4 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 046dde0f4600bce41ad33c476f99b309, type: 3} --- !u!1 &1691202845 GameObject: m_ObjectHideFlags: 0 @@ -5401,6 +5619,11 @@ PrefabInstance: propertyPath: TargetCamera value: objectReference: {fileID: 1314993072} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: TrailDamping + value: 0.25 + objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: GravityCamera @@ -5409,7 +5632,7 @@ PrefabInstance: - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: TrailEndWidth - value: 0.1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} @@ -5424,12 +5647,12 @@ PrefabInstance: - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: NoiseFrequency - value: 0.5 + value: 1 objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: TrailStartWidth - value: 0.25 + value: 0.1 objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} @@ -5439,7 +5662,7 @@ PrefabInstance: - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: ParticleHeightRange - value: 0 + value: 50 objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} @@ -5459,7 +5682,7 @@ PrefabInstance: - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: ParticleHeightOffset - value: 23.77 + value: 10 objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} @@ -5471,11 +5694,341 @@ PrefabInstance: propertyPath: SlimeSettings.SensorSpread value: 0.5 objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.LowValue + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.LowValue + value: 128 + objectReference: {fileID: 0} - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: SlimeSettings.SensorDistance value: 12 objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.LowValue + value: 25 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.HighValue + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.HighValue + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.HighValue + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.SlopeBlend + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.SlopeBlend + value: 0.4 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.SlopeBlend + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.HeightBlend + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.HeightBlend + value: 10 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.HeightBlend + value: 0.01 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Diffusion.LowValue + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.LowValue + value: 10 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TurnSpeed.LowValue + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.LowValue + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Diffusion.HighValue + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.HighValue + value: 100 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TurnSpeed.HighValue + value: 64 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.SlopeThreshold + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.HighValue + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Diffusion.SlopeBlend + value: 0.3 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.SlopeThreshold + value: 0.4 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.SlopeBlend + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.SlopeThreshold + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TurnSpeed.SlopeBlend + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Decay.HeightThreshold + value: -125 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.SlopeBlend + value: 0.3 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Diffusion.HeightBlend + value: 0.01 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Drive.HeightThreshold + value: -100 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.HeightBlend + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorSpread.LowValue + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Speed.HeightThreshold + value: -100 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TrailDamping.LowValue + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TurnSpeed.HeightBlend + value: 0.01 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.HeightBlend + value: 50 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorSpread.HighValue + value: 0.1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TrailDamping.HighValue + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.LowValue + value: 64 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorSpread.SlopeBlend + value: 0.4 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TrailDamping.SlopeBlend + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Diffusion.SlopeThreshold + value: 0.3 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.SlopeThreshold + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.HighValue + value: 8 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorSpread.HeightBlend + value: 0.01 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TrailDamping.HeightBlend + value: 0.01 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TurnSpeed.SlopeThreshold + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.SlopeThreshold + value: 0.3 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Diffusion.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.HeightSlopeLerp + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Intensity.HeightThreshold + value: -150 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.SlopeBlend + value: 0.1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TurnSpeed.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.HeightSlopeLerp + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.Deposition.HeightThreshold + value: -150 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.HeightBlend + value: 15 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorSpread.SlopeThreshold + value: 0.4 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TrailDamping.SlopeThreshold + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorSpread.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.TrailDamping.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.SlopeThreshold + value: 0.2 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.HeightSlopeLerp + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5262902644310250487, guid: efd1f097ce29ffa48bb0045d6502f55d, + type: 3} + propertyPath: SlimeSettings.SensorDistance.HeightThreshold + value: -150 + objectReference: {fileID: 0} - target: {fileID: 6977256487485077368, guid: efd1f097ce29ffa48bb0045d6502f55d, type: 3} propertyPath: m_Name diff --git a/Assets/Scripts/ServerShared/Extensions.cs b/Assets/Scripts/ServerShared/Extensions.cs index a517ad079..c7805e576 100644 --- a/Assets/Scripts/ServerShared/Extensions.cs +++ b/Assets/Scripts/ServerShared/Extensions.cs @@ -24,6 +24,15 @@ public static class Extensions { return baseType.GetInterfaces().Any(interfaceType.Equals); } + + // https://stackoverflow.com/a/800469 + public static string GetHashSHA1(this byte[] data) + { + using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider()) + { + return string.Concat(sha1.ComputeHash(data).Select(x => x.ToString("X2"))); + } + } public static void Send(this NetPeer peer, T message, DeliveryMethod method = DeliveryMethod.ReliableOrdered) where T : Message { diff --git a/Assets/Shaders/Compute/Slime/Slime.compute b/Assets/Shaders/Compute/Slime/Slime.compute index 03736a85d..a60181402 100644 --- a/Assets/Shaders/Compute/Slime/Slime.compute +++ b/Assets/Shaders/Compute/Slime/Slime.compute @@ -20,8 +20,44 @@ struct Particle float3 start; float3 middle; float3 end; + float intensity; }; +struct SlimeParameter +{ + float HeightSlopeLerp; + float HeightThreshold; + float HeightBlend; + float SlopeThreshold; + float SlopeBlend; + float HighValue; + float LowValue; +}; + +struct SlimeSettings +{ + SlimeParameter Deposition; + SlimeParameter Diffusion; + SlimeParameter Decay; + SlimeParameter TurnSpeed; + SlimeParameter Speed; + SlimeParameter Drive; + SlimeParameter SensorDistance; + SlimeParameter SensorSpread; + SlimeParameter TrailDamping; + SlimeParameter Intensity; +}; + +float evaluate(SlimeParameter param, float height, float slope) +{ + return lerp( + lerp(param.LowValue, param.HighValue, smoothstep(param.HeightThreshold - param.HeightBlend, param.HeightThreshold + param.HeightBlend, height)), + lerp(param.LowValue, param.HighValue, smoothstep(param.SlopeThreshold - param.SlopeBlend, param.SlopeThreshold + param.SlopeBlend, slope)), param.HeightSlopeLerp); +} + +// Parameter buffer +RWStructuredBuffer parameters; + // Accumulation Buffer RWTexture2D accumulation; @@ -37,19 +73,9 @@ SamplerState samplerHeightmap; int randomOffset; int numAgents; -float speed; -//float deltaTime; +float deltaTime; int textureWidth; float zoneRadius; -float deposition; -float diffusion; -float decay; -float sensorDistance; -float sensorSpread; -int sensorSize; -float randomSteering; -float turnSpeed; -float drive; // Hash function from H. Schechter & R. Bridson, goo.gl/RXiKaH inline uint hash(uint s) @@ -78,16 +104,16 @@ inline float2 posToUv(float2 pos) return pos / (zoneRadius * 2) + float2(.5, .5); } -float sense(float2 position, float angle, float directionSign) +float sense(int2 position, float angle, float directionSign, float spread, float distance) { - float sensorAngle = angle + directionSign * sensorSpread; + float sensorAngle = angle + directionSign * spread; float2 sensorDir = float2(cos(sensorAngle), sin(sensorAngle)); - int2 sensorCenter = position + sensorDir * sensorDistance; + int2 sensorCenter = position + sensorDir * distance; float sum = 0; - for(int x = -sensorSize; x <= sensorSize; x++) + for(int x = -1; x <= 1; x++) { - for(int y = -sensorSize; y <= sensorSize; y++) + for(int y = -1; y <= 1; y++) { int2 sample = sensorCenter + int2(x, y); if(sample.x >= 0 && sample.x < textureWidth && sample.y >= 0 && sample.y < textureWidth) @@ -104,39 +130,62 @@ inline float unlerp(float x, float min, float max) return (x - min) / (max - min); } +// Z-up normal of the heightmap +float3 GetNormal(int2 pos) +{ + if(pos.x >= textureWidth || pos.y >= textureWidth) return float3(0, 0, 1); + + float e = -Heightmap[pos + int2(1, 0)]; + float n = -Heightmap[pos + int2(0, 1)]; + float me = -Heightmap[pos]; + + // Deduce terrain normal + float3 normal = float3(e - me, n - me, 1.0 / textureWidth * zoneRadius * 2); + return normalize(normal); +} + [numthreads(NUM_THREAD_X,1,1)] void UpdateAgents (uint3 id : SV_DispatchThreadID) { if (id.x >= numAgents) return; Agent agent = agents[id.x]; + SlimeSettings settings = parameters[0]; + + float2 uv = posToUv(agent.position); + int2 texPos = int2(uv * textureWidth); + + float height = -Heightmap[texPos];//.SampleLevel(samplerHeightmap, uv, 0); + float3 normal = GetNormal(texPos); + float slope = acos(dot(normal, float3(0,0,1))) / UNITY_HALF_PI; // Move Agents based on direction and speed float2 direction = float2(cos(agent.angle), sin(agent.angle)); - agent.position += direction * speed; + agent.position += direction * evaluate(settings.Speed, height, slope) * deltaTime; float r = random(id.x + randomOffset); // Clamp position within bounds and randomize direction - if(dot(agent.position, agent.position) > zoneRadius * zoneRadius || isnan(agent.position.x)) + if(dot(agent.position, agent.position) > zoneRadius * zoneRadius) { agent.position = normalize(agent.position) * zoneRadius; //agent.position = float2(0,0); agent.angle = r * UNITY_TWO_PI; } - // if(isnan(agent.position.x)) - // { - // agent.position = float2(0,0); - // agent.angle = r * UNITY_TWO_PI; - // } + if(isnan(agent.position.x)) + { + agent.position = float2(0,0); + agent.angle = r * UNITY_TWO_PI; + } - float2 texPos = posToUv(agent.position) * textureWidth; + float spread = evaluate(settings.SensorSpread, height, slope); + float distance = evaluate(settings.SensorDistance, height, slope); // Acquire sensory data - float forwardSensor = sense(texPos, agent.angle, 0); - float leftSensor = sense(texPos, agent.angle, -1); - float rightSensor = sense(texPos, agent.angle, 1); + float forwardSensor = sense(texPos, agent.angle, 0, spread, distance); + float leftSensor = sense(texPos, agent.angle, -1, spread, distance); + float rightSensor = sense(texPos, agent.angle, 1, spread, distance); // Determine the range of the sensor inputs float minSensor = min(min(leftSensor, rightSensor), forwardSensor); @@ -144,7 +193,7 @@ void UpdateAgents (uint3 id : SV_DispatchThreadID) float range = min(maxSensor - minSensor, .01); // Normalize sensor inputs - forwardSensor = unlerp(forwardSensor, minSensor, maxSensor); + //forwardSensor = unlerp(forwardSensor, minSensor, maxSensor); leftSensor = unlerp(leftSensor, minSensor, maxSensor); rightSensor = unlerp(rightSensor, minSensor, maxSensor); @@ -152,12 +201,12 @@ void UpdateAgents (uint3 id : SV_DispatchThreadID) float desire = leftSensor - rightSensor; // Strength of its directional preference - float motivation = pow(range / maxSensor, 1 / drive); + float motivation = pow(range / maxSensor, 1 / evaluate(settings.Drive, height, slope)); - agent.angle += turnSpeed * lerp(r * 2 - 1, desire, motivation); + agent.angle += evaluate(settings.TurnSpeed, height, slope) * lerp(r * 2 - 1, desire, motivation) * deltaTime; agents[id.x] = agent; - accumulation[int2(texPos)] += deposition; + accumulation[texPos] += evaluate(settings.Deposition, height, slope) * deltaTime; } [numthreads(8,8,1)] @@ -167,6 +216,11 @@ void Diffuse (uint3 id : SV_DispatchThreadID) float previous = accumulation[id.xy]; + SlimeSettings settings = parameters[0]; + float height = -Heightmap[id.xy]; + float3 normal = GetNormal(id.xy); + float slope = acos(dot(normal, float3(0,0,1))) / UNITY_HALF_PI; + float sum = 0; for(int x = -1; x <= 1; x++) { @@ -181,7 +235,7 @@ void Diffuse (uint3 id : SV_DispatchThreadID) } float average = sum / 9; - diffusedAccumulation[id.xy] = lerp(previous, average, diffusion) * decay; + diffusedAccumulation[id.xy] = lerp(previous, average, saturate(evaluate(settings.Diffusion, height, slope) * deltaTime)) * saturate(1-evaluate(settings.Decay, height, slope) * deltaTime); } // Buffer containing the leading position of the agent particle @@ -195,7 +249,6 @@ float noiseAmplitude; float time; float heightRange; float heightOffset; -float trailDamping; int particleCount; #define HASHSCALE 0.1031 @@ -224,16 +277,37 @@ float perlinNoise1D(float p) void CreateAgentParticles (uint3 id : SV_DispatchThreadID) { Agent agent = agents[id.x]; + + float2 uv = posToUv(agent.position); + int2 texPos = int2(uv * textureWidth); + + SlimeSettings settings = parameters[0]; + float height = -Heightmap[texPos]; + float3 normal = GetNormal(texPos); + float slope = acos(dot(normal, float3(0,0,1))) / UNITY_HALF_PI; + float sequence = (float)id.x/particleCount; - float height = Heightmap.SampleLevel(samplerHeightmap, posToUv(agent.position), 0); - float particleHeight = -height + random(id.x) * heightRange + heightOffset; + //float height = -Heightmap.SampleLevel(samplerHeightmap, posToUv(agent.position), 0); + float particleHeight = height + pow(random(id.x)-.5, 3) * heightRange + heightOffset; Particle particle = particles[id.x]; - particle.end = lerp(particle.end, particle.middle, trailDamping); - particle.middle = lerp(particle.middle, particle.start, trailDamping); - particle.start = lerp(particle.start, float3( + float damping = evaluate(settings.TrailDamping, height, pow(slope, .25)); + float3 targetPosition = float3( agent.position.x + perlinNoise1D(id.x*3 + time + sequence) * noiseAmplitude, particleHeight + perlinNoise1D(id.x*3 + 1 + time + sequence) * noiseAmplitude, - agent.position.y + perlinNoise1D(id.x*3 + 2 + time + sequence) * noiseAmplitude), trailDamping); + agent.position.y + perlinNoise1D(id.x*3 + 2 + time + sequence) * noiseAmplitude); + if(length(particle.start-targetPosition) > 256) + { + particle.end = targetPosition; + particle.middle = targetPosition; + particle.start = targetPosition; + } + else + { + particle.end = lerp(particle.end, particle.middle, damping/4); + particle.middle = lerp(particle.middle, particle.start, damping/2); + particle.start = lerp(particle.start, targetPosition, damping); + } + particle.intensity = evaluate(settings.Intensity, height, slope); particles[id.x] = particle; } @@ -291,9 +365,11 @@ void CreateParticleGeometry (uint3 id : SV_DispatchThreadID) v0.pos = pos - right; v0.uv = float2(trailLerp, 0); + v0.intensity = particle.intensity; v1.pos = pos + right; v1.uv = float2(trailLerp, 1); + v1.intensity = particle.intensity; uint vId = idx * 2; vertexBuffer[vId] = v0; diff --git a/Assets/Shaders/Compute/Slime/Slime.cs b/Assets/Shaders/Compute/Slime/Slime.cs index 2f7fa5dde..989fe946f 100644 --- a/Assets/Shaders/Compute/Slime/Slime.cs +++ b/Assets/Shaders/Compute/Slime/Slime.cs @@ -46,6 +46,7 @@ public class Slime : MonoBehaviour private int _diffuseKernel; private int _particleKernel; private int _geometryKernel; + private string _settingsHash; private int IndexBufferSize => ParticleCount * 6 * (TrailPoints - 1); @@ -56,7 +57,8 @@ public class Slime : MonoBehaviour private ComputeBuffer _agentsBuffer; private RenderTexture _accumulationTexture; private RenderTexture _previousAccumulationTexture; - + + private ComputeBuffer _parameterBuffer; private ComputeBuffer _particlesBuffer; private ComputeBuffer _indexBuffer; @@ -77,12 +79,14 @@ public class Slime : MonoBehaviour public Vector3 Start; public Vector3 Middle; public Vector3 End; + public float Intensity; } struct Vertex { public Vector3 Position; public Vector2 UV; + public float Intensity; } #endregion @@ -111,7 +115,9 @@ public class Slime : MonoBehaviour }; } _agentsBuffer.SetData(agents); - + + _parameterBuffer = new ComputeBuffer(1, Marshal.SizeOf(typeof(SlimeSettings))); + _particlesBuffer = new ComputeBuffer(ParticleCount, Marshal.SizeOf(typeof(Particle))); _vertexBuffer = new ComputeBuffer(ParticleCount * 2 * TrailPoints, Marshal.SizeOf(typeof(Vertex))); @@ -137,25 +143,30 @@ public class Slime : MonoBehaviour _indexBuffer.SetData(indexData); } + void UpdateSettings() + { + RegisterResolver.Register(); + var hash = MessagePackSerializer.Serialize(SlimeSettings).GetHashSHA1(); + if(hash != _settingsHash) + { + _settingsHash = hash; + _parameterBuffer.SetData(new[] {SlimeSettings}); + } + } + // Update is called once per frame void Update() { + UpdateSettings(); + SlimeCompute.SetInt("randomOffset", Random.Range(0,65536)); SlimeCompute.SetInt("textureWidth", TextureSize); SlimeCompute.SetInt("numAgents", AgentCount); SlimeCompute.SetFloat("zoneRadius", ZoneRadius); - SlimeCompute.SetFloat("deposition", SlimeSettings.Deposition * Time.deltaTime); - SlimeCompute.SetFloat("diffusion", SlimeSettings.Diffusion * Time.deltaTime); - SlimeCompute.SetFloat("decay", max(1 - SlimeSettings.Decay * Time.deltaTime, 0.01f)); - SlimeCompute.SetFloat("speed", SlimeSettings.Speed * Time.deltaTime); - SlimeCompute.SetFloat("turnSpeed", SlimeSettings.TurnSpeed * Time.deltaTime); - SlimeCompute.SetFloat("randomSteering", SlimeSettings.RandomSteering); - SlimeCompute.SetFloat("sensorDistance", SlimeSettings.SensorDistance); - SlimeCompute.SetFloat("drive", SlimeSettings.Drive); - SlimeCompute.SetFloat("sensorSpread", SlimeSettings.SensorSpread * Mathf.PI / 2); - SlimeCompute.SetInt("sensorSize", SlimeSettings.SensorSize); + SlimeCompute.SetFloat("deltaTime", Time.deltaTime); SlimeCompute.SetBuffer(_updateAgentsKernel, "agents", _agentsBuffer); + SlimeCompute.SetBuffer(_updateAgentsKernel, "parameters", _parameterBuffer); SlimeCompute.SetTexture(_updateAgentsKernel, "accumulation", _accumulationTexture); SlimeCompute.SetTexture(_updateAgentsKernel, "Heightmap", GravityTexture); @@ -163,11 +174,14 @@ public class Slime : MonoBehaviour SlimeCompute.Dispatch(_updateAgentsKernel, numberOfGroups, 1, 1); Graphics.Blit(_accumulationTexture, _previousAccumulationTexture); + SlimeCompute.SetBuffer(_diffuseKernel, "parameters", _parameterBuffer); + SlimeCompute.SetTexture(_diffuseKernel, "Heightmap", GravityTexture); SlimeCompute.SetTexture(_diffuseKernel, "accumulation", _previousAccumulationTexture); SlimeCompute.SetTexture(_diffuseKernel, "diffusedAccumulation", _accumulationTexture); numberOfGroups = Mathf.CeilToInt((float)TextureSize / 8); SlimeCompute.Dispatch(_diffuseKernel, numberOfGroups, numberOfGroups, 1); + SlimeCompute.SetBuffer(_particleKernel, "parameters", _parameterBuffer); SlimeCompute.SetTexture(_particleKernel, "Heightmap", GravityTexture); SlimeCompute.SetBuffer(_particleKernel, "agents", _agentsBuffer); SlimeCompute.SetBuffer(_particleKernel, "particles", _particlesBuffer); @@ -214,16 +228,35 @@ public class Slime : MonoBehaviour } [Serializable, MessagePackObject(keyAsPropertyName:true)] -public class SlimeSettings +public struct SlimeSettings { - public float Deposition; - public float Diffusion; - public float Decay; - public float TurnSpeed; - public float RandomSteering; - public float Speed; - public float Drive; - public float SensorDistance; - public float SensorSpread; - public int SensorSize; + public SlimeParameter Deposition; + public SlimeParameter Diffusion; + public SlimeParameter Decay; + public SlimeParameter TurnSpeed; + public SlimeParameter Speed; + public SlimeParameter Drive; + public SlimeParameter SensorDistance; + public SlimeParameter SensorSpread; + public SlimeParameter TrailDamping; + public SlimeParameter Intensity; +} + +[Serializable, MessagePackObject(keyAsPropertyName:true)] +public struct SlimeParameter +{ + public float HeightSlopeLerp; + public float HeightThreshold; + public float HeightBlend; + public float SlopeThreshold; + public float SlopeBlend; + public float HighValue; + public float LowValue; + + public float Evaluate(float height, float slope) + { + var heightValue = lerp(LowValue, HighValue, smoothstep(HeightThreshold - HeightBlend, HeightThreshold + HeightBlend, height)); + var slopeValue = lerp(LowValue, HighValue, smoothstep(SlopeThreshold - SlopeBlend, SlopeThreshold + SlopeBlend, slope)); + return lerp(heightValue, slopeValue, HeightSlopeLerp); + } } diff --git a/Assets/Shaders/Compute/Slime/SlimeParticles.shader b/Assets/Shaders/Compute/Slime/SlimeParticles.shader index f14a99af8..4a810c78b 100644 --- a/Assets/Shaders/Compute/Slime/SlimeParticles.shader +++ b/Assets/Shaders/Compute/Slime/SlimeParticles.shader @@ -46,7 +46,7 @@ Pass{ Out.pos = UnityObjectToClipPos(float4(vtx.pos, 1.0)); Out.uv = vtx.uv; - Out.col = lerp(_StartColor, _EndColor, vtx.uv.x); + Out.col = float4(lerp(_StartColor, _EndColor, vtx.uv.x).xyz, vtx.intensity); Out.screenPos = ComputeScreenPos(float4(vtx.pos, 1.0)); return Out; @@ -57,7 +57,7 @@ Pass{ // Simple quadratic curve "texture" float x = 1 - 2 * abs(In.uv.y - .5); //return float4(x,In.uv.x, 0 ,1); - float i = x * x * smoothstep(0, _Roundedness, In.uv.x) * (1-In.uv.x) * _Intensity; + float i = x * x * smoothstep(0, _Roundedness, In.uv.x) * (1-In.uv.x) * _Intensity * In.col.a; // Apply screen space dithering float2 screenUV = In.screenPos.xy / In.screenPos.w; @@ -107,7 +107,7 @@ Pass{ Out.pos = UnityObjectToClipPos(float4(vtx.pos, 1.0)); Out.uv = vtx.uv; - Out.col = 1; + Out.col = vtx.intensity; Out.screenPos = ComputeScreenPos(float4(vtx.pos, 1.0)); return Out; @@ -117,7 +117,7 @@ Pass{ { // Simple quadratic curve "texture" float x = 1 - 2 * abs(In.uv.y - .5); - float i = x * x * smoothstep(0, _Roundedness, In.uv.x) * (1-In.uv.x) * _Intensity; + float i = x * x * smoothstep(0, _Roundedness, In.uv.x) * (1-In.uv.x) * _Intensity * In.col.a; // Apply screen space dithering float2 screenUV = In.screenPos.xy / In.screenPos.w; diff --git a/Assets/Shaders/Compute/Slime/SlimeTrails.mat b/Assets/Shaders/Compute/Slime/SlimeTrails.mat index 8f8425369..d981acff5 100644 --- a/Assets/Shaders/Compute/Slime/SlimeTrails.mat +++ b/Assets/Shaders/Compute/Slime/SlimeTrails.mat @@ -63,7 +63,7 @@ Material: - _GlossMapScale: 1 - _Glossiness: 0.5 - _GlossyReflections: 1 - - _Intensity: 24.1 + - _Intensity: 10 - _Metallic: 0 - _Mode: 0 - _OcclusionStrength: 1 @@ -77,6 +77,6 @@ Material: m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - - _EndColor: {r: 0.5849056, g: 0.19037023, b: 0.40103197, a: 1} + - _EndColor: {r: 0.90588236, g: 0.089682385, b: 0.5242822, a: 1} - _StartColor: {r: 0.9339623, g: 0.31624126, b: 0.13656995, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Shaders/Compute/Slime/SlimeVertex.cginc b/Assets/Shaders/Compute/Slime/SlimeVertex.cginc index 96e020668..4fccd8115 100644 --- a/Assets/Shaders/Compute/Slime/SlimeVertex.cginc +++ b/Assets/Shaders/Compute/Slime/SlimeVertex.cginc @@ -5,6 +5,7 @@ struct Vertex { float3 pos; float2 uv; + float intensity; }; inline Vertex GetDefaultVertex() {