Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post here if you need help getting started with Daggerfall Unity or just want to clarify a potential bug. Questions about playing or modding classic Daggerfall should be posted to Community.
Post Reply
User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post by Nystul »

I would need a way to provide custom textures and especially maps like opacity maps, bump maps, specular maps etc for an existing material (created by MaterialReader class). Especially it would be nice to have a global material dictionary of all loaded materials or some equivalent mechansim where one can update these textures on demand and selectively.

For a first implementation it would be enough to have a function which tests if a specific material is loaded/present in the scene (e.g. temple wall texture) and a second function to query the material to be able to attach new textures to it.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post by Interkarma »

Nystul wrote:Especially it would be nice to have a global material dictionary of all loaded materials or some equivalent mechansim where one can update these textures on demand and selectively.

For a first implementation it would be enough to have a function which tests if a specific material is loaded/present in the scene (e.g. temple wall texture) and a second function to query the material to be able to attach new textures to it.
MaterialReader is already doing this under the hood, I just don't expose methods to change the material textures (yet). There's a bit of overhead to doing this properly that I want to tackle in another iteration. I'm looking at doing this as part of enabling early modding efforts by way replacing textures and models. This will be after a few releases of Daggerfall Unity however, and I don't want it to require coding (or even Unity) to use. That's the overhead I'm talking about.

Since you're doing things in code however, it should be possible to make a quick approximation of the features you're asking for. Here's how.

MakeTextureKey() and ReverseTextureKey() already expose the methods to generate and reverse keys for the material dictionary.

GetCachedMaterial() and GetCachedMaterialAtlas() return a CachedMaterial struct from dictionary with all the various bits of information about that material, including the individual textures and properties like rects, sizes, frame counts, etc.

All we really need to add is a couple of methods like HasCachedMaterial() and SetCachedMaterial() to inject whatever back into the material dictionary. The scene builders will then use these materials next time it builds a scene.

It would just be a quick approximation of what you're asking for, but might be a good place to start. Would you like me to pop these methods into the next update? You could possibly even improve them based on your needs and I can roll your changes into the main library.

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post by Nystul »

Interkarma wrote: MakeTextureKey() and ReverseTextureKey() already expose the methods to generate and reverse keys for the material dictionary.

GetCachedMaterial() and GetCachedMaterialAtlas() return a CachedMaterial struct from dictionary with all the various bits of information about that material, including the individual textures and properties like rects, sizes, frame counts, etc.

All we really need to add is a couple of methods like HasCachedMaterial() and SetCachedMaterial() to inject whatever back into the material dictionary. The scene builders will then use these materials next time it builds a scene.

It would just be a quick approximation of what you're asking for, but might be a good place to start. Would you like me to pop these methods into the next update? You could possibly even improve them based on your needs and I can roll your changes into the main library.
that would be wonderful! ;)
thanks for your detailed explainations!

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post by Nystul »

are the terrain tiles conceptionally the same as textures on models? or is this texture atlas stuff (I think it is heavily related to terrain tiles) something different? Or in other words: Does there exist an associated material for each terrain tile?
I know that the terrain tiles are rendered with your tilemap shader and not with the standard shader so I would guess they are something special.
I would like to have a metalness/glossmap for each material (for every terrain tile or at least a combined atlas of the metal/gloss map of the corresponding terrain texture tiles atlas).
In my planned reflection mod I would like to exchange your tilemap shader with an extended version integrating these maps to achieve reflective shading (To make a puddle of water reflective in a selective manner only on texture areas that are indeed water).

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post by Interkarma »

This journal entry has a pretty good summary of the terrain tilemap shader.

http://www.dfworkshop.net/improved-terrain-tiling/

From DFTFU 1.3 the terrain tilemap shader does use the Standard shader template and it would be possible to update it (and the terrain atlas material) to use a normal map, emission map, metallic settings, etc. I didn't put much time into this as I see the tilemap shader more as a "retro default" solution.

But I'm happy to help you work through the problems if you're interested in making a new "less retro" terrain texturing system. :)

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Replacing/Injecting Textures/Maps in materials created by MaterialReader class

Post by Nystul »

thanks! I will try to hack something together - lets see how long it will take ;)

update:
i managed to inject material properties to normal model textures. And it is even possible without changing MaterialReader script! It already offers everything one needs to do this (the GetCachedMaterial() function is indeed enough)
next thing will be to take a closer look to terrain tiles...

update2:
i managed to hack the terrain tiles as well - works surprisingly well

Post Reply