AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
VolumeController.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity
7 {
11  public class VolumeController : MonoBehaviour
12  {
14 
15  public Int3 VolumeSize { get; private set; }
16  public Int3 VolumeSizePow2 { get; private set; }
17 
18  private bool isSetup;
19 
20  void OnEnable()
21  {
22  EnsureSetup();
23  }
24 
25  void Update()
26  {
27  Shader.SetGlobalMatrix("_WorldToVolume", this.transform.worldToLocalMatrix);
28 
29  Shader.SetGlobalVector("_VolBufferSize", new Vector4(VolumeSize.x, VolumeSize.y, VolumeSize.z));
30 
31  Shader.SetGlobalVector("_VolTextureFactor", new Vector4((float)VolumeSize.x / VolumeSizePow2.x,
32  (float)VolumeSize.y / VolumeSizePow2.y,
33  (float)VolumeSize.z / VolumeSizePow2.z,
34  0.0f));
35  }
36 
37  public void EnsureSetup()
38  {
39  if (isSetup)
40  {
41  return;
42  }
43 
44  isSetup = true;
45 
46  VolumeSize = this.VolumeInfo.Size;
47  VolumeSizePow2 = MathExtensions.PowerOfTwoGreaterThanOrEqualTo(VolumeSize);
48 
49  Debug.Log("Volume Controller Configured! " + this.VolumeSizePow2);
50  }
51  }
52 }
Holds data about a volume asset
static int PowerOfTwoGreaterThanOrEqualTo(this int v)
Extension methods and helper functions for various math data
3D integer class - operates similarly to Unity's Vector3D
Definition: Int3.cs:16
Configures volume variables in shader