google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.71k stars 1.87k forks source link

Arbitrarily replacing textures at runtime causes a flicker (C++) #7391

Closed Alan-FGR closed 10 months ago

Alan-FGR commented 10 months ago

Describe the bug Calling materialInstance->setParameter to replace a texture (with different dimensions) at runtime causes a flicker. Unfortunately I couldn't record a video showing the issue, but it shouldn't be necessary. I'm not sure this is just something undocumented and I should wait for a specific time to replace the texture, or maybe I have to call something afterwards. I couldn't figure by looking at the code.

To Reproduce Steps to reproduce the behavior:

  1. Load an asset
  2. Call materialInstance->setParameter on a material used in the asset

Expected behavior Texture should be fully updated and rendered the next frame.

Screenshots N/A. I can try to record a video, but my screen recorder is compressing the flicker out.

Desktop (please complete the following information):

romainguy commented 10 months ago

This is not an expected behavior. What flickers exactly?

Alan-FGR commented 10 months ago

Thank you for the timely reply.

It's the material. Sometimes it seems to be fully black for a frame, sometimes I think the texture has some kind of glitch like a uv shift.

I was pretty sure that was just me being stupid and not calling some update or maybe not deferring that to the appropriate time when you're supposed to swap textures. Now that I know that's not the case I'll try to gather some more information and test on other devices/drivers. I don't think it's a driver bug though.

I'll try to do a frame capture the when the texture is replaced to see if that is captured.

Sorry not providing more concrete information. I've very limited time during the week.

romainguy commented 10 months ago

It could be that your new texture isn't ready yet? Hard to say without seeing your code. setParameter() only sets a uniform on the shader.

pixelflinger commented 10 months ago

It could be that your new texture isn't ready yet? Hard to say without seeing your code. setParameter() only sets a uniform on the shader.

I'm assuming he's taking about the setParameter overload that takes a texture and sampler.

What texture are you changing? Is it an external texture? is it generated by something else? Or is it a set of fixed textures? We are pretty sure that this code path is working, it's used when streaming camera for instance.

Alan-FGR commented 10 months ago

@pixelflinger you are correct regarding the overload.

This actually ended up being a problem in my code. After setting the texture I was calling the routine to generate mipmaps in an outer scope. I was able to fix that by simply moving that so it happens before setting the texture. So, you were right @romainguy, the texture wasn't quite ready yet.

I'm closing this. Thank you for the replies and sorry for the inconvenience.