Example #1
0
        protected void OnEnable()
        {
            var desc = new RenderTextureDescriptor(this.textureSize.x, this.textureSize.y, RenderTextureFormat.RFloat, 0, 0);

            desc.enableRandomWrite = true;
            desc.sRGB = false;
            this.electricalPotentialGrid = new CircleRT(2, desc);

            this.dispatcher = new ComputeShaderDispatcher(this.cs);
            this.dispatcher.AddParameter("Init", this.parameter);
            this.dispatcher.AddParameter("JacobiStep", this.parameter);
            this.dispatcher.AddParameter("WeightSum", this.parameter);
            this.dispatcher.AddParameter("SetBoundary", this.parameter);

            this.dispatcher.AddParameter("InitDart", this.parameter);
            this.dispatcher.AddParameter("InitDartLeaderChargeDensity", this.parameter);
            this.dispatcher.AddParameter("UpdateDartLeader", this.parameter);


            this.parameter.potentialBoundaryTex.Value = TextureManager.Create(desc);
            this.parameter.dartLeaderTex.Value        = TextureManager.Create(desc);

            var count = this.textureSize.x * this.textureSize.y;

            this.parameter.adjacentWeight.Value = new ComputeBuffer(count, Marshal.SizeOf <float>());


            this.parameter.potentialBoundaryInputTex.Value = TextureManager.Create(this.textureSize.x, this.textureSize.y, TextureFormat.RGFloat, false, true);
            (this.parameter.potentialBoundaryInputTex.Value as Texture2D).Apply();

            this.parameter.displayTex.Value = TextureManager.Create(this.textureSize.x, this.textureSize.y, TextureFormat.ARGB32);

            this.parameter.obstacleTex.Value = TextureManager.Create(this.textureSize.x, this.textureSize.y, TextureFormat.RFloat, false, true);
        }
Example #2
0
        protected void CheckBufferChanged(GPUBufferVariable <T> source)
        {
            if (this.hashData.objectBufferSorted == null || this.hashData.objectBufferSorted.Size != source.Size)
            {
                //use source as object buffer
                this.hashData.objectBuffer.InitBuffer(source);
                //create new buffer for sorted data
                this.hashData.objectBufferSorted.InitBuffer(source.Size);
                //create new buffer for object index
                this.hashData.objectGridIndexBuffer.InitBuffer(source.Size);

                this.dispatcher = new ComputeShaderDispatcher <Kernel>(this.gridCS);
                foreach (Kernel k in Enum.GetValues(typeof(Kernel)))
                {
                    this.dispatcher.AddParameter(k, this.gridData);
                    this.dispatcher.AddParameter(k, this.hashData);
                }
            }
            else
            {
                this.hashData.objectBuffer.UpdateBuffer(source);
            }

            var gs = this.gridData.gridSize;

            this.hashData.hashTableSize = gs.x * gs.y * gs.z;
        }
        protected void OnEnable()
        {
            LogTool.AssertIsTrue(this.computeShader != null);

            this.dispatcher = new ComputeShaderDispatcher(this.computeShader);
            this.dispatcher.AddParameter(WindowKernel, this.data);
            this.dispatcher.AddParameter(MaxKernel, this.data);
        }
Example #4
0
        protected void InitDispatcher()
        {
            this.defaultDispatcher = new ComputeShaderDispatcher <DefaultKernel>(this.computeShader);
            foreach (DefaultKernel e in System.Enum.GetValues(typeof(DefaultKernel)))
            {
                this.defaultDispatcher.AddParameter(e, this.data);
            }

            this.dispatcher = new ComputeShaderDispatcher <Kernel>(this.computeShader);
            foreach (Kernel e in System.Enum.GetValues(typeof(Kernel)))
            {
                this.dispatcher.AddParameter(e, this.data);
            }
        }
Example #5
0
        protected void OnEnable()
        {
            this.Init(this.gridData.gridSize);
            this.parameter.particleBuffer.InitBuffer(this.numOfParticles, true, false);
            foreach (var i in Enumerable.Range(0, this.parameter.particleBuffer.Size))
            {
                var rand = new float3(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
                rand -= 0.5f;
                this.parameter.particleBuffer.CPUData[i].pos = this.space.TRS.MultiplyPoint(rand);
                this.parameter.particleBuffer.CPUData[i].col = 1;
            }
            this.parameter.particleBuffer.SetToGPUBuffer(true);

            this.particleDispather = new ComputeShaderDispatcher(this.particleCS);
            this.particleDispather.AddParameter("ResetColor", this.parameter);
            this.particleDispather.AddParameter("UpdateColor", this.parameter);
            this.particleDispather.AddParameter("UpdateColor", this.gridData);
        }
Example #6
0
        protected void OnEnable()
        {
            this.data.input     = this.input.Clone() as Texture2D;
            this.data.maskedTex = this.input.Clone() as Texture2D;
            this.data.template  = this.template.Clone() as Texture2D;

            var desc = new RenderTextureDescriptor(this.input.width, this.input.height, RenderTextureFormat.ARGBFloat);

            desc.enableRandomWrite = true;
            this.data.resultTex    = TextureManager.Create(desc);

            this.dispatcher = new ComputeShaderDispatcher(this.shader);
            this.dispatcher.AddParameter("Process", this.data);

            var tm = this.GetComponent <TextureReduction>();

            tm.Init(this.data.resultTex);

            //calculate result for each pixel
            var domain = new int2(input.width - template.width, input.height - template.height);

            this.dispatcher.Dispatch("Process", domain.x, domain.y);
            //find max value from result texture
            var result = tm.GetReductionResult();

            Debug.Log(result);

            var pixel = result.xy.FloorToInt();
            var h     = new int2(template.width, template.height);

            foreach (var u in Enumerable.Range(0, template.width))
            {
                foreach (var v in Enumerable.Range(0, template.height))
                {
                    this.data.maskedTex.SetPixel(pixel.x + u, pixel.y + v, Color.red);
                }
            }
            this.data.maskedTex.Apply();
        }
Example #7
0
 public static ComputeShaderDispatcher CreateDispatcher(this IComputeShader shader)
 {
     return(ComputeShaderDispatcher.Create(shader));
 }