# Making a cylindrical mask instead of sphere

**URL:** <https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 26, 2015, 3:59pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473 "2015-04-26T15:59:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![VoidGoat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VoidGoat](https://forums.unrealengine.com/u/VoidGoat)\
**Post date:** [April 26, 2015, 3:59pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/1 "2015-04-26T15:59:55Z")

</div>

I’ve been using a sphere mask to create location based opacity on my materials but what I really need is a cylindrical shape instead. is there a way to make a cylinder mask?

---

<div class="post-metadata">

**Author:** ![RyanB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyanB](https://forums.unrealengine.com/u/RyanB)\
**Post date:** [April 27, 2015, 6:01pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/2 "2015-04-27T18:01:50Z")

</div>

Hi VoidGoat,

what type of cylinder shape? As viewed from above a cylinder looks exactly like a circle (or sphere), and from the side a cylinder looks like a rectangle. From other angles a cylinder looks like an ellipse with a rectangle in the middle.

You could actually use the distance field shape for a cylinder if you want. That said there is probably a far easier method if you give some more info.

[Distance Field link](http://iquilezles.org/www/articles/distfunctions/distfunctions.htm)

float sdCappedCylinder( vec3 p, vec2 h )  
{  
vec2 d = abs(vec2(length(p.xz),p.y)) - h;  
return min(max(d.x,d.y),0.0) + length(max(d,0.0));  
}

p would be worldposition. by first rotating or transform worldposition you could rotate the cylinder and scale it by scaling worldposition.

The shape you get from the cylinder would depend on how you sample it, ie offsetting from 0 would be like getting different cross sections in 2d.

---

<div class="post-metadata">

**Author:** ![VoidGoat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VoidGoat](https://forums.unrealengine.com/u/VoidGoat)\
**Post date:** [April 28, 2015, 3:52am UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/3 "2015-04-28T03:52:38Z")

</div>

I am making it appear as though there is a hole cut into the wall and it needs to be a cylindrical shape. right now the sphere mask is being used to make the area that the sphere touches transparent and i want this same effect but with a cylindrical shape instead

---

<div class="post-metadata">

**Author:** ![RyanB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyanB](https://forums.unrealengine.com/u/RyanB)\
**Post date:** [May 19, 2015, 1:11am UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/4 "2015-05-19T01:11:03Z")

</div>

I made the cylinder distance field from above into a material network that you can copy. What this does is return a distance field for a the world. This is set up so that “height” also scales worldposition. To scale the cylinder, multiply worldposition by something first. To offset it, add something.

 ![43226-cylinder_distancefield.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/d/0/8d093cbf86f893f35b710c83e5cbd797266eafe4.jpeg)

Here is that material applied to a few static mesh planes. You can see how each plane shows a cross section of where it intersections the cylinder function.

I was curious if you need to show the interior surface of the cylinder since that is quite a bit more work. You will have to do some research on detecting when the ray hits the caps vs the sides and then create virtual side coordinates. For those you could look at the “Spline Thicken” material function which does virtual cylinder exterior, making it an interior is just inverting the height variable.

And as you can see, cylinders look like circles from the side so there won’t be much to make this look different from a spheremask, yet this is still a cylinder hole by definition:

![43227-cylinder_distancefield_example.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/c/8/bc8d86009fe22bb647e666fc401c4db662736129.jpeg)

I am actually planning to mess with a ray-marching material function soon which would help in doing all this stuff.

---

<div class="post-metadata">

**Author:** ![RyanB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyanB](https://forums.unrealengine.com/u/RyanB)\
**Post date:** [May 19, 2015, 3:53pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/5 "2015-05-19T15:53:04Z")

</div>

hey, actually I got a raymarching distance field function working. The only downside is the custom node requires all the distance field functions be written inside of the function since custom nodes cannot communicate with eachother. It is also really expensive to use the normals. If you want this ill try to get it pasted here.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0dafa81b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0dafa81b](https://forums.unrealengine.com/u/anonymous_user_0dafa81b)\
**Post date:** [January 9, 2016, 9:45am UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/6 "2016-01-09T09:45:33Z")

</div>

Hi…I really want to make this material…

How can we change Location,Height and Width of cylinder?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_101bca4f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_101bca4f](https://forums.unrealengine.com/u/anonymous_user_101bca4f)\
**Post date:** [March 18, 2017, 11:58pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/7 "2017-03-18T23:58:06Z")

</div>

Thanks bro

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_101bca4f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_101bca4f](https://forums.unrealengine.com/u/anonymous_user_101bca4f)\
**Post date:** [March 19, 2017, 4:50pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/8 "2017-03-19T16:50:46Z")

</div>

If anyone is interested, here is a cone:

 ![130801-снимок.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/8/0/c804955bef696e2e5be6a6bf574f782220bc94d9.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0e83961b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0e83961b](https://forums.unrealengine.com/u/anonymous_user_0e83961b)\
**Post date:** [April 24, 2019, 11:05am UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/9 "2019-04-24T11:05:22Z")

</div>

does anyone know how to leave the opacity permanently? i understand it’s called location based opacity, which means where ever the actor is, the opacity location is updated. but is there any way to leave the effect behind as a trace as the actor is moving?

thanks in advance

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9ca8c27f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9ca8c27f](https://forums.unrealengine.com/u/anonymous_user_9ca8c27f)\
**Post date:** [May 9, 2021, 11:28am UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/10 "2021-05-09T11:28:32Z")

</div>

Have you solved this problem? I’m also looking for cylindrical cameras and fisheye cameras;

If you solve it, can you share the method? Thank you very much. My email address is

---

<div class="post-metadata">

**Author:** ![Azad\_N](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Azad\_N](https://forums.unrealengine.com/u/Azad_N)\
**Post date:** [February 4, 2025, 2:26pm UTC](https://forums.unrealengine.com/t/making-a-cylindrical-mask-instead-of-sphere/316473/11 "2025-02-04T14:26:43Z")

</div>

How we can get a direction vector from SDF shapes?
