当前位置: 首页>>代码示例>>C#>>正文


C# ComputeBuffer.SetData方法代码示例

本文整理汇总了C#中UnityEngine.ComputeBuffer.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# ComputeBuffer.SetData方法的具体用法?C# ComputeBuffer.SetData怎么用?C# ComputeBuffer.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.ComputeBuffer的用法示例。


在下文中一共展示了ComputeBuffer.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WallService

 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);
 }
开发者ID:sugi-cho,项目名称:ParticlePhysics,代码行数:8,代码来源:WallService.cs

示例2: Awake

        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);
        }
开发者ID:nobnak,项目名称:InstancingExampleUnity,代码行数:27,代码来源:Instancing.cs

示例3: Init

    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);
    }
开发者ID:mqmtech,项目名称:ShadersDemo,代码行数:34,代码来源:GPUParticleSystem.cs

示例4: CreateResources

    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);
        }
    }
开发者ID:jaronimoe,项目名称:cellVIEW_animated,代码行数:58,代码来源:DrawBillboards.cs

示例5: HashService

 public HashService(ComputeShader compute, LifeService l, PositionService p)
 {
     _compute = compute;
     _lifes = l;
     _positions = p;
     _kernelInitHashes = compute.FindKernel(ShaderConst.KERNEL_INIT_HASHES);
     HashData = new int[l.Lifes.count];
     Hashes = new ComputeBuffer(l.Lifes.count, Marshal.SizeOf(typeof(int)));
     Hashes.SetData (HashData);
 }
开发者ID:nobnak,项目名称:ParticlePhysics,代码行数:10,代码来源:HashService.cs

示例6: PositionService

 public PositionService(ComputeShader compute, int capacity)
 {
     _kernelUpload = compute.FindKernel(ShaderConst.KERNEL_UPLOAD_POSITION);
     _compute = compute;
     _positions = new Vector2[capacity];
     P0 = new ComputeBuffer(capacity, Marshal.SizeOf(_positions[0]));
     P0.SetData(_positions);
     _uploader = new ComputeBuffer(INITIAL_CAP, Marshal.SizeOf(_positions[0]));
     ShaderUtil.CalcWorkSize(capacity, out SimSizeX, out SimSizeY, out SimSizeZ);
 }
开发者ID:nobnak,项目名称:ParticlePhysics,代码行数:10,代码来源:PositionService.cs

示例7: LifeService

        public LifeService(ComputeShader compute, int capacity)
        {
            _compute = compute;
            _kernelSimulate = compute.FindKernel(ShaderConst.KERNEL_SIMULATE_LIFE);
            _kernelUpload = compute.FindKernel(ShaderConst.KERNEL_UPLOAD_LIFE);
            _lifes = new float[capacity];
            Lifes = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(float)));
            Lifes.SetData(_lifes);
            _uploader = new ComputeBuffer(INIT_CAPACITY, Marshal.SizeOf(typeof(float)));

            ShaderUtil.CalcWorkSize(capacity, out SimSizeX, out SimSizeY, out SimSizeZ);
        }
开发者ID:nobnak,项目名称:ParticlePhysics,代码行数:12,代码来源:LifeService.cs

示例8: GetClusters

    public static List<Vector4> GetClusters(List<Vector4> atoms, int numCentroids)
    {
        if (ComputeShaderManager.Instance.KMeansCS == null) throw new Exception("KMeans compute shader not assigned");

        if (numCentroids <= 0) throw new Exception("Num centroids too low");

        var centroids = new List<Vector4>();
        var centroidStep = Mathf.CeilToInt(atoms.Count / (float)numCentroids);
        for (int i = 0; i < numCentroids; i++)
        {
            if (i*centroidStep < atoms.Count)
            {
                centroids.Add(atoms[i * centroidStep]);
            }
            else
            {
                centroids.Add(atoms[UnityEngine.Random.Range(0, atoms.Count)]);
            }
        }

        var centroidBuffer = new ComputeBuffer(numCentroids, 4 * sizeof(float));
        centroidBuffer.SetData(centroids.ToArray());

        var pointBuffer = new ComputeBuffer(atoms.Count, 4 * sizeof(float));
        pointBuffer.SetData(atoms.ToArray());

        var membershipBuffer = new ComputeBuffer(atoms.Count, sizeof(int));

        ComputeShaderManager.Instance.KMeansCS.SetInt("_NumPoints", atoms.Count);
        ComputeShaderManager.Instance.KMeansCS.SetInt("_NumCentroids", numCentroids);

        for (int i = 0; i < 5; i++)
        {
            ComputeShaderManager.Instance.KMeansCS.SetBuffer(0, "_PointBuffer", pointBuffer);
            ComputeShaderManager.Instance.KMeansCS.SetBuffer(0, "_CentroidBuffer", centroidBuffer);
            ComputeShaderManager.Instance.KMeansCS.SetBuffer(0, "_MembershipBuffer", membershipBuffer);
            ComputeShaderManager.Instance.KMeansCS.Dispatch(0, Mathf.CeilToInt(atoms.Count / 1), 1, 1);

            ComputeShaderManager.Instance.KMeansCS.SetBuffer(1, "_PointBuffer", pointBuffer);
            ComputeShaderManager.Instance.KMeansCS.SetBuffer(1, "_NewCentroidBuffer", centroidBuffer);
            ComputeShaderManager.Instance.KMeansCS.SetBuffer(1, "_NewMembershipBuffer", membershipBuffer);
            ComputeShaderManager.Instance.KMeansCS.Dispatch(1, Mathf.CeilToInt(numCentroids / 64.0f), 1, 1);
        }

        var newCentroids = new Vector4[numCentroids];
        centroidBuffer.GetData(newCentroids);

        pointBuffer.Release();
        centroidBuffer.Release();
        membershipBuffer.Release();

        return newCentroids.ToList();
    }
