Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. // You can execute this in the editor as long as you don't instantiate the material
  5. //[ExecuteInEditMode]
  6. public class Smear : MonoBehaviour
  7. {
  8. Queue<Vector3> m_recentPositions = new Queue<Vector3>();
  9. public int FramesBufferSize = 0;
  10. public Renderer Renderer = null;
  11. private Material m_instancedMaterial;
  12. private Material InstancedMaterial
  13. {
  14. get { return m_instancedMaterial; }
  15. set { m_instancedMaterial = value; }
  16. }
  17. private void Start()
  18. {
  19. // Instantiate the material so every object has a unique smear effect
  20. InstancedMaterial = Renderer.material;
  21. // Use this instead if you want to affect all objects at the same time or if you want to run in the editor
  22. //InstancedMaterial = Renderer.sharedMaterial;
  23. }
  24. private void LateUpdate()
  25. {
  26. // Feed the previous position in the queue to the shader
  27. if ( m_recentPositions.Count > FramesBufferSize )
  28. InstancedMaterial.SetVector( "_PrevPosition", m_recentPositions.Dequeue() );
  29. // Feed the current anchor position to the shader
  30. InstancedMaterial.SetVector( "_Position", transform.position );
  31. m_recentPositions.Enqueue( transform.position );
  32. }
  33. }