[NME]How can i make my mask face the screen, and in the meanwhile, keep its position following the mesh?

NME PG: https://nme.babylonjs.com/#R2H90R#6

By now, to keep the mask face the screen, i used WorldPos * ViewProjectionTransform output to calculate the mask position.
It worked well in NME,

but not well in project.

Beacause the mask position value is based on the world position, when mesh moved, mask did not, so i come here ask for help.
Hope the mask face the screen and keep its position following the mesh.

Reason for [face the screen]:To keep the inside things visible at any camera angle through the mask.
Reason for [follow the mesh position]:To filter out the correct shield position when mesh moving.

cc @PatrickRyan to see if he has a few cycles to help

@kikoshoung, is the shield a sphere like you are showing here? If so you can just use a fresnel node to accomplish the effect which will move with the shield since it’s based on the mesh normal.

Updated shader


Granted, if you have a more complex mesh, this method falls down a bit:


But if your mesh does not have any hard angles it may still work. Or if the shield is some sort of dome or sphere, this is a very cheap way to go. Otherwise, if you need to do a projection from the view direction which will also require mesh normals and likely show some distortion.

The only way to do it otherwise would be to use the screen space block to ignore the mesh entirely, but then you need some way to shift the 0 coordinate of the screen to align with the mesh position on screen, which could get complicated.


Yes, just in sphere shield case.
Thanks for your fresnel solution, it helps so much!

1 Like