Texture masking allows one node to mask another node or set of nodes with a texture.
This is similar to a stencil, but does not actually restrict rendering.
NOTE: This effect will not show in editor. You must run to see the mask in effect.
To fix this limitation, this effect would have to be migrated to a tool script.
To use texture masking:
- first create a
ShaderMaterial
(or multiple materials). - Assign
MaskUI.shader
to theShaderMaterial
, and set a mask texture inShader Params
. - Create a Control node over the area you want masked, and add
MaskControl.gd
as a script. - Add all
ShaderMaterial
you created into theMaterials
section of theScript
params. - Assign the
ShaderMaterial
you created earlier to every Control or Sprite you wish to be masked.
An optimization to cull controls fully outside of the bounds of the mask should ideally be possib.e
However, due to a combination of a lack of geometry shaders, poor design in the Control node implementation of mutating VERTEX position, rather than transform scale, and no easy way in 2D to inject custom vertex data for this purpose, it is impossible to determine the size of the control.
This is an area may wish to continue exploring in the future.
Another feature to consider adding is an inverse mask: hiding within the rect instead of outside.
A demo showing how to build an input key remapping screen.
- Click the buttons to change the bound keys.
- Persists the keys to disk, so they are preserved after the project is restarted.
Language: GDScript
Renderer: GLES 2