Exemplo n.º 1
0
        void Start()
        {
            _sourceTexture = new RenderTexture(256, 256, 0);
            _resultTexture = new RenderTexture(256, 256, 0);

            _sourceTexture.filterMode        = FilterMode.Point;
            _resultTexture.enableRandomWrite = true;

            _sourceTexture.Create();
            _resultTexture.Create();

            Graphics.Blit(_defaultTexture, _sourceTexture);

            _sourceRenderer.material.mainTexture = _sourceTexture;
            _resultRenderer.material.mainTexture = _resultTexture;

            _lineMaterial       = new Material(_shader);
            _lineMaterial.color = Color.black;

            _lineMesh = new Mesh();
            _lineMesh.MarkDynamic();
            _lineMesh.vertices = new Vector3[2];
            _lineMesh.SetIndices(new[] { 0, 1 }, MeshTopology.Lines, 0);

            _eraserMaterial       = new Material(_shader);
            _eraserMaterial.color = Color.white;

            _eraserMesh = new Mesh();
            _eraserMesh.MarkDynamic();
            _eraserMesh.vertices = new Vector3[4];
            _eraserMesh.SetIndices(new[] { 0, 1, 2, 1, 3, 2 }, MeshTopology.Triangles, 0);

            _weightTable  = WeightReader.ReadFromFile(Path.Combine(Application.streamingAssetsPath, _weightFileName));
            _sourceTensor = new Tensor(new[] { 256, 256, 3 });
        }
Exemplo n.º 2
0
        void OnDestroy()
        {
            Destroy(_sourceTexture);
            Destroy(_resultTexture);

            Destroy(_lineMaterial);
            Destroy(_lineMesh);

            Destroy(_eraserMaterial);
            Destroy(_eraserMesh);

            WeightReader.DisposeTable(_weightTable);
            _sourceTensor.Dispose();
        }
Exemplo n.º 3
0
        void OnDestroy()
        {
            GpuHelper.ReleaseAllBuffers();

            Destroy(_sourceTexture);
            Destroy(_resultTexture);

            Destroy(_lineMaterial);
            Destroy(_lineMesh);

            Destroy(_eraserMaterial);
            Destroy(_eraserMesh);

            WeightReader.DisposeTable(_weightTable);
            _sourceTensor.Dispose();
            _resultTensor.Dispose();
        }
Exemplo n.º 4
0
        void Start()
        {
            var weights = Path.Combine(Application.streamingAssetsPath, _weightFileName);

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            var result = ImageFilter.Deprocess(
                Generator.Apply(
                    ImageFilter.Preprocess(_sourceTexture),
                    WeightReader.ReadFromFile(weights)
                    )
                );

            stopwatch.Stop();
            Debug.Log("Done. Total inference time is " + stopwatch.Elapsed);

            GetComponent <MeshRenderer>().material.mainTexture = result;
        }