예제 #1
0
        void Awake()
        {
            tiles = GetComponentsInChildren <Tile>();

            if (rect.size == Vector2Int.zero)
            {
                Debug.LogWarning("Invalid rect size");
                return;
            }

            rt = new RenderTexture(rect.width, rect.height, 0, RenderTextureFormat.ARGB32)
            {
                filterMode = FilterMode.Point,
                wrapMode   = TextureWrapMode.Clamp,
            };
            rt.Create();
            OnTextureReady.Invoke(rt);

            tex = new Texture2D(rect.width, rect.height, TextureFormat.ARGB32, true, false)
            {
                filterMode = FilterMode.Point,
                wrapMode   = TextureWrapMode.Clamp,
            };
            tex.Apply();

            tilesPixels = new List <Color32[]>(tiles.Length);
            for (int i = 0; i < tiles.Length; i++)
            {
                tiles[i].rt = rt;
                var r1 = tiles[i].rect;
                tilesPixels.Add(new Color32[r1.width * r1.height]);
            }

            StartCoroutine(Run());
        }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        _processor.ShaderName = Shader.name;
        foreach (var v in ShaderValues)
        {
            switch (v.Type)
            {
            case ShaderValueType.Float:
                _processor.ProcessingMaterial.SetFloat(v.name, float.Parse(v.value));
                break;

            case ShaderValueType.Vec2:
                _processor.ProcessingMaterial.SetVector(v.name, Utilities.ParseVector2(v.value));
                break;

            case ShaderValueType.Vec3:
                _processor.ProcessingMaterial.SetVector(v.name, Utilities.ParseVector3(v.value));
                break;

            case ShaderValueType.Vec4:
                _processor.ProcessingMaterial.SetVector(v.name, Utilities.ParseVector4(v.value));
                break;

            case ShaderValueType.Texture:
                _processor.ProcessingMaterial.SetTexture(v.name, v.texValue);
                break;
            }
        }
        _result.Invoke(_processor.ProcessTexture(_srcTexture, Pass, Downscale));
    }
예제 #3
0
        protected virtual void Update()
        {
            if (width != Screen.width || height != Screen.height || Input.GetKeyDown(KeyCode.R))
            {
                InitializeComputeShader();
            }
            computeShader.SetFloat(diffId, diff);
            computeShader.SetFloat(viscId, visc);
            computeShader.SetFloat(dtId, Time.deltaTime);
            computeShader.SetFloat(velocityCoefId, velocityCoef);
            computeShader.SetFloat(densityCoefId, densityCoef);

            if (!isDensityOnly)
            {
                VelocityStep();
            }
            DensityStep();

            computeShader.SetTexture(kernelMap[ComputeKernels.Draw], densityId, densityTex);
            computeShader.SetTexture(kernelMap[ComputeKernels.Draw], velocityId, velocityTex);
            computeShader.SetTextureFromGlobal(kernelMap[ComputeKernels.Draw], solverId, solverTexId);
            computeShader.Dispatch(kernelMap[ComputeKernels.Draw], Mathf.CeilToInt((float)solverTex.width / gpuThreads.x), Mathf.CeilToInt((float)solverTex.height / gpuThreads.y), 1);
            Shader.SetGlobalTexture(solverTexId, solverTex);

            textureBinding.Invoke(solverTex);
        }
예제 #4
0
        public void SetTexture(string uuid)
        {
            if (String.IsNullOrWhiteSpace(uuid))
            {
                return;
            }

            if (this.uuid != uuid)
            {
                var texture = Textures.Get(uuid);
                this.uuid   = uuid;
                this.cached = texture;

                OnTextureChanged.Invoke(texture);

                if (avatar.IsLocal)
                {
                    avatar.Peer["ubiq.avatar.texture.uuid"] = this.uuid;
                }

                if (avatar.IsLocal && SaveTextureSetting)
                {
                    SaveSettings();
                }
            }
        }
예제 #5
0
 private void OnSucceed(Texture2D tex)
 {
     if (downloadSuceed != null)
     {
         downloadSuceed.Invoke(tex);
     }
 }
    protected virtual void OnStartStreaming(PipelineProfile activeProfile)
    {
        using (var profile = activeProfile.GetStream(sourceStreamType))
        {
            var videoProfile = profile as VideoStreamProfile;
            if (videoProfile == null)
            {
                Debug.LogWarningFormat("{0} not in active profile", sourceStreamType);
                return;
            }

            if (texture != null)
            {
                Destroy(texture);
            }

            texture = new Texture2D(videoProfile.Width, videoProfile.Height, textureFormat, false, true)
            {
                wrapMode   = TextureWrapMode.Clamp,
                filterMode = filterMode
            };
            texture.Apply();
            textureBinding.Invoke(texture);
        }
        if (realSenseDevice.processMode == RealSenseDevice.ProcessMode.UnityThread)
        {
            UnityEngine.Assertions.Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId);
            realSenseDevice.onNewSample += OnNewSampleUnityThread;
        }
        else
        {
            realSenseDevice.onNewSample += OnNewSampleThreading;
        }
    }
