Skip to content

Commit

Permalink
Added bounds to cloners.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Jun 14, 2017
1 parent 05da940 commit 09dfc65
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
36 changes: 30 additions & 6 deletions Assets/Cloner/ClonerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public CosineGradient gradient {

#region Misc properties

[SerializeField] Bounds _bounds =
new Bounds(Vector3.zero, Vector3.one * 10);

public Bounds bounds {
get { return _bounds; }
set { _bounds = value; }
}

[SerializeField] int _randomSeed;

public int randomSeed {
Expand All @@ -134,7 +142,6 @@ public int randomSeed {
ComputeBuffer _transformBuffer;
bool _materialCloned;
MaterialPropertyBlock _props;
Bounds _bounds;
Vector3 _noiseOffset;
float _pulseTimer;

Expand Down Expand Up @@ -165,6 +172,13 @@ int InstanceCount {

#region MonoBehaviour functions

void OnValidate()
{
_noiseFrequency = Mathf.Max(0, _noiseFrequency);
_pulseFrequency = Mathf.Max(0, _pulseFrequency);
_bounds.size = Vector3.Max(Vector3.zero, _bounds.size);
}

void Start()
{
// Initialize the indirect draw args buffer.
Expand All @@ -180,7 +194,7 @@ void Start()
_positionBuffer = _pointSource.CreatePositionBuffer();
_normalBuffer = _pointSource.CreateNormalBuffer();
_tangentBuffer = _pointSource.CreateTangentBuffer();
_transformBuffer = new ComputeBuffer(InstanceCount, 3 * 4 * 4);
_transformBuffer = new ComputeBuffer(InstanceCount * 3, 4 * 4);

// This property block is used only for avoiding an instancing bug.
_props = new MaterialPropertyBlock();
Expand All @@ -194,10 +208,6 @@ void Start()
_material = new Material(_material);
_material.name += " (cloned)";
_materialCloned = true;

// Slightly expand the bounding box.
_bounds = _pointSource.bounds;
_bounds.Expand(_bounds.extents * 0.25f);
}

void OnDestroy()
Expand Down Expand Up @@ -258,6 +268,20 @@ void Update()
_pulseTimer += _pulseFrequency * Time.deltaTime;
}

void OnDrawGizmos()
{
Gizmos.color = new Color(0, 1, 1, 0.3f);
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(_bounds.center, _bounds.size);
}

void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(_bounds.center, _bounds.size);
}

#endregion
}
}
4 changes: 4 additions & 0 deletions Assets/Cloner/Editor/ClonerRendererEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed class ClonerRendererEditor : Editor
SerializedProperty _material;
SerializedProperty _gradient;

SerializedProperty _bounds;
SerializedProperty _randomSeed;

static class Labels
Expand Down Expand Up @@ -56,6 +57,7 @@ void OnEnable()
_material = serializedObject.FindProperty("_material");
_gradient = serializedObject.FindProperty("_gradient");

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

Expand Down Expand Up @@ -87,6 +89,8 @@ public override void OnInspectorGUI()

EditorGUILayout.PropertyField(_material);
EditorGUILayout.PropertyField(_gradient);

EditorGUILayout.PropertyField(_bounds);
EditorGUILayout.PropertyField(_randomSeed);

serializedObject.ApplyModifiedProperties();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Cloner/Shaders/Cloner.shader
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Shader "Cloner/Surface"

// Retrieve a transformation from TransformBuffer.
float4 ps = _TransformBuffer[id + _InstanceCount * 0];
float3 bx = _TransformBuffer[id + _InstanceCount * 1];
float3 by = _TransformBuffer[id + _InstanceCount * 2];
float3 bx = _TransformBuffer[id + _InstanceCount * 1].xyz;
float3 by = _TransformBuffer[id + _InstanceCount * 2].xyz;
float3 bz = cross(bx, by);

// Object to world matrix.
Expand Down
50 changes: 49 additions & 1 deletion Assets/Prisma.unity
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 73
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &46505022
Expand Down Expand Up @@ -840,6 +843,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 72
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!114 &112253469
Expand Down Expand Up @@ -2694,6 +2700,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 78
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &330282730
Expand Down Expand Up @@ -5579,6 +5588,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 79
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &598615217
Expand Down Expand Up @@ -6498,6 +6510,9 @@ MonoBehaviour:
_pulseFrequency: 3
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 2, z: 0}
m_Extent: {x: 2, y: 2, z: 2}
_randomSeed: 5
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &691913311
Expand Down Expand Up @@ -7145,6 +7160,9 @@ MonoBehaviour:
_pulseFrequency: 1.11111
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 0.7, z: 0}
m_Extent: {x: 0.7, y: 0.7, z: 0.7}
_randomSeed: 45
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!114 &726657054
Expand Down Expand Up @@ -7925,6 +7943,9 @@ MonoBehaviour:
_pulseFrequency: 1.11111
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 0.7, z: 0}
m_Extent: {x: 0.7, y: 0.7, z: 0.7}
_randomSeed: 47
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &811981994
Expand Down Expand Up @@ -8338,6 +8359,9 @@ MonoBehaviour:
_pulseFrequency: 1
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 2, z: 0}
m_Extent: {x: 2, y: 2, z: 2}
_randomSeed: 1
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!114 &833565843
Expand Down Expand Up @@ -9174,6 +9198,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 77
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &911842853
Expand Down Expand Up @@ -9457,6 +9484,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 76
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &932793598
Expand Down Expand Up @@ -10152,6 +10182,9 @@ MonoBehaviour:
_pulseFrequency: 3
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 0.7, z: 0}
m_Extent: {x: 0.7, y: 0.7, z: 0.7}
_randomSeed: 46
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &1019759789
Expand Down Expand Up @@ -11853,6 +11886,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 74
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!114 &1153973812
Expand Down Expand Up @@ -12642,6 +12678,9 @@ MonoBehaviour:
_pulseFrequency: 2
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: d651ee3c7271bf645b264ff6468e185a, type: 2}
_bounds:
m_Center: {x: 0, y: 0.26, z: 0}
m_Extent: {x: 0.5, y: 0.5, z: 0.5}
_randomSeed: 75
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &1211016074
Expand Down Expand Up @@ -14660,7 +14699,7 @@ Light:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 0.35
m_Strength: 1
m_Bias: 0.01
m_NormalBias: 0.1
m_NearPlane: 0.2
Expand Down Expand Up @@ -16555,6 +16594,9 @@ MonoBehaviour:
_pulseFrequency: 1
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 2, z: 0}
m_Extent: {x: 2, y: 2, z: 2}
_randomSeed: 6
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!1 &1699911857
Expand Down Expand Up @@ -16670,6 +16712,9 @@ MonoBehaviour:
_pulseFrequency: 3
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 2, z: 0}
m_Extent: {x: 2, y: 2, z: 2}
_randomSeed: 0
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!114 &1715255985
Expand Down Expand Up @@ -17273,6 +17318,9 @@ MonoBehaviour:
_pulseFrequency: 3
_material: {fileID: 2100000, guid: af23b3746403da141b6274cfa552d084, type: 2}
_gradient: {fileID: 11400000, guid: 3f7a16a167f35224196a138b665daa7d, type: 2}
_bounds:
m_Center: {x: 0, y: 0.7, z: 0}
m_Extent: {x: 0.7, y: 0.7, z: 0.7}
_randomSeed: 44
_compute: {fileID: 7200000, guid: 38648807cddccb549bd3e872d8442617, type: 3}
--- !u!114 &1820302642
Expand Down

0 comments on commit 09dfc65

Please sign in to comment.