Пример #1
0
        /*
         * Private methods
         */

        private static void StartGPU(DataType type, HeadsetModel headset, ElectrodePattern pattern, ElectrodeLayout layout, string path)
        {
            var shader = LoadAsset <ComputeShader>($"{type}");
            var kernel = shader.FindKernel("CSMain");

            var electrodeBuffer = default(ComputeBuffer);

            if (type == DataType.Phosphene)
            {
                var electrodes = pattern.GetElectrodePositions(layout);
                electrodeBuffer = new ComputeBuffer(electrodes.Length, sizeof(float) * 2);
                electrodeBuffer.SetData(electrodes);
                shader.SetBuffer(kernel, "_electrodes", electrodeBuffer);
            }

            var texture = headset.CreateRenderTexture();

            shader.SetTexture(kernel, "_result", texture);
            shader.SetVector("_headset_diameter", headset.GetRetinalDiameter());
            shader.SetVector("_headset_resolution", headset.GetResolution());

            shader.Dispatch(kernel, headset.GetWidth() / 8, headset.GetHeight() / 8, 1);
            electrodeBuffer?.Dispose();

            Texture2D asset = texture.ToTexture2D(TextureFormat.RGBAFloat, true);

            texture.Release();

            asset.anisoLevel = 0;
            asset.filterMode = FilterMode.Point;

            if (type == DataType.Phosphene)
            {
                AddRandomSeeds(asset);
            }

            SaveAsset(asset, path);
        }