예제 #7
0
 /// <summary> Method used by the ThemeManager when the active variant or selected theme have changed </summary>
 /// <param name="theme"> Target theme </param>
 public override void UpdateTarget(ThemeData theme)
 {
     if (Event == null)
     {
         return;
     }
     if (theme == null)
     {
         return;
     }
     base.UpdateTarget(theme);
     if (ThemeId == Guid.Empty)
     {
         return;
     }
     if (PropertyId == Guid.Empty)
     {
         return;
     }
     if (theme.ActiveVariant == null)
     {
         return;
     }
     Event.Invoke(theme.ActiveVariant.GetTexture(PropertyId));
 }
예제 #8
0
    private void ProcessFrame(VideoFrame frame)
    {
        if (HasTextureConflict(frame))
        {
            if (texture != null)
            {
                Destroy(texture);
            }

            using (var p = frame.Profile) {
                bool linear = (QualitySettings.activeColorSpace != ColorSpace.Linear) ||
                              (p.Stream != Stream.Color && p.Stream != Stream.Infrared);
                texture = new Texture2D(frame.Width, frame.Height, Convert(p.Format), false, linear)
                {
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = filterMode
                };
            }

            textureBinding.Invoke(texture);
        }

        texture.LoadRawTextureData(frame.Data, frame.Stride * frame.Height);
        texture.Apply();
    }
예제 #9
0
    protected override void UpdateState()
    {
        RenderTexture.active = _output;
        GL.PushMatrix();
        GL.LoadPixelMatrix(0, 1920, 1080, 0);
        GL.Clear(false, true, Color.black);
        _processor.ProcessingMaterial.SetFloat("_Focus", _focus);
        _processor.ProcessingMaterial.SetFloat("_Size", _size);


        if (_left != null)
        {
            _processor.ProcessingMaterial.SetFloat("_flip", 0);
            Graphics.DrawTexture(new Rect(0, 0, 1920, 1080), _processor.ProcessTexture(_left, 0));
        }
        if (_right != null)
        {
            _processor.ProcessingMaterial.SetFloat("_flip", 1);
            Graphics.DrawTexture(new Rect(0, 0, 1920, 1080), _processor.ProcessTexture(_right, 0));
        }
        GL.PopMatrix();
        RenderTexture.active = null;

        Output.Invoke(_output);
    }
예제 #10
0
파일: TextureInput.cs 프로젝트: mrayy/Klak
 void Update()
 {
     if (tex != _oldTex)
     {
         _tex.Invoke(tex);
         _oldTex = tex;
     }
 }
예제 #11
0
 protected override void UpdateState()
 {
     if (tex != _oldTex)
     {
         _tex.Invoke(tex);
         _oldTex = tex;
     }
 }
예제 #12
0
 // Update is called once per frame
 void UpdateState()
 {
     if (_camSource.Update())
     {
         left.Invoke(_camSource.LeftEye());
         right.Invoke(_camSource.RightEye());
     }
 }
예제 #13
0
 protected void SetAsOutput(RenderTexture tex)
 {
     if (targetCamera != null)
     {
         targetCamera.targetTexture = tex;
     }
     Changed.Invoke(tex);
 }
    private void ResetTexture(VideoStreamRequest vsr)
    {
        if (texture != null)
        {
            Destroy(texture);
        }

        texture = new Texture2D(vsr.Width, vsr.Height, Convert(vsr.Format), false, true)
        {
            wrapMode   = TextureWrapMode.Clamp,
            filterMode = filterMode
        };

        _currVideoStreamFilter = vsr.Clone();

        texture.Apply();
        textureBinding.Invoke(texture);
    }
 protected void InjectSourceColorToImage()
 {
     lerpMat.SetFloat(PROP_LERP_EMISSION, lerpEmission);
     lerpMat.SetFloat(PROP_LERP_DISSIPATION, lerpDissipation);
     lerpMat.SetTexture(PROP_PREV_TEX, _imageTex0.Texture);
     Graphics.Blit(_sourceTex.Texture, _imageTex1.Texture, lerpMat);
     OnUpdateAdvectedImageTexture.Invoke(_imageTex1.Texture);
     SwapImageTexture();
 }
