Let’s say I create a very basic material with a diffuse map and a gloss map.
And then I create another material with a diffuse map and a gloss map.
They’re not instances of each other. Will Unreal recognize that they are the same but with different textures and know not to compile two separate materials?
No, it would be assumed that you created two identical materials for a reason, perhaps that one ought to be able to have modifications at a later date, without affecting the other, or perhaps a different blueprint setup later on down the line.
Theoretically, the engine is indeed open source, and adding this yourself would be doable if you really, really wanted it - but you wouldn’t really gain any kind of performance advantage from it, so there isn’t really a point.
There should be a performance advantage usually. I’m not entirely sure how unreal handles shaders but it’s a good idea to have as few shaders as possible.
For example, in my engine, I used to say that a material has a normal map and diffuse map in some config file. And then another material also has a normal map and diffuse map but totally different textures. It was an uber shader system so I’d just have one generic shader for everything with #ifdef sections depending on of normal mapping was needed, skeletal animation, etc… And my C++ code would compile different versions of the uber shader depending on features needed. So I might have like 100 materials but a total of maybe 3 or 4 shaders that all just use different textures. And this was just based on how other games did it.
I kind of assumed this is what material instances are in Unreal. Only one set of shaders should be compiled for all material instances.