Skip to content

Commit

Permalink
Added initial spread parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Jun 7, 2017
1 parent fb60963 commit a2912ee
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Assets/Swarm/CrawlingSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public VolumeData volume {
get { return _volume; }
}

[SerializeField] float _initialSpread = 0.4f;

public float initialSpread {
get { return _initialSpread; }
set { _initialSpread = value; }
}

[SerializeField] float _noiseFrequency = 4;

public float noiseFrequency {
Expand Down Expand Up @@ -155,6 +162,7 @@ void Start()
_compute.SetInt("InstanceCount", InstanceCount);
_compute.SetInt("HistoryLength", HistoryLength);
_compute.SetFloat("RandomSeed", _randomSeed);
_compute.SetFloat("InitialSpread", _initialSpread);
_compute.SetTexture(kernel, "DFVolume", _volume.texture);
_compute.SetBuffer(kernel, "PositionBuffer", _positionBuffer);
_compute.SetBuffer(kernel, "TangentBuffer", _tangentBuffer);
Expand Down
7 changes: 5 additions & 2 deletions Assets/Swarm/Editor/CrawlingSwarmEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class CrawlingSwarmEditor : Editor
SerializedProperty _template;
SerializedProperty _radius;

SerializedProperty _volume;
SerializedProperty _speed;
SerializedProperty _volume;
SerializedProperty _initialSpread;
SerializedProperty _noiseFrequency;
SerializedProperty _noiseSpread;
SerializedProperty _noiseMotion;
Expand All @@ -38,8 +39,9 @@ void OnEnable()
_template = serializedObject.FindProperty("_template");
_radius = serializedObject.FindProperty("_radius");

_volume = serializedObject.FindProperty("_volume");
_speed = serializedObject.FindProperty("_speed");
_volume = serializedObject.FindProperty("_volume");
_initialSpread = serializedObject.FindProperty("_initialSpread");
_noiseFrequency = serializedObject.FindProperty("_noiseFrequency");
_noiseSpread = serializedObject.FindProperty("_noiseSpread");
_noiseMotion = serializedObject.FindProperty("_noiseMotion");
Expand All @@ -62,6 +64,7 @@ public override void OnInspectorGUI()

EditorGUILayout.PropertyField(_speed);
EditorGUILayout.PropertyField(_volume);
EditorGUILayout.PropertyField(_initialSpread);
EditorGUILayout.LabelField("Noise Field");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_noiseFrequency, Labels.frequency);
Expand Down
5 changes: 3 additions & 2 deletions Assets/Swarm/Shader/CrawlingSwarm.compute
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CBUFFER_START(Params)
uint InstanceCount;
uint HistoryLength;
float RandomSeed;
float InitialSpread;
uint IndexOffset0;
uint IndexOffset1;
uint IndexOffset2;
Expand Down Expand Up @@ -55,8 +56,8 @@ float4 SampleVolume(float3 p)
void CrawlingInit(uint id : SV_DispatchThreadID)
{
// Pick two random points and use closer one.
float3 p1 = RandomPoint(id + 0.0) / 3;
float3 p2 = RandomPoint(id + 0.5) / 3;
float3 p1 = RandomPoint(id + 0.0) * InitialSpread;
float3 p2 = RandomPoint(id + 0.5) * InitialSpread;
float d1 = SampleVolume(p1).w;
float d2 = SampleVolume(p2).w;
float3 p = d1 < d2 ? p1 : p2;
Expand Down
1 change: 1 addition & 0 deletions Assets/Test/Test (Crawling).unity
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ MonoBehaviour:
_radius: 0.005
_speed: 0.7
_volume: {fileID: 11400000, guid: 33827603f26d861438dab734dfca23e1, type: 2}
_initialSpread: 0.25
_noiseFrequency: 4
_noiseSpread: 0.25
_noiseMotion: 0.1
Expand Down

0 comments on commit a2912ee

Please sign in to comment.