public WallService(int capacity) { this.capacity = capacity; _colliders = new List<Transform>(capacity); _walls = new Wall[capacity]; Walls = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Wall))); Walls.SetData(_walls); }
static public int constructor(IntPtr l) { int argc = LuaDLL.lua_gettop(l); UnityEngine.ComputeBuffer o; if (argc == 3) { System.Int32 a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); o = new UnityEngine.ComputeBuffer(a1, a2); pushObject(l, o); return(1); } else if (argc == 4) { System.Int32 a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); UnityEngine.ComputeBufferType a3; checkEnum(l, 4, out a3); o = new UnityEngine.ComputeBuffer(a1, a2, a3); pushObject(l, o); return(1); } LuaDLL.luaL_error(l, "New object failed."); return(0); }
void InitializeBuffers() { computeBuffer = new ComputeBuffer(numPoints, 12); computeShaderA.SetBuffer(kernelID, "outputBuffer", computeBuffer); timeBuffer = new ComputeBuffer(1, 4); timeArray = new float[1]; material.SetBuffer("buf_Points", computeBuffer); }
static int SetGlobalBuffer(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes <string, UnityEngine.ComputeBuffer>(L, 1)) { string arg0 = ToLua.ToString(L, 1); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.ToObject(L, 2); UnityEngine.Shader.SetGlobalBuffer(arg0, arg1); return(0); } else if (count == 2 && TypeChecker.CheckTypes <int, UnityEngine.ComputeBuffer>(L, 1)) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.ToObject(L, 2); UnityEngine.Shader.SetGlobalBuffer(arg0, arg1); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Shader.SetGlobalBuffer")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void BitonicSort(ComputeBuffer kip, ComputeBuffer kip_tmp, uint num) { uint BITONIC_BLOCK_SIZE = 512; uint TRANSPOSE_BLOCK_SIZE = 16; uint NUM_ELEMENTS = num; uint MATRIX_WIDTH = BITONIC_BLOCK_SIZE; uint MATRIX_HEIGHT = NUM_ELEMENTS / BITONIC_BLOCK_SIZE; for (uint level = 2; level <= BITONIC_BLOCK_SIZE; level <<= 1) { m_consts[0].level = level; m_consts[0].levelMask = level; m_consts[0].width = MATRIX_HEIGHT; // not a mistake! m_consts[0].height = MATRIX_WIDTH; // m_buf_consts[0].SetData(m_consts); m_cs_bitonic_sort.SetBuffer(0, "consts", m_buf_consts[0]); m_cs_bitonic_sort.SetBuffer(0, "kip_rw", kip); m_cs_bitonic_sort.Dispatch(0, (int)(NUM_ELEMENTS / BITONIC_BLOCK_SIZE), 1, 1); } // Then sort the rows and columns for the levels > than the block size // Transpose. Sort the Columns. Transpose. Sort the Rows. for (uint level = (BITONIC_BLOCK_SIZE << 1); level <= NUM_ELEMENTS; level <<= 1) { m_consts[0].level = (level / BITONIC_BLOCK_SIZE); m_consts[0].levelMask = (level & ~NUM_ELEMENTS) / BITONIC_BLOCK_SIZE; m_consts[0].width = MATRIX_WIDTH; m_consts[0].height = MATRIX_HEIGHT; m_buf_consts[0].SetData(m_consts); // Transpose the data from buffer 1 into buffer 2 m_cs_bitonic_sort.SetBuffer(1, "consts", m_buf_consts[0]); m_cs_bitonic_sort.SetBuffer(1, "kip", kip); m_cs_bitonic_sort.SetBuffer(1, "kip_rw", kip_tmp); m_cs_bitonic_sort.Dispatch(1, (int)(MATRIX_WIDTH / TRANSPOSE_BLOCK_SIZE), (int)(MATRIX_HEIGHT / TRANSPOSE_BLOCK_SIZE), 1); // Sort the transposed column data m_cs_bitonic_sort.SetBuffer(0, "consts", m_buf_consts[0]); m_cs_bitonic_sort.SetBuffer(0, "kip_rw", kip_tmp); m_cs_bitonic_sort.Dispatch(0, (int)(NUM_ELEMENTS / BITONIC_BLOCK_SIZE), 1, 1); m_consts[0].level = BITONIC_BLOCK_SIZE; m_consts[0].levelMask = level; m_consts[0].width = MATRIX_HEIGHT; m_consts[0].height = MATRIX_WIDTH; m_buf_consts[0].SetData(m_consts); // Transpose the data from buffer 2 back into buffer 1 m_cs_bitonic_sort.SetBuffer(1, "consts", m_buf_consts[0]); m_cs_bitonic_sort.SetBuffer(1, "kip", kip_tmp); m_cs_bitonic_sort.SetBuffer(1, "kip_rw", kip); m_cs_bitonic_sort.Dispatch(1, (int)(MATRIX_HEIGHT / TRANSPOSE_BLOCK_SIZE), (int)(MATRIX_WIDTH / TRANSPOSE_BLOCK_SIZE), 1); // Sort the row data m_cs_bitonic_sort.SetBuffer(0, "consts", m_buf_consts[0]); m_cs_bitonic_sort.SetBuffer(0, "kip_rw", kip); m_cs_bitonic_sort.Dispatch(0, (int)(NUM_ELEMENTS / BITONIC_BLOCK_SIZE), 1, 1); } }
void Awake() { var mf = prefab.GetComponent<MeshFilter>(); var mesh = mf.sharedMesh; _indexBuf = new ComputeBuffer(mesh.triangles.Length, Marshal.SizeOf(mesh.triangles[0])); _indexBuf.SetData(mesh.triangles); _vertexBuf = new ComputeBuffer(mesh.vertices.Length, Marshal.SizeOf(mesh.vertices[0])); _vertexBuf.SetData(mesh.vertices); _uvBuf = new ComputeBuffer(mesh.uv.Length, Marshal.SizeOf(mesh.uv[0])); _uvBuf.SetData(mesh.uv); var gofab = new GameObject("Position"); gofab.hideFlags = HideFlags.HideAndDontSave; _trs = GenerateRandom(gofab, count); _worlds = new float[16 * _trs.Length]; _worldBuf = new ComputeBuffer(_trs.Length, 16 * Marshal.SizeOf(_worlds[0])); UpdateWorlds(); _mat = new Material(prefab.renderer.sharedMaterial); _mat.SetBuffer(CS_INDEX_BUFFER, _indexBuf); _mat.SetBuffer(CS_VERTEX_BUFFER, _vertexBuf); _mat.SetBuffer(CS_UV_BUFFER, _uvBuf); _mat.SetBuffer(CS_WORLD_BUFFER, _worldBuf); }
public virtual void ReleaseGPUResources() { ClearMaterials(); if (m_buf_trail_vertices != null) { m_buf_trail_vertices.Release(); m_buf_trail_vertices = null; } if (m_buf_trail_history != null) { m_buf_trail_history.Release(); m_buf_trail_history = null; } if (m_buf_trail_entities != null) { m_buf_trail_entities.Release(); m_buf_trail_entities = null; } if (m_buf_trail_params != null) { m_buf_trail_params.Release(); m_buf_trail_params = null; } }
static public int Release(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); self.Release(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int constructor(IntPtr l) { LuaDLL.lua_remove(l, 1); UnityEngine.ComputeBuffer o; if (matchType(l, 1, typeof(int), typeof(int))) { System.Int32 a1; checkType(l, 1, out a1); System.Int32 a2; checkType(l, 2, out a2); o = new UnityEngine.ComputeBuffer(a1, a2); pushObject(l, o); return(1); } else if (matchType(l, 1, typeof(int), typeof(int), typeof(UnityEngine.ComputeBufferType))) { System.Int32 a1; checkType(l, 1, out a1); System.Int32 a2; checkType(l, 2, out a2); UnityEngine.ComputeBufferType a3; checkEnum(l, 3, out a3); o = new UnityEngine.ComputeBuffer(a1, a2, a3); pushObject(l, o); return(1); } LuaDLL.luaL_error(l, "New object failed."); return(0); }
// private void InitiateBuffers() { // Debug.Log("InitiateBuffers"); // Texture2D renderTexture = m_MultiSourceManger.GetColorTexture(); if( renderTexture != null ) { gameObject.renderer.material.SetTexture("_MainTex", renderTexture); } m_DepthPoints = m_MultiSourceManger.GetDepthCoordinates(); if( m_DepthPoints != null ) { m_DepthBuffer = new ComputeBuffer( m_DepthPoints.Length, sizeof(float) * 2 ); gameObject.renderer.material.SetBuffer( "depthCoordinates", m_DepthBuffer ); } m_BodyIndexPoints = m_MultiSourceManger.GetBodyIndexData(); if( m_BodyIndexPoints != null) { m_BodyIndexBuffer = new ComputeBuffer( m_BodyIndexPoints.Length, sizeof(float) ); gameObject.renderer.material.SetBuffer ( "bodyIndexBuffer", m_BodyIndexBuffer ); } }
/// <summary> /// Start this instance. /// Initializes all buffers and other resources needed by tressfx simulation and rendering. /// </summary> public void Start() { if (this.hairData == null) { Debug.LogError("No hair data assigned to TressFX :("); } // Vertex buffers this.g_HairVertexPositions = this.InitializeBuffer (this.hairData.m_pVertices, 16); this.g_HairVertexPositionsPrev = this.InitializeBuffer (this.hairData.m_pVertices, 16); this.g_InitialHairPositions = this.InitializeBuffer (this.hairData.m_pVertices, 16); // Tangents and rotations this.g_HairVertexTangents = this.InitializeBuffer (this.hairData.m_pTangents, 16); this.g_GlobalRotations = this.InitializeBuffer (this.hairData.m_pGlobalRotations, 16); this.g_LocalRotations = this.InitializeBuffer (this.hairData.m_pLocalRotations, 16); // Others this.g_HairRestLengthSRV = this.InitializeBuffer (this.hairData.m_pRestLengths, 4); this.g_HairStrandType = this.InitializeBuffer (this.hairData.m_pHairStrandType, 4); this.g_HairRefVecsInLocalFrame = this.InitializeBuffer (this.hairData.m_pRefVectors, 16); this.g_FollowHairRootOffset = this.InitializeBuffer (this.hairData.m_pFollowRootOffset, 16); this.g_HairThicknessCoeffs = this.InitializeBuffer (this.hairData.m_pThicknessCoeffs, 4); this.g_TexCoords = this.InitializeBuffer(this.hairData.m_TexCoords, 16); // Get other parts this.simulation = this.GetComponent<TressFXSimulation> (); }
static void ComputeBuffer_stride(JSVCall vc) { UnityEngine.ComputeBuffer _this = (UnityEngine.ComputeBuffer)vc.csObj; var result = _this.stride; JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(result)); }
void OnDisable() { if (volume!= null) { volume.Release(); volume= null; } if (volumeBuffer != null) { volumeBuffer.Release(); volumeBuffer = null; } if (targetBuffer != null) { targetBuffer.Release(); targetBuffer = null; } /* if (particleColorBuffer != null) { particleColorBuffer.Release(); particleColorBuffer = null; } */ if (particleBuffer != null) { particleBuffer.Release(); particleBuffer = null; } }
public SplatGenVerticesPass() { base.LoadComputeShader("Assets/Shaders/splat_gen_vertices.compute"); indexCounterBuffer = new ComputeBuffer(1, sizeof(int)); nonemptyLeft = new ComputeBuffer(1, sizeof(int)); }
public static Tensor InvokeFunctionKernel(string name, Tensor input) { var compute = Pix2PixResources.Compute; var kernel = compute.FindKernel(name); uint tgn_x, tgn_y, tgn_z; compute.GetKernelThreadGroupSizes(kernel, out tgn_x, out tgn_y, out tgn_z); Debug.Assert(tgn_y == 1 && tgn_z == 1); var length = input.Data.Length; Debug.Assert(length % tgn_x == 0); var buffer_input = new UnityEngine.ComputeBuffer(length, sizeof(float)); var buffer_output = new UnityEngine.ComputeBuffer(length, sizeof(float)); buffer_input.SetData(input.Data); compute.SetBuffer(kernel, "Input", buffer_input); compute.SetBuffer(kernel, "Output", buffer_output); compute.Dispatch(kernel, length / (int)tgn_x, 1, 1); var output = new Tensor(input.Shape); buffer_output.GetData(output.Data); buffer_input.Dispose(); buffer_output.Dispose(); return(output); }
static public int constructor(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); UnityEngine.ComputeBuffer o; if (argc == 3) { System.Int32 a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); o = new UnityEngine.ComputeBuffer(a1, a2); pushValue(l, true); pushValue(l, o); return(2); } else if (argc == 4) { System.Int32 a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); UnityEngine.ComputeBufferType a3; checkEnum(l, 4, out a3); o = new UnityEngine.ComputeBuffer(a1, a2, a3); pushValue(l, true); pushValue(l, o); return(2); } return(error(l, "New object failed.")); } catch (Exception e) { return(error(l, e)); } }
public ConstantService(int capacity, ConstantData d) { _data = d; _dragCoeffData = new float[capacity]; _dragCoeffs = new ComputeBuffer (capacity, Marshal.SizeOf (typeof(float))); CheckDragCoeffs(); }
void InitializeBuffers() { // Set start point compute buffer startPointBuffer = new ComputeBuffer(VertCount, 4); // create space in the buffer for 3 float per point (float = 4 bytes) // Set const compute buffer size constantBuffer = new ComputeBuffer(1, 4); modBuffer = new ComputeBuffer(VertCount, 8); // Set output buffer size. outputBuffer = new ComputeBuffer(VertCount, 12); // These values will be the starting y coords for each point. float[] values = new float[VertCount]; Vector2[] mods = new Vector2[VertCount]; for (int i = 0; i < VertCount; i++) { values[i] = Random.value * 2 * Mathf.PI; mods[i] = new Vector2(.1f + Random.value, .1f + Random.value); } modBuffer.SetData(mods); // Load starting valuse into the compute buffer startPointBuffer.SetData(values); // Only need to set the offsets once in the CS computeShader.SetBuffer(CSKernel, "startPointBuffer", startPointBuffer); }
static int SetBuffer(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3 && TypeChecker.CheckTypes <int, UnityEngine.ComputeBuffer>(L, 2)) { UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock)); int arg0 = (int)LuaDLL.lua_tonumber(L, 2); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.ToObject(L, 3); obj.SetBuffer(arg0, arg1); return(0); } else if (count == 3 && TypeChecker.CheckTypes <string, UnityEngine.ComputeBuffer>(L, 2)) { UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock)); string arg0 = ToLua.ToString(L, 2); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.ToObject(L, 3); obj.SetBuffer(arg0, arg1); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.MaterialPropertyBlock.SetBuffer")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void DoInit() { if(_particlesBuffer != null) { _particlesBuffer.Release(); _particlesBuffer = null; } _particlesBuffer = new ComputeBuffer(_totalNumParticles, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ImageParticleEngine.ParticleData)) ); _particlesPhysicsBuffer = new ComputeBuffer(_totalNumParticles, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ImageParticleEngine.ParticlePhysicsData)) ); _shaderCompute.SetBuffer(_initImageKernelId, "_ParticlesBuffer", _particlesBuffer); _shaderCompute.SetBuffer(_initImageKernelId, "_ParticlesPhysicsBuffer", _particlesPhysicsBuffer); _shaderCompute.SetBuffer(_updateParticlesKernel, "_ParticlesBuffer", _particlesBuffer); _shaderCompute.SetBuffer(_updateParticlesKernel, "_ParticlesPhysicsBuffer", _particlesPhysicsBuffer); _shaderCompute.SetVector("_ImageSize", new Vector4(_image.width, _image.height, 0f, 0f)); _shaderCompute.SetTexture(_initImageKernelId, "_Image", _image); _shaderCompute.SetVector("_Position", transform.position); _shaderCompute.SetVector("_ParticleHalfSize", new Vector4(1f, 1f, 1f, 1f)*0.016f); _shaderCompute.SetInt("_ImageLayers", _imageLayers); _material.SetBuffer("_ParticlesBuffer", _particlesBuffer); _material.SetVector("_ImageSize", new Vector4(_image.width, _image.height, 0f, 0f)); _material.SetVector("_ParticleHalfSize", new Vector4(1f, 1f, 0f, 1f)*0.016f); _shaderCompute.Dispatch(_initImageKernelId, _numThreadGroupsX, _numThreadGroupsY, _numThreadGroupsZ); }
public void InitBuffers() { // Ingredient data if (ProteinColors == null) ProteinColors = new ComputeBuffer(NumIngredientsMax, 16); if (ProteinToggleFlags == null) ProteinToggleFlags = new ComputeBuffer(NumIngredientsMax, 4); // Instance data if (ProteinInstanceInfos == null) ProteinInstanceInfos = new ComputeBuffer(NumProteinInstancesMax, 16); if (ProteinInstanceCullFlags == null) ProteinInstanceCullFlags = new ComputeBuffer(NumProteinInstancesMax, 4); if (ProteinInstancePositions == null) ProteinInstancePositions = new ComputeBuffer(NumProteinInstancesMax, 16); if (ProteinInstanceRotations == null) ProteinInstanceRotations = new ComputeBuffer(NumProteinInstancesMax, 16); // Atom data if (ProteinAtomPositions == null) ProteinAtomPositions = new ComputeBuffer(NumProteinAtomMax, 16); if (ProteinAtomCount == null) ProteinAtomCount = new ComputeBuffer(NumIngredientsMax, 4); if (ProteinAtomStart == null) ProteinAtomStart = new ComputeBuffer(NumIngredientsMax, 4); // Cluster data if (ProteinClusterPositions == null) ProteinClusterPositions = new ComputeBuffer(NumProteinAtomMax, 16); if (ProteinClusterCount == null) ProteinClusterCount = new ComputeBuffer(NumIngredientsMax * 4, 4); if (ProteinClusterStart == null) ProteinClusterStart = new ComputeBuffer(NumIngredientsMax * 4, 4); // Lod data if (LodInfos == null) LodInfos = new ComputeBuffer(8, 16); // Sphere batch if (SphereBatchBuffer == null) SphereBatchBuffer = new ComputeBuffer(NumSphereBatchesMax, 16, ComputeBufferType.Append); }
void InitializeSimulation() { if (SystemInfo.supportsComputeShaders) { m_cb_params = new ComputeBuffer(1, CSParams.size); m_cb_particles = new ComputeBuffer(m_particle_count, peParticle.size); m_cb_positions = new ComputeBuffer(m_particle_count, 12); m_cb_velocities = new ComputeBuffer(m_particle_count, 12); m_buf_positions = new Vector3[m_particle_count]; m_buf_velocities = new Vector3[m_particle_count]; m_csparams = new CSParams[1]; } { UnityEngine.Random.seed = 0; var tmp = new peParticle[m_particle_count]; for (int i = 0; i < tmp.Length; ++i) { tmp[i].position = new Vector3( UnityEngine.Random.Range(-5.0f, 5.0f), UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f, UnityEngine.Random.Range(-5.0f, 5.0f)); } m_cb_particles.SetData(tmp); } }
void Start () { ReleaseBuffers (); if (CoordinateMapperManager == null) { return; } _CoordinateMapperManager = CoordinateMapperManager.GetComponent<CoordinateMapperManager>(); Texture2D renderTexture = _CoordinateMapperManager.GetColorTexture(); if (renderTexture != null) { gameObject.GetComponent<Renderer>().material.SetTexture("_MainTex", renderTexture); } depthPoints = _CoordinateMapperManager.GetDepthCoordinates (); if (depthPoints != null) { depthBuffer = new ComputeBuffer(depthPoints.Length, sizeof(float) * 2); gameObject.GetComponent<Renderer>().material.SetBuffer("depthCoordinates", depthBuffer); } bodyIndexPoints = _CoordinateMapperManager.GetBodyIndexBuffer (); if (bodyIndexPoints != null) { bodyIndexBuffer = new ComputeBuffer(bodyIndexPoints.Length, sizeof(float)); gameObject.GetComponent<Renderer>().material.SetBuffer ("bodyIndexBuffer", bodyIndexBuffer); } }
void Start() { //清空緩衝器。 ReleaseBuffers (); //如果讀取不到資料來源程式,跳出。 if (CoordinateMapperManager == null) { return; } _CoordinateMapperManager = CoordinateMapperManager.GetComponent<CoordinateMapperManager>(); //讀取彩色貼圖。 Texture2D renderTexture = _CoordinateMapperManager.GetColorTexture(); if (renderTexture != null) { gameObject.renderer.material.SetTexture("_MainTex", renderTexture); } //讀取深度資料座標。 depthPoints = _CoordinateMapperManager.GetDepthCoordinates (); if (depthPoints != null) { depthBuffer = new ComputeBuffer(depthPoints.Length, sizeof(float) * 2); gameObject.renderer.material.SetBuffer("depthCoordinates", depthBuffer); } //讀取人體辨識資料。 bodyIndexPoints = _CoordinateMapperManager.GetBodyIndexBuffer (); if (bodyIndexPoints != null) { bodyIndexBuffer = new ComputeBuffer(bodyIndexPoints.Length, sizeof(float)); gameObject.renderer.material.SetBuffer ("bodyIndexBuffer", bodyIndexBuffer); } }
void OnRenderObject() { if (UseComputeData) { cso = GetComponent<ComputeShaderOutput>(); wso = GetComponent<WeatherShaderOutput>(); if (outputBuffer == null && cso != null) outputBuffer = cso.outputBuffer; if (outputBuffer == null && wso != null) outputBuffer = wso.outputBuffer; if (cso != null) cso.Dispatch(); else { wso.Dispatch(); Wind = wso.wind; } } material.SetPass(0); material.SetColor("_Color", color); material.SetBuffer("buf_Points", outputBuffer); material.SetTexture("_Sprite", sprite); material.SetVector("_Size", size); material.SetInt("_StaticCylinderSpherical", billboardType); material.SetVector("_worldPos", transform.position); material.SetVector("_Wind", Wind); Graphics.DrawProcedural(MeshTopology.Points, outputBuffer.count); }
static public int constructor(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); UnityEngine.ComputeBuffer o; if(argc==3){ System.Int32 a1; checkType(l,2,out a1); System.Int32 a2; checkType(l,3,out a2); o=new UnityEngine.ComputeBuffer(a1,a2); pushValue(l,true); pushValue(l,o); return 2; } else if(argc==4){ System.Int32 a1; checkType(l,2,out a1); System.Int32 a2; checkType(l,3,out a2); UnityEngine.ComputeBufferType a3; checkEnum(l,4,out a3); o=new UnityEngine.ComputeBuffer(a1,a2,a3); pushValue(l,true); pushValue(l,o); return 2; } return error(l,"New object failed."); } catch(Exception e) { return error(l,e); } }
protected override void Awake() { base.Awake(); int tileSize = GetTileSize(); int capacity = GetCapacity(); for(int i = 0; i < capacity; i++) { ComputeBuffer buffer; switch((int)m_dataType) { case (int)DATA_TYPE.FLOAT: buffer = new ComputeBuffer(tileSize, sizeof(float) * m_channels, m_bufferType); break; case (int)DATA_TYPE.INT: buffer = new ComputeBuffer(tileSize, sizeof(int) * m_channels, m_bufferType); break; case (int)DATA_TYPE.BYTE: buffer = new ComputeBuffer(tileSize, sizeof(byte) * m_channels, m_bufferType); break; default: buffer = new ComputeBuffer(tileSize, sizeof(float) * m_channels, m_bufferType); break; }; CBSlot slot = new CBSlot(this, buffer); AddSlot(i, slot); } }
/// <summary> /// Uses the GPU to generate a RenderTexture where the pixels in the texture represent noise. /// Set the octaves variable before calling this to a desired value. /// </summary> /// <returns>RenderTexture</returns> /// <param name="width"> Width of the texture to generate. </param> /// <param name="height"> Height of the texture to generate. </param> /// <param name="noiseOffsetX"> X Coordinate of the offset for the noise on the texture. </param> /// <param name="noiseOffsetY"> Y Coordinate of the offset for the noise on the texture. </param> /// <param name="noiseScale"> Value to scale the noise coordinates by. </param> /// <param name="normalize"> Whether or not to remap the noise from (-1, 1) to (0, 1). </param> public static UnityEngine.RenderTexture GetNoiseRenderTexture(int width, int height, float noiseOffsetX = 0, float noiseOffsetY = 0, float noiseScale = 0.01f, bool normalize = true) { UnityEngine.RenderTexture retTex = new UnityEngine.RenderTexture(width, height, 0); retTex.enableRandomWrite = true; retTex.Create(); UnityEngine.ComputeShader shader = UnityEngine.Resources.Load(shaderPath) as UnityEngine.ComputeShader; if (shader == null) { UnityEngine.Debug.LogError(noShaderMsg); return(null); } int[] resInts = { width, height }; int kernel = shader.FindKernel("ComputeNoise"); shader.SetTexture(kernel, "Result", retTex); SetShaderVars(shader, new UnityEngine.Vector2(noiseOffsetX, noiseOffsetY), normalize, noiseScale); shader.SetInts("reses", resInts); UnityEngine.ComputeBuffer permBuffer = new UnityEngine.ComputeBuffer(perm.Length, 4); permBuffer.SetData(perm); shader.SetBuffer(kernel, "perm", permBuffer); shader.Dispatch(kernel, width / 14, height / 15, 1); permBuffer.Release(); return(retTex); }
void Start() { ComputeBuffer buffer = new ComputeBuffer (4 * 4 * 2 * 2, sizeof(int)); int kernel = shader.FindKernel ("CSMain2"); shader.SetBuffer (kernel, "buffer2", buffer); shader.Dispatch (kernel, 2, 2, 1); int[] data = new int[4 * 4 * 2 * 2]; buffer.GetData (data); for(int i = 0; i < 8; i++) { string line = ""; for(int j = 0; j < 8; j++) { line += " " + data[j+i*8]; } Debug.Log (line); } buffer.Release (); }
public void Init() { _numParticlesX = _particleGroupsX * kNumThreadsX; _numParticlesY = _particleGroupsY * kNumThreadsY; _numParticles = _numParticlesX * _numParticlesY; _currentCopiedVertices = 0; _particleMaterial = Resources.Load<Material>("GPUParticleMat"); _computeShader = Resources.Load<ComputeShader>("ComputeShaders/GPUParticleUpdater"); _kernelMoveParticles = _computeShader.FindKernel(kKernelMoveParticles); _particlesData = new Particle[_numParticles]; InitBuffer(_particlesData); for (int i = 0; i < _particlesData.Length; ++i) { float id = ((float)i) / 10000.1f; CreateParticle(id); } // Set ComputeShader Parameters _particlesBuffer = new ComputeBuffer(_particlesData.Length, System.Runtime.InteropServices.Marshal.SizeOf(typeof(GPUParticleSystem.Particle))); _particlesBuffer.SetData(_particlesData); _computeShader.SetBuffer(_kernelMoveParticles, "_ParticlesBuffer", _particlesBuffer); _computeShader.SetFloat("_Width", _numParticlesX); _computeShader.SetFloat("_Height", _numParticlesY); // Set Shader Parameters _particleMaterial.SetBuffer("_ParticlesBuffer", _particlesBuffer); }
// Use this for initialization void Start() { Debug.Log("Population size: " + populationSize); int width = (int)Mathf.Round(Mathf.Sqrt(populationSize)); int height = (int)Mathf.Round(Mathf.Sqrt(populationSize)); testing = new ComputeBuffer(10, Marshal.SizeOf(typeof(Individual))); Debug.Log("Seed " + DateTime.Now.Millisecond); // Fill with random genome, and run first fitness test. int kernel = shader.FindKernel("InitializePopulation"); DebugAux.Assert(kernel >= 0, "Couldn't find kernel: " + "InitializePopulation " + kernel); shader.SetBuffer(kernel, "Population", testing); shader.SetFloat("seed", DateTime.Now.Millisecond); shader.Dispatch(kernel, 32, 32, 1); Individual[] tes = new Individual[10]; testing.GetData(tes); for (int i = 0; i < tes.Length; i++) Debug.Log(tes[i].genome + " " + tes[i].fitness); // Selection.. /*kernel = shader.FindKernel("AllOnesFitness"); DebugAux.Assert(kernel >= 0, "Couldn't find kernel: " + "AllOnesFitness " + kernel); shader.SetBuffer(kernel, "Population", testing); shader.Dispatch(kernel, 32, 32, 1);*/ testing.Dispose(); }
public void Init(ComputeBuffer keys) { int x, y, z; ShaderUtil.CalcWorkSize(keys.count, out x, out y, out z); _compute.SetInt(PROP_COUNT, keys.count); _compute.SetBuffer(_kernelInit, BUF_KEYS, keys); _compute.Dispatch(_kernelInit, x, y, z); }
void InitializeBuffers() { outputBuffer = new ComputeBuffer(VertCount, (sizeof(float) * 3) + (sizeof(int) * 6)); computeShader.SetBuffer(CSKernel, "outputBuffer", outputBuffer); if (Debugrender) PointMaterial.SetBuffer("buf_Points", outputBuffer); }
void OnDestroy() { if(m_buffer!=null) { m_buffer.Release(); m_buffer = null; } }
void InitializeMembers() { if (m_entities == null) { m_entities = new MetaballData[m_max_entities]; m_buffer = new ComputeBuffer(m_max_entities, MetaballData.size); m_material = GetComponent<Renderer>().sharedMaterial; } }
public PointService(int capacity) { _capacity = capacity; _count = 0; _pointData = new Vector2[capacity]; _points = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Vector2))); Upload(); }
public void Initialize(ComputeShader sh_bitonic_sort) { m_cs_bitonic_sort = sh_bitonic_sort; m_buf_consts[0] = new ComputeBuffer(1, 16); m_buf_consts[1] = new ComputeBuffer(1, 16); m_buf_dummies[0] = new ComputeBuffer(1, 16); m_buf_dummies[1] = new ComputeBuffer(1, 16); }
void CreateResources() { NumInstances = SceneManager.Get.NumProteinInstances; if (quadUVs == null) { var uvs = quadMesh.uv; quadUVs = new ComputeBuffer(uvs.Length, sizeof(float) * 2); quadUVs.SetData(uvs); } if (quadIndices == null) { var indices = quadMesh.triangles; quadIndices = new ComputeBuffer(indices.Length, sizeof(float) * 1); quadIndices.SetData(indices); } if (quadVertices == null) { var normals = quadMesh.vertices; quadVertices = new ComputeBuffer(normals.Length, sizeof(float) * 3); quadVertices.SetData(normals); } if (true) { var colors = new Color[NumInstances]; for (int i = 0; i < NumInstances; i++) { //colors[i] = new Color(Random.value, Random.value, Random.value, 0.2f); Vector4 col = SceneManager.Get.ProteinColors[(int) SceneManager.Get.ProteinInstanceInfos[i].x]; //TODO: expose orderedEntities in trannimation manager, acces it here as orderedEntities[i].isFinalized() ? 1.0 : 0.0 use this as alpha. THEN make the alpha actuall alpha in the shader colors[i] = new Color(col.x, col.y, col.z, TrannimationManager.Get.getInstanceBillboardAlpha(i)); } if (instanceColors == null) instanceColors = new ComputeBuffer(NumInstances, sizeof(float) * 4); instanceColors.SetData(colors); } if (/*instancePositions == null &&*/ TrannimationManager.Get.upload != null && TrannimationManager.Get.upload.Length >= NumInstances - 1) { var positions = new Vector3[NumInstances]; for (int i = 0; i < NumInstances; i++) { //positions[i] = SceneManager.Get.ProteinInstancePositions[i] * PersistantSettings.Instance.Scale; //Random.insideUnitSphere * SpawnRegionSize; positions[i] = TrannimationManager.Get.upload[i] * PersistantSettings.Instance.Scale; } if (instancePositions == null) instancePositions = new ComputeBuffer(NumInstances, sizeof(float) * 3); instancePositions.SetData(positions); } }
void Start () { _spherePositionsList = new List<Vector3>(); _buffer = new ComputeBuffer(_spherePositionsList.Count, 12); _audioSource = GetComponent<AudioSource>(); _leftFoot = GameObject.FindGameObjectWithTag("FootL").transform; _rightFoot = GameObject.FindGameObjectWithTag("FootR").transform; }
public static Tensor InvokeConvolutionKernel( ConvolutionMode mode, string name, Tensor input, Tensor filter, Tensor bias ) { var compute = Pix2PixResources.Compute; var kernel = compute.FindKernel(name); uint tgn_x, tgn_y, tgn_z; compute.GetKernelThreadGroupSizes(kernel, out tgn_x, out tgn_y, out tgn_z); var deconv = (mode == ConvolutionMode.Backward); var outHeight = deconv ? input.Shape[0] * 2 : input.Shape[0] / 2; var outWidth = deconv ? input.Shape[1] * 2 : input.Shape[1] / 2; var outChannels = filter.Shape[deconv ? 2 : 3]; Debug.Assert(outHeight % tgn_z == 0); Debug.Assert(outWidth % tgn_y == 0); Debug.Assert(outChannels % tgn_x == 0); var output = new Tensor(new [] { outHeight, outWidth, outChannels }); var buffer_input = new UnityEngine.ComputeBuffer(input.Data.Length, sizeof(float)); var buffer_filter = new UnityEngine.ComputeBuffer(filter.Data.Length, sizeof(float)); var buffer_bias = new UnityEngine.ComputeBuffer(bias.Data.Length, sizeof(float)); var buffer_output = new UnityEngine.ComputeBuffer(output.Data.Length, sizeof(float)); buffer_input.SetData(input.Data); buffer_filter.SetData(filter.Data); buffer_bias.SetData(bias.Data); compute.SetInts("InputShape", input.Shape); compute.SetInts("FilterShape", filter.Shape); compute.SetInts("OutputShape", output.Shape); compute.SetBuffer(kernel, "Input", buffer_input); compute.SetBuffer(kernel, "Filter", buffer_filter); compute.SetBuffer(kernel, "Bias", buffer_bias); compute.SetBuffer(kernel, "Output", buffer_output); compute.Dispatch(kernel, outChannels / (int)tgn_x, outWidth / (int)tgn_y, outHeight / (int)tgn_z ); buffer_output.GetData(output.Data); buffer_input.Dispose(); buffer_filter.Dispose(); buffer_bias.Dispose(); buffer_output.Dispose(); return(output); }
public void StartDetection(ComputeBuffer image) { using (var tensor = new Tensor(1, IMAGE_SIZE, IMAGE_SIZE, 3, image)) { var inputs = new Dictionary <string, Tensor> { { INPUT_NAME, tensor } }; _worker.Execute(inputs); _worker.FlushSchedule(); } }
static public int GetData(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (argc == 2) { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); System.Array a1; checkType(l, 2, out a1); self.GetData(a1); pushValue(l, true); return(1); } else if (argc == 5) { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); System.Array a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); System.Int32 a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.GetData(a1, a2, a3, a4); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function GetData to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int Release(IntPtr l) { try { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); self.Release(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int get_stride(IntPtr l) { try { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); pushValue(l, true); pushValue(l, self.stride); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int Release(IntPtr l) { try{ UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); self.Release(); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int constructor(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); UnityEngine.ComputeBuffer o; if (argc == 3) { System.Int32 a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); o = new UnityEngine.ComputeBuffer(a1, a2); pushValue(l, true); pushValue(l, o); return(2); } else if (argc == 4) { System.Int32 a1; checkType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); UnityEngine.ComputeBufferType a3; a3 = (UnityEngine.ComputeBufferType)LuaDLL.luaL_checkinteger(l, 4); o = new UnityEngine.ComputeBuffer(a1, a2, a3); pushValue(l, true); pushValue(l, o); return(2); } return(error(l, "New object failed.")); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int get_stride(IntPtr l) { try { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); pushValue(l, self.stride); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static bool Graphics_SetRandomWriteTarget__Int32__ComputeBuffer(JSVCall vc, int argc) { int len = argc; if (len == 2) { System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); UnityEngine.Graphics.SetRandomWriteTarget(arg0, arg1); } return(true); }
static public int GetNativeBufferPtr(IntPtr l) { try { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); var ret = self.GetNativeBufferPtr(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static bool Shader_SetGlobalBuffer__String__ComputeBuffer(JSVCall vc, int argc) { int len = argc; if (len == 2) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); UnityEngine.Shader.SetGlobalBuffer(arg0, arg1); } return(true); }
static bool Graphics_DrawProceduralIndirect__MeshTopology__ComputeBuffer(JSVCall vc, int argc) { int len = argc; if (len == 2) { UnityEngine.MeshTopology arg0 = (UnityEngine.MeshTopology)JSApi.getEnum((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); UnityEngine.Graphics.DrawProceduralIndirect(arg0, arg1); } return(true); }
static bool Material_SetBuffer__String__ComputeBuffer(JSVCall vc, int argc) { int len = argc; if (len == 2) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); ((UnityEngine.Material)vc.csObj).SetBuffer(arg0, arg1); } return(true); }
static bool ComputeShader_SetBuffer__Int32__String__ComputeBuffer(JSVCall vc, int argc) { int len = argc; if (len == 3) { System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer arg2 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); ((UnityEngine.ComputeShader)vc.csObj).SetBuffer(arg0, arg1, arg2); } return(true); }
static public int GetData(IntPtr l) { try { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); System.Array a1; checkType(l, 2, out a1); self.GetData(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int GetData(IntPtr l) { try{ UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); System.Array a1; checkType(l, 2, out a1); self.GetData(a1); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static bool ComputeBuffer_CopyCount__ComputeBuffer__ComputeBuffer__Int32(JSVCall vc, int argc) { int len = argc; if (len == 3) { UnityEngine.ComputeBuffer arg0 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)JSMgr.datax.getObject((int)JSApi.GetType.Arg); System.Int32 arg2 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg); UnityEngine.ComputeBuffer.CopyCount(arg0, arg1, arg2); } return(true); }
static public int SetCounterValue(IntPtr l) { try { UnityEngine.ComputeBuffer self = (UnityEngine.ComputeBuffer)checkSelf(l); System.UInt32 a1; checkType(l, 2, out a1); self.SetCounterValue(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
protected override void Unload() { if (this.computeBuffer != null) { this.computeBuffer.Release(); } this.computeBuffer = null; if (this.exportToGlobal) { this.ApplyToGlobal(); } base.Unload(); }
static int SetGlobalBuffer(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); string arg0 = ToLua.CheckString(L, 1); UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.CheckObject(L, 2, typeof(UnityEngine.ComputeBuffer)); UnityEngine.Shader.SetGlobalBuffer(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public static Tensor InvokeNormalizationKernel( string name, Tensor input, Tensor scale, Tensor offset ) { var compute = Pix2PixResources.Compute; var kernel = compute.FindKernel(name); uint tgn_x, tgn_y, tgn_z; compute.GetKernelThreadGroupSizes(kernel, out tgn_x, out tgn_y, out tgn_z); var length = input.Data.Length; var channels = input.Shape[2]; Debug.Assert(channels % tgn_x == 0); Debug.Assert(channels == scale.Data.Length); Debug.Assert(channels == offset.Data.Length); var buffer_input = new UnityEngine.ComputeBuffer(length, sizeof(float)); var buffer_scale = new UnityEngine.ComputeBuffer(channels, sizeof(float)); var buffer_offset = new UnityEngine.ComputeBuffer(channels, sizeof(float)); var buffer_output = new UnityEngine.ComputeBuffer(length, sizeof(float)); buffer_input.SetData(input.Data); buffer_scale.SetData(scale.Data); buffer_offset.SetData(offset.Data); compute.SetInts("InputShape", input.Shape); compute.SetInts("OutputShape", input.Shape); compute.SetBuffer(kernel, "Input", buffer_input); compute.SetBuffer(kernel, "Filter", buffer_scale); compute.SetBuffer(kernel, "Bias", buffer_offset); compute.SetBuffer(kernel, "Output", buffer_output); compute.Dispatch(kernel, channels / (int)tgn_x, 1, 1); var output = new Tensor(input.Shape); buffer_output.GetData(output.Data); buffer_input.Dispose(); buffer_scale.Dispose(); buffer_offset.Dispose(); buffer_output.Dispose(); return(output); }