Giter Site home page Giter Site logo

Comments (4)

karasusan avatar karasusan commented on July 18, 2024

@Julius-Caesar6
Can you give me a code snippet to replicate your issue?

from com.unity.webrtc.

Julius-Caesar6 avatar Julius-Caesar6 commented on July 18, 2024

Of course. In the VideoReceive sample in VideoReceiveSample.cs from line 81 ("video.OnVideoReceived += tex =>") instead of line 83: "receiveImage.texture =tex;", paste this code:
` // Original line where rawImage texture is set to tex.
// receiveImage.texture = tex;
Texture2D originalReceivedTexture = tex as Texture2D;

                    // Setting rawImage texture to the Texture2D also works and gives the correct live view.
                    // receiveImage.texture = originalReceivedTexture; 

                    // Get pixels of texture into array of Colors.
                    Color[] texturePixels = originalReceivedTexture.GetPixels();

                    // Pixel manipulation ... (for example grayscaling)

                    // Apply pixels back to new texture
                    Texture2D processedTexture = new Texture2D(tex.width, tex.height);
                    processedTexture.SetPixels(texturePixels);
                    processedTexture.Apply();
                    
                    // In this instance in play mode the rawImage only shows a gray image. 
                    receiveImage.texture = processedTexture;`

So what happens is that by doing nothing to the pixels yet and just getting them from one texture and setting them to another, the live aspect is somehow lost. I don't necessarily need to set the pixels to a new texture (in this snippet it is just to illustrate), but need the live pixel values of "tex".

Thank you for your time and help!

from com.unity.webrtc.

karasusan avatar karasusan commented on July 18, 2024

@Julius-Caesar6
Hi, thanks for the detail, I replicated your issue.
originalReceivedTexture is updated asynchronously on GPU. CPU memory in texture is not updated, therefore GetPixels returns gray color buffer.

Can you try ReadPixels instead of GetPixels? ReadPixels can read CPU memory from rendertarget.
In addition, reading CPU memory is high cost generally, please check the performance.  

from com.unity.webrtc.

Julius-Caesar6 avatar Julius-Caesar6 commented on July 18, 2024

@karasusan
Thank you for you reply!
I will try your recommendations and see if I can get it working.

from com.unity.webrtc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.