I get an error saying:
tx.readPixels(…).then is not a function
Looks like I can’t use it as a promise, is it because I’m using a texture generated with RenderTargetTexture and not a regular texture as in your example?
The readPixels() returns an array but the .then method is not available
I managed to make it work using await tx.readPixels() instead of the promise style.
Thanks a lot
Is there a method to know when a texture generate with RenderTargetTexture from a camera is filled?
If I use it straight away even if the isReady parameter is true the resulting texture is black. If I use a setTimeout with 50 milliseconds I get the proper image.
I’m not confident using a setTimeout cause if it runs on a slower machine or the machine is busier and it takes longer it will result in a black texture.
If I use the tx.onAfterRenderObservable to wait I get a texture that is grey and not anymore black but without the full rendered image in it
That’s because I think you are using 4.2 and in 4.2
readPixels is synchronous and returns an
ArrayBufferView, not a
I think you should be able to use
onAfterUnbind seemed to work but after some more testing it appears that once every 10 times (it’s not a fixed amount just a variable observed statistic) the textures is not filled. Any idea if it should be working 100% of the times or if it is a possibility?
Hum, I think to be on the safe side you should use
Another solution that should work is to use
Tools.DumpFramebuffer(width, height, engine, successCallback, mimeType, fileName); in the
DumpFrameBuffer will read the data from the currently bound texture, which is still the RTT at this point.
You are amazing Evgeni, it’s so cool to learn this amazing library knowing that I can rely on somebody like you.
engine.onEndFrameObservable seems to be reliable 100% of times.
Thanks so much
Hi, I’m back with the question of the day
Now everything works perfectly but I have a small issue with the Sampling Mode.
When I use BABYLON.Texture.NEAREST_NEAREST with low res textures to achieve a pixelated effect I always have an artifact, a thin line in the middle of the textures. I’ve tried all similar sampling modes but the issue is always there. Even if I set it in the constructor instead of later using tx.updateSamplingMode.
Any idea where that artifact is coming from?
EDIT: I found a working solution using non power of 2 sizes for the RenderTargetTexture, it results in slightly less defined textures but the artifact is gone, i guess thanks to the internal texture resampling. But still, if possible, I would like to understand what’s causing the artifact in the first place.
Thanks as usual
Hard to say without a repro. Have you tried to set the wrap mode to clamp?
Using tx.wrapR = BABYLON.Texture.CLAMP_ADDRESSMODE totally fixed the issue.
I virtually hug you