Open DoctorAnsem opened 4 years ago
Never thought about the interaction between models using a custom material and the dynamic refraction added by cloak. Sounds like it luckily enough mostly works, save the diffuse map being missing of course.
I suspect the reason both why it is missing and why the refraction actually works is that Shader Patch only considers textures being set to slot 0 for custom materials, otherwise it backs out and does nothing. Unlike almost every other shader in the game the diffuse map for refraction is in slot 2, this seams like it is turning out to be a blessing here though since the diffuse map in slot 0 is what Shader Patch uses to identify when to use a custom material. Since it doesn't see slot 2 as a valid place for a material to go it doesn't apply it and when the game switches to using the refraction shader it just works, minus the diffuse texture now being missing.
I think it actually shouldn't be too hard to get the diffuse texture showing up though, custom materials already have the concept of a "fail safe texture" (you may have seen it in the material editor UI) that is used to keep the z-prepass working for alpha-cutout/hard edged transparency materials. The fail safe texture also happens to always be (for pbr/normal_ext/basic_unlit materials) the diffuse map/base color map so I think if we extend it's usage we should be able to fix this problem without too much work.
I truthfully am not aware if there's been any talk about refractions either not being available or broken, or whatever. Nonetheless there is a small oddity that should be noted - a stock unit, the Bothan Spy, uses a refraction rendertype to make a fancy effect when the unit uses its invisibility weapon and, surprise surprise, turns transparent. Now given that the munge process prints a warning of some sort when dealing with refractions, the custom materials react to it surprisingly well. A tiny little flaw pops up though - the material loses its diffuse texture whenever it transitions into the refraction. It's barely even noticeable in this instance, thankfully, but it is there so bottom of the list I guess.
Just as an afterthought, I guess static refraction-mapped models might suffer from this much worse, but I don't know for sure. Generally I try to avoid using refractions on static models because of that god awful alpha sorting issue.