开发者ID:matmuze,项目名称:VIZZIES,代码行数:53,代码来源:KMeansClustering.cs

示例9: VelocityService

 public VelocityService(ComputeShader compute, int capacity)
 {
     _kernelUpload = compute.FindKernel(ShaderConst.KERNEL_UPLOAD_VELOCITY);
     _kernelClampVelocity = compute.FindKernel(ShaderConst.KERNEL_CLAMP_VELOCITY);
     _compute = compute;
     _velocities = new Vector2[capacity];
     V0 = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Vector2)));
     V1 = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Vector2)));
     V0.SetData(_velocities);
     V1.SetData(_velocities);
     _uploader = new ComputeBuffer(INITIAL_CAP, Marshal.SizeOf(_velocities[0]));
     ShaderUtil.CalcWorkSize(capacity, out SimSizeX, out SimSizeY, out SimSizeZ);
 }
开发者ID:nobnak,项目名称:ParticlePhysics,代码行数:13,代码来源:VelocityService.cs

示例10: CreateComputeResources

 void CreateComputeResources()
 {
     if (cbDrawArgs == null)
     {
         cbDrawArgs = new ComputeBuffer (1, 16, ComputeBufferType.DrawIndirect);
         var args= new int[4];
         args[0] = 0; args[1] = 1; args[2] = 0; args[3] = 0;
         cbDrawArgs.SetData (args);
     }
     if (cbPoints == null)
     {
         cbPoints = new ComputeBuffer (90000, 12+16, ComputeBufferType.Append);
     }
 }
开发者ID:hongaaronc,项目名称:IntermediateGame,代码行数:14,代码来源:DepthOfField.cs

示例11: InitiateBuffers

	void InitiateBuffers()
	{
		bar[] values = new bar[WIDTH*HEIGHT];
		for(int i=0; i < WIDTH*HEIGHT; ++i)
		{
			values[i].Position = 5.0f;
			values[i].Velocity = 0.0f;
			values[i].h		   = 1.0f;
		}

//		Debug.Log(Marshal.SizeOf(bar));
		_BarBuffer = new ComputeBuffer(WIDTH*HEIGHT, sizeof(float)*3);
		_BarBuffer.SetData(values);
	}
开发者ID:jonwa,项目名称:Project-Alix,代码行数:14,代码来源:SimulateWater.cs

