Skip to content

Commit

Permalink
Added random seed to crawling swarm.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Jun 6, 2017
1 parent bcb0816 commit 650e70f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Assets/Swarm/CrawlingSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public CosineGradient gradient {

#endregion

#region Misc properties

[SerializeField] int _randomSeed;

public int randomSeed {
set { _randomSeed = value; }
}

#endregion

#region Hidden attributes

[SerializeField, HideInInspector] ComputeShader _compute;
Expand Down Expand Up @@ -144,6 +154,7 @@ void Start()
var kernel = _compute.FindKernel("CrawlingInit");
_compute.SetInt("InstanceCount", InstanceCount);
_compute.SetInt("HistoryLength", HistoryLength);
_compute.SetFloat("RandomSeed", _randomSeed);
_compute.SetTexture(kernel, "DFVolume", _volume.texture);
_compute.SetBuffer(kernel, "PositionBuffer", _positionBuffer);
_compute.SetBuffer(kernel, "TangentBuffer", _tangentBuffer);
Expand Down
6 changes: 6 additions & 0 deletions Assets/Swarm/Editor/CrawlingSwarmEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class CrawlingSwarmEditor : Editor
SerializedProperty _material;
SerializedProperty _gradient;

SerializedProperty _randomSeed;

static class Labels
{
public static GUIContent frequency = new GUIContent("Frequency");
Expand All @@ -44,6 +46,8 @@ void OnEnable()

_material = serializedObject.FindProperty("_material");
_gradient = serializedObject.FindProperty("_gradient");

_randomSeed = serializedObject.FindProperty("_randomSeed");
}

public override void OnInspectorGUI()
Expand All @@ -68,6 +72,8 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_material);
EditorGUILayout.PropertyField(_gradient);

EditorGUILayout.PropertyField(_randomSeed);

serializedObject.ApplyModifiedProperties();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Swarm/Shader/CrawlingSwarm.compute
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SamplerState samplerDFVolume;
CBUFFER_START(Params)
uint InstanceCount;
uint HistoryLength;
float RandomSeed;
uint IndexOffset0;
uint IndexOffset1;
uint IndexOffset2;
Expand All @@ -32,7 +33,7 @@ CBUFFER_END

float Random(float u, float v)
{
float f = dot(float2(12.9898, 78.233), float2(u, v));
float f = dot(float2(12.9898, 78.233), float2(u, v)) + RandomSeed;
return frac(43758.5453 * sin(f));
}

Expand Down
3 changes: 2 additions & 1 deletion Assets/Test/Test (Crawling).unity
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ GameObject:
- component: {fileID: 1452801457}
- component: {fileID: 1452801456}
m_Layer: 0
m_Name: Crawler Swarm
m_Name: Crawling Swarm
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand All @@ -363,6 +363,7 @@ MonoBehaviour:
_noiseMotion: 0.1
_material: {fileID: 2100000, guid: b3e3f432bd29ac1499686dbad7ae39ef, type: 2}
_gradient: {fileID: 11400000, guid: 202a0875a5bc2554a932e60d8ed7e7ec, type: 2}
_randomSeed: 100
_compute: {fileID: 7200000, guid: e579db230e141ad4baa8636ac84ed1ef, type: 3}
--- !u!4 &1452801457
Transform:
Expand Down

0 comments on commit 650e70f

Please sign in to comment.