Download

How to initialize a RenderTarget with Texture

Hi guys, we are working on a brush painting tool in VR and we use RenderTargets for it. We have different sprays you can use to paint with different colors on the surface on a car mesh. It works great but we want to be able to save the result and load it again. At the moment we export the RenderTarget and save it on the disk. When you login next time we load the saved RenderTarget (we convert from .hdr to .png) as texture and draw the texture (as Material) to the RenderTarget. Our problem is that the image looses quality over time. Probably because of converting the image from hdr to png and loading it as texture and then drawing back to the RenderTarget.

The best solution would be to load the saved RenderTarget hdr image and directly initialize the RenderTarget with it. Has anyone an idea how to achieve this?

Thanks for your help,
Best, Dominik

I’m yet to work out why this is the case, but I’ve run into a similar issue before. While it works for most applications, there is some precision loss when going from the material to the render target - probably even more so when writing a texture to a render target in that way. Drawing to the render target through a material unfortunately doesn’t give mathematically identical results each time.

In my case, I was drawing a solid colour (0.5, 0.5, 0.0) to a portion of a render target. Even though the initial render target started out the same colour, over time the areas that I’d drawn in started to get lighter and lighter. It’s an incredibly minute difference, but it does add up over time.

What you’ll need to do is export the data of the render target in a native HDR format (like exr) - then read it back in and copy the data directly to the RHI resource. That can only be done with C++