示例12: CreateBuffers

    //To setup a ComputeBuffer we pass in the array length, as well as the size in bytes of a single element.
    //We fill the offset buffer with random numbers between 0 and 2*PI.
    void CreateBuffers() {
        offsetBuffer = new ComputeBuffer(VertCount, 4); //Contains a single float value (OffsetStruct)

        float[] values = new float[VertCount];

        for (int i = 0; i < VertCount; i++) {
            values[i] = Random.value * 2 * Mathf.PI;
        }

        offsetBuffer.SetData(values);

        constantBuffer = new ComputeBuffer(1, 4); //Contains a single element (time) which is a float

        outputBuffer = new ComputeBuffer(VertCount, 12); //Output buffer contains vertices (float3 = Vector3 -> 12 bytes)
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:17,代码来源:PanbakedCS.cs

示例13: Start

    void Start()
    {
        // Setup the base args buffer
        particleLocations = new Vector4[particleCount];
        //particleColors = new Vector4[particleCount];
        particleTargets = new Vector4[particleCount];

        for (int i = 0; i < particleCount; i++)
        {
            // Generate a random location
            Vector3 newLoc = Random.insideUnitSphere * 0.5f + new Vector3(0.5f,0.5f,0.5f);
            particleLocations[i] = new Vector4(newLoc.x, newLoc.y, newLoc.z, particlePower);
            particleTargets[i] = newLoc;
            //particleColors[i] = new Vector3(Random.value, Random.value, Random.value);
        }

        targetBuffer = new ComputeBuffer(particleCount, 16);
        targetBuffer.SetData(particleTargets);

        //particleColorBuffer = new ComputeBuffer(particleCount, 16);
        //particleColorBuffer.SetData(particleColors);

        particleBuffer = new ComputeBuffer(particleCount, 16);
        particleBuffer.SetData(particleLocations);

        int pixelCount = textureSize * textureSize * textureSize;

        tex3D = new Texture3D( textureSize, textureSize, textureSize, TextureFormat.ARGB32, false);
        tex3D.wrapMode = TextureWrapMode.Clamp;
        tex3D.anisoLevel = 0;

        pixels = new Color[pixelCount];
        volumeBuffer = new ComputeBuffer(pixelCount, 16);
        volumeBuffer.SetData(pixels);

        /*
        volume = new RenderTexture(textureSize, textureSize, 0, RenderTextureFormat.ARGB32);
        volume.volumeDepth = textureSize;
        volume.isVolume = true;
        volume.enableRandomWrite = true;
        volume.Create();
        */

        //renderer.material.SetTexture ("_Volume", tex3D);
        //renderer.material.SetTexture ("_Volume", volume);
        //renderer.material.SetTexture("_dataFieldTex", tex3D);
        marchingCubesMaterial.SetTexture("_dataFieldTex", tex3D);
    }
开发者ID:kristofe,项目名称:UnityGPUMarchingCubes,代码行数:48,代码来源:ParticlesRenderInto3DCS.cs

示例14: GridService

        public GridService(ComputeShader compute, Grid g, HashService h)
        {
            _compute = compute;
            _grid = g;
            _hashes = h;
            _kernelInit = compute.FindKernel(ShaderConst.KERNEL_INIT_GRID);
            _kernelConstruct = compute.FindKernel(ShaderConst.KERNEL_CONSTRUCT_GRID);
            var gridCellCount = g.nx * g.ny;

            StartData = new uint[gridCellCount];
            EndData = new uint[gridCellCount];
            _hashGridStart = new ComputeBuffer(gridCellCount, Marshal.SizeOf(typeof(uint)));
            _hashGridEnd = new ComputeBuffer(gridCellCount, Marshal.SizeOf(typeof(uint)));
            _hashGridStart.SetData (StartData);
            _hashGridEnd.SetData (EndData);
        }
开发者ID:nobnak,项目名称:ParticlePhysics,代码行数:16,代码来源:GridService.cs

示例15: InitializeBuffers

    void InitializeBuffers() {
        VertCount = 10 * 10 * 10 * cubeMultiplier * cubeMultiplier * cubeMultiplier;

        outputBuffer = new ComputeBuffer(VertCount, (sizeof(float) * 3) + (sizeof(int) * 6));
        mapBuffer = new ComputeBuffer(VertCount, sizeof(int));

        int width = 10 * cubeMultiplier;
        int height = 10 * cubeMultiplier;
        int depth = 10 * cubeMultiplier;

        TestNoise noise = new TestNoise(1f, 1f, 3);
        float[][] tempNoiseHeight = new float[10 * cubeMultiplier][];
        for(int i = 0; i < tempNoiseHeight.Length; i++) {
            tempNoiseHeight[i] = new float[10 * cubeMultiplier];

            for(int j = 0; j < tempNoiseHeight[i].Length; j++) {
                tempNoiseHeight[i][j] = noise.GetNoise((double)(i) * 0.05, (double)(j) * 0.14, 0.0) * 0.5f + 0.5f; //UnityEngine.Random.Range(0f, 1f);
            }
        }

        int[] map = new int[VertCount];

        for(int x = 0; x < width; x++) {
            for(int y = 0; y < height; y++) {
                for(int z = 0; z < depth; z++) {
                    int idx = x + (y * 10 * cubeMultiplier) + (z * 10 * cubeMultiplier * 10 * cubeMultiplier);

                    if (tempNoiseHeight[x][z] >= y / (float)height)
                        map[idx] = 1;
                    else
                        map[idx] = 0;
                }
            }
        }

        mapBuffer.SetData(map);

        computeShader.SetBuffer(CSKernel, "outputBuffer", outputBuffer);
        computeShader.SetBuffer(CSKernel, "mapBuffer", mapBuffer);

        computeShader.SetVector("group_size", new Vector3(cubeMultiplier, cubeMultiplier, cubeMultiplier));

        if (Debugrender)
            PointMaterial.SetBuffer("buf_Points", outputBuffer);

        transform.position -= (Vector3.one * 10 * cubeMultiplier) * 0.5f;
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:47,代码来源:TestVoxelComputeShaderOutput.cs


注:本文中的UnityEngine.ComputeBuffer.SetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。