Skip to content

Commit

Permalink
Added random seed to SwirlingSwarm
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Jun 6, 2017
1 parent 5e33449 commit bcb0816
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Assets/Swarm/Editor/SwirlingSwarmEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class SwirlingSwarmEditor : Editor
SerializedProperty _material;
SerializedProperty _gradient;

SerializedProperty _randomSeed;

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

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

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

public override void OnInspectorGUI()
Expand All @@ -64,6 +68,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/SwirlingSwarm.compute
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ StructuredBuffer<float4> PositionBufferRO;
CBUFFER_START(Params)
uint InstanceCount;
uint HistoryLength;
float RandomSeed;
float Spread;
float StepWidth;
float NoiseFrequency;
Expand All @@ -24,7 +25,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
13 changes: 13 additions & 0 deletions Assets/Swarm/SwirlingSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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 @@ -140,6 +150,8 @@ void OnEnable()
_props = new MaterialPropertyBlock();
_props.SetFloat("_UniqueID", Random.value);
}

_noiseOffset = Vector3.one * _randomSeed;
}

void OnDisable()
Expand All @@ -161,6 +173,7 @@ void Update()

_compute.SetInt("InstanceCount", InstanceCount);
_compute.SetInt("HistoryLength", HistoryLength);
_compute.SetFloat("RandomSeed", _randomSeed);
_compute.SetFloat("Spread", _spread);
_compute.SetFloat("StepWidth", _length / _template.segments);
_compute.SetFloat("NoiseFrequency", _noiseFrequency);
Expand Down
1 change: 1 addition & 0 deletions Assets/Test/Test (Swirling).unity
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ MonoBehaviour:
_noiseMotion: {x: 0, y: 0.04, z: 0}
_material: {fileID: 2100000, guid: b3e73ed1912d1474f998247575b31fe5, type: 2}
_gradient: {fileID: 11400000, guid: 202a0875a5bc2554a932e60d8ed7e7ec, type: 2}
_randomSeed: 123
_compute: {fileID: 7200000, guid: 70e8fc98ef3d1974485d153a4e66dbcc, type: 3}
--- !u!4 &1575138651
Transform:
Expand Down

0 comments on commit bcb0816

Please sign in to comment.