Question about 1.15 spheremask example from Math level

Hello Everyone, Recently I have been trying to learn Material System in UE4. So i am looking through the content example, Math level. So at the 1.15 Spheremask section, there’s a material set up using Absolute World Position and Actor Position. So when i removed the actor link and connected the Absolute World Position to the 2nd Mask . All the Grass/Green texture Disappeared. Also if i did the same with Actor position connecting to both the Mask node, the Green texture disappears again. I looked up the definition for both Absolute and Actor position node. But couldn’t make any sense out of it. Could someone explain me…

  1. Why The Green Texture disappeared ?

  2. What is the point of using Absolute
    World Position and Actor Position ?

  3. What can i use those nodes for ?
    (with an example if possible)

  4. Also another question , is In the
    Mask node only R and G is checked.
    Why isn’t the Blue Channel checked
    as well ?

  5. Why isn’t Alpha channel checked as
    well ? Through the Sphere Mask its
    connecting to the Alpha for the Lerp
    Node.

Thanks for reading.

Hey NinkuEx -

Most all of your questions can be answered by an understanding of vectors and how a material uses them. So let me try to break this down in a logical fashion. I will try to make sure I hit all your questions as we go through it.

The Example has a Cobblestone Texture (TexA) and a Grass Texture (TexB) plugged into a LERP (Linear Interpolator), so as the value plugged into the alpha approaches 1 from 0 your go from TexA to TexB. In this particular instance we have a sphere mask used to control the alpha.

The sphere mask node generates a sphere, a 3-dimensional object, using the distance vector generated by the distance from A to B in space and the given radius. In math terms, a sphere can be described implicitly as f(p) = ||p - c|| - r = 0, read as the function of vector p is equal to the length (or norm) between vector p minus vector c minus the radius is equal to 0 where c is the center origin point and p is a point on the surface of the sphere. For our purposes and to simplify here, the sphere mask takes two vectors (locations) and float radius value and produces a sphere using those values.

Obviously we have the radius set to 100 units, the other two nodes produce the Central Point (B) and Sphere Edge point (A). Absolute World Position gives us the current pixel in world space, or more simply the current pixel on your screen that is getting rendered and where that pixel exists in the 3 dimensional space of the world being rendered. The Actor Position gives us the location in the world of the actor with the material being applied. So, in those terms, the sphere mask creates a sphere centered on the actor’s world position then using a radius of 100 calculates which pixels on the screen correspond to the world location of the central point + 100 units.

So to answer your first question directly, the green disappears completely because by measuring the distance from 1 to 1 (Absolute World to Absolute World) is equal to 0, so no sphere is generated and a hard 0 value is passed into your LERP node and only the TexA is rendered.

Hopefully I have already made clear why you need the Absolute World Position and the Actor Position in the sphere mask setup earlier.

You will want to use these nodes anytime you might need to call the information that they provide, the documentation for Material Expressions has some good examples for using both nodes: https://udn.unrealengine.com/docs/ue4/INT/Engine/Rendering/Materials/ExpressionReference

Finally, why mask the values? While the Sphere Mask will use up to a 4 vector (RGBA), the two arguments A and B must match in type so a 2 vector and a 2 vector. Since, we are dealing, in this example with a flat surface we only need to look up the XY coordinates or (RG). As a test, look at what you get when you mask to RGB on both in the Material Editor cube. That may be something you would want, but if not there is no need to have the engine calculate the additional math involved.

Hopefully this helps you get started, understanding how materials work can be daunting but well worth the effort.

Eric Ketchum

1 Like

Hey Eric ,

Thanks a lot.
That helps me understand more about how these materials works.