Text is visible through fog

Is it possible to have world space text affected by fog?

Original Post on Discord

by user 300386587278049291

@SwingingTom I think that would fall into your area - could the three.js defines and chunks for fog also been passed through to UI meshes?

Same issue with particles

by user 300386587278049291

Thanks for the report @BMAN

That’s a good question. I would say, atm, this may be possible by assigning a custom material to a font. However, not sure how it will react with glyphs and RGSS.
Im going to add an entry to check it

by user 690088582958153812

@herbst🌵 atm, default text shader doesn’t feed fog uniforms nor use fog chunks. This could be easily added in core but this looks to me that fog is somewhat odd for common UI. What do you think? Is there any downside/overheat to add them by default even if they will be use rarely?

Also atm, fog can be achieved by overriding the font material on element. Standard three material implementations are provided in the examples/folder.

// StandardMaterial from three-mesh-ui/examples/materials/mdsf/
const fogText = new ThreeMeshUI.Text({textContent:"MSDFStandardMaterial (fog enabled)"});

// MSDFStandardMaterial from 'three-mesh-ui/examples/materials/msdf/MSDFStandardMaterial';
fogText.fontMaterial = new MSDFBasicMaterial({ /* material options */ });
    
// That's it...Fog enabled
// Other materials available; Standard, Transmission, Normal, etc...

by user 690088582958153812

AnimationFog.gif

by user 690088582958153812

We can also add a different material per font, we won’t have to repeat the material assignation per element.

// Once font are registered, we can get the font family to apply material per variant
const FluxFamily = FontLibrary.getFontFamily("FluxArchitect");
FluxFamily.getVariant('700','normal').fontMaterial = MeshNormalMaterial;

by user 690088582958153812

If it’s via define then it’ll basically only be active if fog is actually on (those codepaths are compiled out if not used)

Also I think it should be optional to enable fog on UI - there are cases where it’s desired and some where it’s not

Agreed, do you think the proposed workaround is reacheable for needle users?

by user 690088582958153812

Can we add the fog uniforms to the default font shader and guard them with a define? And then expose an option in the canvas + Text component in Unity to either enable or disable the define on the font material?

Would requires an update, but yes absolutely.

by user 690088582958153812

Thank you @SwingingTom and everyone!

by user 300386587278049291