Interkarma / daggerfall-unity

Open source recreation of Daggerfall in the Unity engine
http://www.dfworkshop.net
MIT License
2.7k stars 327 forks source link

"Read/Write Enabled" pass on DFU textures #2609

Open KABoissonneault opened 6 months ago

KABoissonneault commented 6 months ago

DFU has a tendency to default to requiring "Read/Write Enabled" when loading a texture. Lots of APIs don't have a "readOnly" parameter, and when it calls an API with the flag, it tends to pass "false".

"Read/Write Enabled" is the Unity term to make the texture appear on the CPU. This can be required for reading pixels and writing to pixels from DFU code. If a texture is only used by shaders (the GPU), we call it "read only" (despite the ambiguity with the Unity term). So I will call a texture "readable" if it's Read/Write Enabled (on the CPU) and shader-only if it's not.

It's currently pretty inconsistent what textures are expected by DFU to be readable, because of the default to "readOnly=false". I'd like for someone to do a pass on which ones are truly required, and which ones are just there because the old code didn't account for it.

I have this post from King of Worms, who's got experience with replacing all the textures in DFU.

When asked which textures he thinks really need the Read/Write Enabled flag:

From the old info I got from The Lacus, read/write should be enabled in case that:

  • a sprite is from the terrain assets (trees, flowers etc)
  • is a animated animal or animated sprite in general
  • is a overlay of another texture (like a lot of assets in the HUD)
  • is paperdoll

And these are the textures where he currently uses the flag:

So on my side, I have the flag enabled on

  • whole paperdoll
  • all animals
  • all animated lights
  • all terrain sprites
  • most of the animated sprites excluding NPCs
  • lots of HUD elements
  • none of the Handheld

He gets a "texture is not readable" warning on the following assets, which we suspect to be spurious

I got some warning on assets like: TFAC... - so checking if portraits including FACES.CIF should be read/write enabled would be cool Animated HUD elements like Spinning coins (380_6-0 + 434_6-0) & Magic effect (380_5-0 + 434_5-0)

Some HUD assets which overlay (are over-layed by) other assets like SHOP00I0.IMG GNRC01I0.IMG REPR01I0.IMG

INVE16I0.CIF_4-0 INVE16I0.CIF_6-0 INVE16I0.CIF_7-0 INVE16I0.CIF_9-0 (so this is basically all these INVE-CIF assets whenever they appear ingame)

Some sprites: 207_16-0 (so this is basically the whole 207 archive)

So, let's clarify which ones are truly required, and let's remove the warning where it's not

ex: "GNRC01I0" is in DaggerfallMerchantServicePopupWindow.cs. It's loaded in LoadTextures with baseTexture = ImageReader.GetTexture(baseTextureName);. This function has no "readOnly" parameter, and it calls GetImageData which does not either. In GetImageData, you have multiple formats being handled differently (TEXTURE, IMG, CIF, RCI, CFA, BSS, GFX). When it comes to the path with no texture imported from mods, the texture is created with GetTexture, which sets the pixels from the DF data then calls Texture2D.Apply with makeNoLongerReadable as false. When it comes to imported textures, it changes by archive type.For TEXTURE, the overloads with readOnly are not called, so it defaults to false. For IMG/CIF, RCI/CFA/BSS/GFX, readOny=false is explicitly passed to those functions. With a readOnly parameter somewhere in there, we could fix both DFU base textures (for performance reasons) and imported mod textures