Is there a way to read RGBA values from any Texture 2D? It seems this is something often requested, but the various methods posted so far just don’t work.
This returns null except when using certain very specific texture settings. And even when it works, the data is too small.
RawImageData->Lock(LOCK_READ_ONLY)
RHILockTexture2D() doesn’t work. The data is always too small even on uncompressed textures.
What is the proper way to read RGBA values from a texture directly? I don’t care about speed and it can be editor only. I just want to write an editor tool that merges a bunch of tiles together into a single texture. Ironically, writing seems to be no problem.
Yeah, I’m already rendering into a texture and doing ReadPixels. Problem I’m having now is that the output is blurry and I have no idea why. It shows up crisp when I first double click on the output texture. But as soon as I save, it gets blurry.
Yeah. It’s really weird. Sometimes when I load the texture up in the editor after it’s generated, it looks fine. But when I hit the save icon, it goes blurry.
The exact same code generates all the tiles. The material to render the texture uses LOD0. Oh wait… these can be streamed in, right? That’s likely the problem. Let me force them to load all LODs. Thing is I have like 50 textures. I don’t want to change them one by one.
Yeah, it was the streaming functionality that was making it blurry. There’s an option in the settings to disable it. So I have to remember to disable streaming when generating these textures.
The entire reason for having my own code to create the tiles is I have to see if I can write the mips myself including the highest resolution. If you just use tiles like that, you’ll get color bleeding from adjacent tiles. So I need to add a border. It’s similar to what virtual textures does, except the border is used for the exact opposite reason. In SVT, they copy neighbouring tiles over into the border. I don’t want that. I want to avoid going into the adjacent tiles so the border is just the outside pixels of each tile duplicated.
Can you confirm that “InTexture” is valid? Like I said - the Source.LockMip(0) has worked 100% of the time in all test and live scenarios for quite some time.
But it still doesn’t work unless it’s uncompressed.
If it’s out there, I’ve tried it. I also tried RHILockTexture2D(), but that has the problem that it gives you the compressed buffer directly, so I can’t use it unless I find a decompressor but that seems like a lot of work.
Hmmm… I wonder if the streaming functionality wasn’t interfering with it. Let me try it again with streaming disabled.
I added that code and it compiled about 200 shaders. And the pointers weren’t null anymore, but the memory from the textures were too small. Some texture buffer look like they had repeated smaller tiles.