예제 #16
0
    // Update is called once per frame
    void Update()
    {
        Mat LeftIRMat  = Util.toMat((Texture2D)LeftIrTexture, CvType.CV_8UC1);
        Mat RightIRMat = Util.toMat((Texture2D)LeftIrTexture, CvType.CV_8UC1);

        Mat XLeft  = new Mat();
        Mat YLeft  = new Mat();
        Mat XRight = new Mat();
        Mat YRight = new Mat();

        Imgproc.Sobel(LeftIRMat, XLeft, CvType.CV_32F, 1, 0, (int)ksize, scale);
        Imgproc.Sobel(LeftIRMat, YLeft, CvType.CV_32F, 0, 1, (int)ksize, scale);
        Imgproc.Sobel(RightIRMat, XRight, CvType.CV_32F, 1, 0, (int)ksize, scale);
        Imgproc.Sobel(RightIRMat, YRight, CvType.CV_32F, 0, 1, (int)ksize, scale);
        Mat x = XLeft + XRight;
        Mat y = XRight + (YRight);

        DenseOpticalFlow opticalFlow = DISOpticalFlow.create(DISOpticalFlow.PRESET_MEDIUM);

        //OpenCVForUnity.VideoModule.DenseOpticalFlow opticalFlow = new OpenCVForUnity.VideoModule.DenseOpticalFlow(IntPtr.Zero);


        Texture2D xTexture = (Texture2D)Util.toTexture(x, TextureFormat.RFloat);

        xTextureEvent.Invoke(xTexture);

        Texture2D yTexture = (Texture2D)Util.toTexture(y, TextureFormat.RFloat);

        yTextureEvent.Invoke(yTexture);

        Mat x8Bit = new Mat();
        Mat y8Bit = new Mat();

        x.convertTo(x8Bit, CvType.CV_8UC1, 0.1f);
        y.convertTo(y8Bit, CvType.CV_8UC1, 0.1f);

        Mat flow = new Mat();

        opticalFlow.calc(y8Bit, x8Bit, flow);
        List <Mat> planes = new List <Mat> ();

        // split
        Core.split(flow, planes);

        Texture2D flowTexture = new Texture2D(LeftIrTexture.width, LeftIrTexture.height, TextureFormat.RFloat, false);

        Utils.fastMatToTexture2D(planes[(int)flowPlane], flowTexture);
        flowTextureEvent.Invoke(flowTexture);


        //Mat canneyRslt = new Mat();
        //Imgproc.Canny(,,IRMat, canneyRslt, threshold1, threshold2);


        //Imgproc.Canny(IRMat, canneyRslt, threshold1, threshold2);
    }
예제 #17
0
 void CreateOutput(RenderTexture s)
 {
     if (output != null)
     {
         output.Release();
     }
     output = new RenderTexture(s.width, s.height, s.depth, s.format);
     output.Create();
     onCreateOutput.Invoke(output);
 }
 // Use this for initialization
 public void Create()
 {
     if (RenderTextureCamera.targetTexture != null)
     {
         RenderTextureCamera.targetTexture.Release();
     }
     renderTexture = new RenderTexture(TemplateRenderTexture);
     RenderTextureCamera.targetTexture = renderTexture;
     RenderTextureEvent.Invoke(renderTexture);
 }
예제 #19
0
    void Start()
    {
        var cam           = GetComponent <Camera>();
        var width         = cam.pixelWidth;
        var height        = cam.pixelHeight;
        var targetTexture = Helper.CreateRenderTexture(width, height);

        onCreateTarget.Invoke(targetTexture);
        cam.targetTexture = targetTexture;
    }
예제 #20
0
 // Update is called once per frame
 void Update()
 {
     if (!Active)
     {
         return;
     }
     if (_eyes != null)
     {
         _leftEye.Invoke(_eyes.LeftEye);
         _rightEye.Invoke(_eyes.RightEye);
         _config.Invoke(_eyes.Configuration);
     }
     else
     {
         _leftEye.Invoke(null);
         _rightEye.Invoke(null);
         _config.Invoke(null);
     }
 }
예제 #21
0
    protected void SetOutputTexture(RenderTexture tex)
    {
        var c = GetCamera();

        if (c != null)
        {
            c.targetTexture = tex;
        }
        Changed.Invoke(tex);
    }
