Created
July 17, 2017 16:21
-
-
Save cabbibo/e99e94c4ce65eb3d65076baf2e7c1ded to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.XR.iOS; | |
public class ARKitComputeCloud : MonoBehaviour { | |
public Material material; | |
private float[] values; | |
public ComputeBuffer _buffer; | |
struct Vert{ | |
public float used; | |
public Vector3 pos; | |
public Vector3 vel; | |
public Vector3 nor; | |
public Vector2 uv; | |
public Vector3 targetPos; | |
public Vector3 debug; | |
}; | |
private int vertStructSize = 1 + 3 + 3 + 3+2+3+3; | |
// Use this for initialization | |
void OnEnabled() { | |
values = new float[ maxPointsToShow * vertStructSize ]; | |
_buffer = new ComputeBuffer( maxPointsToShow , vertStructSize * sizeof( float )); | |
int index = 0; | |
for( int i = 0; i < maxPointsToShow; i++ ){ | |
// used | |
values[ index++ ] = 0; | |
// positions | |
values[ index++ ] = Random.Range( -1 , 1 ); | |
values[ index++ ] = Random.Range( -1 , 1 ); | |
values[ index++ ] = Random.Range( -1 , 1 ); | |
// vel | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
// normals | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
//uvs | |
values[ index++ ] = (float)i/(float)maxPointsToShow; | |
values[ index++ ] = i; | |
// target pos | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
// Debug | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
values[ index++ ] = 0; | |
} | |
_buffer.SetData(values); | |
} | |
public void OnDisabled(){ | |
_buffer.Release(); | |
} | |
void OnRenderObject(){ | |
material.SetPass(0); | |
material.SetBuffer( "_vertBuffer", _buffer ); | |
Graphics.DrawProcedural(MeshTopology.Triangles, maxPointsToShow * 6 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment