UnityEngine.ComputeShader.SetFloat C# (CSharp) Method

SetFloat() public method

Set a float parameter.

public SetFloat ( string name, float val ) : void
name string Variable name in shader code.
val float Value to set.
return void
        public void SetFloat(string name, float val)
        {
            this.SetFloat(Shader.PropertyToID(name), val);
        }

Same methods

ComputeShader::SetFloat ( int nameID, float val ) : void

Usage Example

コード例 #1
0
    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);
    }
All Usage Examples Of UnityEngine.ComputeShader::SetFloat