Skip to content

Texture Blinking Issue #9

Description

@MurkesM

I'm using, await AsyncImageLoader.LoadImageAsync(tex, byteArray); and it loads the correct texture and is greatly increasing performance but the main issue is sometimes the texture loads as completely black for 1 frame and it happens multiple times every second causing the texture to blink. I'm not simply loading a static texture but instead loading a series of textures that play a video. Any thoughts on what might be causing this?

video of the issue:
https://user-images.githubusercontent.com/91104156/204570541-7a66809b-432d-443b-95a1-705793665cbe.mp4

Activity

  1. Looooong commented on Nov 29, 2022

    @Looooong
    Owner

    The texture is black initially because the texture data is being uploaded from the CPU to the GPU and the transfer is not finished yet. You can check the troubleshooting guide here.

    In your case, you can implement something like double-buffering. Make an additional texture which acts as a buffer and is displayed on the screen. When you finished loading texture from file, transfer the texture data on the GPU to this buffer texture using shader or compute shader. This will only present a black screen at first when the buffer texture is not initialized. There will be no black screen when the buffer texture is updated with new frame.

  2. MurkesM commented on Nov 29, 2022

    @MurkesM
    Author

    I'm not sure exactly what you mean or how to do this part: " When you finished loading texture from file, transfer the texture data on the GPU to this buffer texture using shader or compute shader."

  3. Looooong commented on Nov 30, 2022

    @Looooong
    Owner

    Something like this:

    var bufferTexture = new RenderTexture(...);
    
    var frame0 = await AsyncImageLoader.LoadImageAsync(...); // This loads image from disk -> CPU side -> GPU side
    Graphics.Blit(frame0, bufferTexture); // Transfer texture data to the buffer only on the GPU side.
    
    var frame1 = await AsyncImageLoader.LoadImageAsync(...);
    Graphics.Blit(frame1, bufferTexture);
    
    var frame2 = await AsyncImageLoader.LoadImageAsync(...);
    Graphics.Blit(frame2, bufferTexture);
    
    // And so on...

    What you want to put on the screen is the bufferTexture.

  4. MurkesM commented on Dec 2, 2022

    @MurkesM
    Author

    that worked using Graphics.CopyTexture :) Although I'm now trying to build to android to test and I'm getting these 2 errors. I assume the first error is causing the second error. Any thoughts?
    Unity_NHQ7IQlbfU
    Unity_xD1R7ihPCr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions