What you posted is how to use texture atlases with material functions.
HLSL shader code should be like this: