🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

how to pass n last frames into shader by unity

Started by
0 comments, last by AhmedSaleh 3 years, 7 months ago

I have video Input source that is feeding my App with frames, and I would like to pass the last N frames into the shader (as textures) and get the result of shader as a texture.

It should be similar to cyclic buffer of N textures when on each frame I insert the frame into it and remove the oldest one.

I have tried the following code, but it doesn't feed my shader with the Last N Frames correctly:

   public void Filter_Left(ref Texture2D source)
        {
            Graphics.Blit(source, src_left);

            if (_historyPagesLeft == null)
            {
                           

                _historyPagesLeft = new RenderTexture[HISTORY_CAPACITY];
                for (int i = 0; i < HISTORY_CAPACITY; i++)
                {

                    _historyPagesLeft[i] = new RenderTexture(src_left);

                    filterMaterialAssetLeft.SetTexture(_historyIDs[i], _historyPagesLeft[i]);

                }
            }

            filterMaterialAssetLeft.SetFloat("_dataDelta", dataDelta);
            filterMaterialAssetLeft.SetFloat("_blurRadius", _blurRadius);
            filterMaterialAssetLeft.SetFloat("_stepsDelta", _stepsDelta);
            filterMaterialAssetLeft.SetFloat("_StandardDeviation", _StandardDeviation);

            Graphics.Blit(source, dest_left, filterMaterialAssetLeft);

            left_queue.Enqueue(src_left);
            if (left_queue.Count == HISTORY_CAPACITY)
            {

                for (int i = 0; i < HISTORY_CAPACITY; i++)
                {
                    RenderTexture s = left_queue.Dequeue();
                    filterMaterialAssetLeft.SetTexture(_historyIDs[i], s);
                }
            }


        }
Game Programming is the process of converting dead pictures to live ones .

This topic is closed to new replies.

Advertisement