예제 #22
0
 public void Start()
 {
     tex = new Texture2D(1024, 1);
     for (int i = 0; i < tex.width; i++)
     {
         float t = (float)i / (float)tex.width;
         tex.SetPixel(i, 0, gradient.Evaluate(t));
     }
     tex.Apply();
     TextureBinding.Invoke(tex);
 }
    private void SetTexture(RenderTexture captured)
    {
        var c = GetCamera();

        if (c != null)
        {
            c.targetTexture = captured;
        }

        Changed.Invoke(captured);
    }
예제 #24
0
        void Update()
        {
            if (_outputTex == null || _outputTex.width != _attachedCamera.pixelWidth || _outputTex.height != _attachedCamera.pixelHeight)
            {
                ReleaseTexture();
                _outputTex = new RenderTexture(_attachedCamera.pixelWidth, _attachedCamera.pixelHeight, 24, format);
            }

            _attachedCamera.targetTexture = _outputTex;
            OnCapture.Invoke(_outputTex);
        }
예제 #25
0
    // Update is called once per frame
    void Update()
    {
        Mat IRMat = Util.toMat((Texture2D)IRtexture, CvType.CV_8UC3);

        Mat canneyRslt = new Mat();

        Imgproc.Canny(IRMat, canneyRslt, threshold1, threshold2);

        Texture2D cannyTexture = (Texture2D)Util.toTexture(canneyRslt, TextureFormat.R8);

        textureBinding.Invoke(cannyTexture);
    }
예제 #26
0
        // Use this for initialization
        void Start()
        {
            rt3d                   = new RenderTexture(size, size, 0, format);
            rt3d.isVolume          = true;
            rt3d.volumeDepth       = size;
            rt3d.enableRandomWrite = true;
            rt3d.wrapMode          = TextureWrapMode.Repeat;
            rt3d.Create();
            rt3d.name = this.ToString() + ".rt3d";

            onCreateTexture.Invoke(rt3d);
            Render();
        }
예제 #27
0
    public void OnPostRenderUpdate()
    {
        if (frame3Dgpu == null)
        {
            return;
        }

        //		fullSizeBinding.Invoke(frame3D.filteredImage);
        //		previewBinding.Invoke(frame3D.smallFilteredImage);

        // just refering one of filtered effect. Not processed here
        //		if(lut != null)
        //			if (lut.LUT != null)
        //				lut.filterImage(frame3Dgpu, filterStrength);

        // change invoke texture if lut is set or not.

        if (frame3Dgpu.snapped)
        {
            // This function uses readback data from GPU memory. So need to be called after Rendered
            WaterMarkFrame3D(frame3Dgpu, watermark, watermarkDepth);
        }

        if (lut != null)
        {
            textureBinding.Invoke(frame3Dgpu.recoloredImages[lut.index]);
        }
        else
        {
            textureBinding.Invoke(frame3Dgpu.filteredImage);
        }

        // only when snapped, it will invoke to save file
        if (frame3Dgpu.snapped)
        {
            frame3DgpuBinding.Invoke(frame3Dgpu);
        }
    }
예제 #28
0
    // Update is called once per frame
    protected override void UpdateState()
    {
        if (Index != _camSource.CameraIndex)
        {
            _camSource.StopPlayer();
            _camSource.CameraIndex = _index;
            _camSource.Width       = Width;
            _camSource.Height      = Height;
            _camSource.StartPlayer();
        }

        if (texture.GetPersistentEventCount() > 0)
        {
            if (ProcessedImage)
            {
                texture.Invoke(_camSource.VideoTexture);
            }
            else
            {
                texture.Invoke(_camSource.SourceTexture);
            }
        }
    }
예제 #29
0
        void Update()
        {
            if (updateMode == UpdateMode.Update)
            {
                if (image == null)
                {
                    return;
                }

                if (blur.Render(image, ref blurred, iterations, lod))
                {
                    BlurredOnCreate.Invoke(blurred);
                }
            }
        }
예제 #30
0
    private void updateFilteredRGBImage()
    {
        // lut filter here
        Vector3[] corners   = new Vector3[4];
        Vector3[] vpcorners = new Vector3[4];
        gameObject.GetComponent <RectTransform>().GetWorldCorners(corners);
        UnityEngine.Rect screenRect = new UnityEngine.Rect(0, 0, Screen.width, Screen.height);
        bool             onscreen   = screenRect.Contains((Vector2)corners[0]) || screenRect.Contains((Vector2)corners[2]);

        if (onscreen)
        {
            if (lut != null)
            {
                if (lut.filterImage(frame3dgpu, brightness, contrast, filterStrength))
                {
                    textureBinding.Invoke(frame3dgpu.recoloredImages[lut.index]);
                }
            }
            else
            {
                textureBinding.Invoke(frame3dgpu.filteredImage);
            }
        }
    }