# \[FREE\] Curvature Shader

**URL:** <https://forums.unrealengine.com/t/free-curvature-shader/91962>\
**Category:** Community & Industry Discussion\
**Tags:** unreal-engine\
**Created:** [May 12, 2017, 2:57pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962 "2017-05-12T14:57:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mserena](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mserena](https://forums.unrealengine.com/u/mserena)\
**Post date:** [May 12, 2017, 2:57pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/1 "2017-05-12T14:57:33Z")

</div>

Hi,

Made a curvature shader based of this [GLSL shader](http://madebyevan.com/shaders/curvature/)

- Updated to use BasePassPixelShader.usf version of NormalCurvatureToRoughness it’s cheaper and with a better result.

[Youtube](https://www.youtube.com/watch?v=Qmi9LgH5N2E)

The normals are interpolated linearly so the faceting can’t be fixed at the moment, but with higher resolution mesh or more math savy people (or UE4 will do smooth interpolated normals) this could be improved upon.  
Lemme know if you find it useful.  
Built in 4.16 but can be for any version.

Zip attached

---- Updated with function to include PostProcess  
---- Updated 2 - New function based off BasePassPixelShader.usf recreated in function attached with image to recreate it.

---

<div class="post-metadata">

**Author:** ![hessjacobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hessjacobs](https://forums.unrealengine.com/u/hessjacobs)\
**Post date:** [May 16, 2017, 7:14am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/2 "2017-05-16T07:14:52Z")

</div>

@mserena: Hi, looks interesting. I just had a brief look on the shader (your supplied uasset from the zip only works in 4.16, 4.15 and earlier versions do not recognize it).  
A question: can you please supply more info or explain how you have used your MF in the material from the examples (picture above and video) - maybe you can post a screenshot of the material BP?

THX and greetings  
Markus

---

<div class="post-metadata">

**Author:** ![Sitrec](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sitrec](https://forums.unrealengine.com/u/Sitrec)\
**Post date:** [May 16, 2017, 11:46am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/3 "2017-05-16T11:46:05Z")

</div>

Super useful, thank you! I made something similar a while back but didn’t get a result quite this good, this looks a lot nicer.

---

<div class="post-metadata">

**Author:** ![sleepingdragon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sleepingdragon](https://forums.unrealengine.com/u/sleepingdragon)\
**Post date:** [May 16, 2017, 12:20pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/4 "2017-05-16T12:20:55Z")

</div>

thank you.

---

<div class="post-metadata">

**Author:** ![mserena](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mserena](https://forums.unrealengine.com/u/mserena)\
**Post date:** [May 17, 2017, 12:42pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/5 "2017-05-17T12:42:41Z")

</div>

@hessjacobs sure here you go. nothing that won’t work in previous versions.  
 ![de6f970aa443a474698162a4d2b07ea9f659048e.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)  
@Sitrec thank you, all credit goes out to Evan Wallace though, I just rebuilt his glsl shader.

---

<div class="post-metadata">

**Author:** ![hessjacobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hessjacobs](https://forums.unrealengine.com/u/hessjacobs)\
**Post date:** [May 17, 2017, 6:28pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/6 "2017-05-17T18:28:32Z")

</div>

@mserena: thanks - got it working in 4.14, of course 🙂 In your example video how did you setup your red/green material? … just using a lerp function between colors an applying the MF output to the alpha input of the lerp?

---

<div class="post-metadata">

**Author:** ![HiIAmMoot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HiIAmMoot](https://forums.unrealengine.com/u/HiIAmMoot)\
**Post date:** [May 18, 2017, 9:23am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/8 "2017-05-18T09:23:21Z")

</div>

Is there a way to make this a postprocess shader?

---

<div class="post-metadata">

**Author:** ![mserena](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mserena](https://forums.unrealengine.com/u/mserena)\
**Post date:** [May 18, 2017, 10:35am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/9 "2017-05-18T10:35:31Z")

</div>

Sure thing, just updated my post to include a PP function to do it. Tried to incorporate into the same function but it complained about it being used in an opaque material.  
But the process is just replace the PixelNormalWS with sceneTexture : worldNormal

---

<div class="post-metadata">

**Author:** ![mserena](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mserena](https://forums.unrealengine.com/u/mserena)\
**Post date:** [May 19, 2017, 12:50am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/10 "2017-05-19T00:50:48Z")

</div>

> [@hessjacobs;710412](#):
>
> @mserena: thanks - got it working in 4.14, of course 🙂 In your example video how did you setup your red/green material? … just using a lerp function between colors an applying the MF output to the alpha input of the lerp?

yep, just use it as the alpha in the lerp and it will blend two colours based of the curvature

---

<div class="post-metadata">

**Author:** ![ryukishi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ryukishi](https://forums.unrealengine.com/u/ryukishi)\
**Post date:** [October 31, 2017, 4:38pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/11 "2017-10-31T16:38:27Z")

</div>

Thanks mserena, this is awesome. I working for a surgical simulator company and I’m trying to use your shader to fill the mesh cracks with blood but the threshold is stock on fine details, I’m trying to change it to the bigger shapes but have a hard time to find what to change. I wonder if you could hint me where I should start? And Do you think that would be possible to fill the curvature of overlapping objects cracks? Well thank you if you can’t help anyway, this is already awesome giving it free.

---

<div class="post-metadata">

**Author:** ![Acriax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/acriax/32/472400_2.png) [@Acriax](https://forums.unrealengine.com/u/Acriax)\
**Post date:** [November 22, 2017, 9:57pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/12 "2017-11-22T21:57:57Z")

</div>

Hey Mark, from what I saw on the youtube video, this looks fantastic! But I can’t see any download in this thread?

---

<div class="post-metadata">

**Author:** ![mserena](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mserena](https://forums.unrealengine.com/u/mserena)\
**Post date:** [November 27, 2017, 5:25am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/14 "2017-11-27T05:25:29Z")

</div>

@Acriax the first post should have a two zips you can download, two different methods and there’s also a picture showing you how to recreate it.

---

<div class="post-metadata">

**Author:** ![Acriax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/acriax/32/472400_2.png) [@Acriax](https://forums.unrealengine.com/u/Acriax)\
**Post date:** [November 27, 2017, 5:55pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/15 "2017-11-27T17:55:42Z")

</div>

> [@mserena](#):
>
> @Acriax the first post should have a two zips you can download, two different methods and there’s also a picture showing you how to recreate it.

Ah, my mistake! Seems I can’t see attachments when I’m logged into the forums for some reason. :S

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_128d48a2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_128d48a2](https://forums.unrealengine.com/u/anonymous_user_128d48a2)\
**Post date:** [May 14, 2019, 8:42am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/17 "2019-05-14T08:42:23Z")

</div>

> [@mserena](#):
>
> @Acriax the first post should have a two zips you can download, two different methods and there’s also a picture showing you how to recreate it.

Is there a way to do this without the camera affecting it?

---

<div class="post-metadata">

**Author:** ![neVeRmind8837](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@neVeRmind8837](https://forums.unrealengine.com/u/neVeRmind8837)\
**Post date:** [September 12, 2019, 12:02pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/18 "2019-09-12T12:02:56Z")

</div>

Awesome, thank you very much for this!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fb514ab9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fb514ab9](https://forums.unrealengine.com/u/anonymous_user_fb514ab9)\
**Post date:** [December 15, 2019, 1:00pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/19 "2019-12-15T13:00:30Z")

</div>

How can you use it to like applying edge wear?

---

<div class="post-metadata">

**Author:** ![jensdittmer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jensdittmer](https://forums.unrealengine.com/u/jensdittmer)\
**Post date:** [November 3, 2020, 3:17pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/20 "2020-11-03T15:17:45Z")

</div>

Sadly, this seems not to work anymore in newer versions of UE (maybe I can save someone some time ;))

---

<div class="post-metadata">

**Author:** ![Agnaguduu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agnaguduu](https://forums.unrealengine.com/u/Agnaguduu)\
**Post date:** [April 27, 2021, 1:46am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/21 "2021-04-27T01:46:42Z")

</div>

Hi, I would be very interested in this as it is exactly what I need for my project. I do not see a download link and apparently, it’s not working on new versions anyways. I wouldn’t mind paying for such a plugin.

---

<div class="post-metadata">

**Author:** ![Skaio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Skaio](https://forums.unrealengine.com/u/Skaio)\
**Post date:** [May 25, 2021, 8:08pm UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/22 "2021-05-25T20:08:00Z")

</div>

Thank you Mserena for the great resource. I got a variation of this technique to work in 4.25 and 4.26. [I put the variation on the UE4 marketplace](https://www.unrealengine.com/marketplace/en-US/product/stylized-curve-shader) so others could try it out.

There are a few limitations, it doesn’t seem to work great for edge wear on low poly right angles. It works better on high-poly (10k+ tris) objects.

If you’re looking for edge wear in UE4, this Polycount thread helped me

> **[FWVN edge wear material function for dynamic procedural texturing](https://polycount.com/discussion/202689/fwvn-edge-wear-material-function-for-dynamic-procedural-texturing)**
>
> I got a bunch of requests for a tutorial or release of the fwvn edge detect technique in the past, so I finally decided to take some steps and roll it into a material function, which I will make available very soon.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4384bf631](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4384bf631](https://forums.unrealengine.com/u/anonymous_user_4384bf631)\
**Post date:** [June 1, 2021, 4:05am UTC](https://forums.unrealengine.com/t/free-curvature-shader/91962/23 "2021-06-01T04:05:30Z")

</div>

I think there is a couple of mistake here, first you do transforms from screen space to world space, it should be the opposite, also you divide by the normals length in the end, but normals in UE4 are automatically normalized, so they should be equal to one. I am no GLSL expert but in the original code it was referring to vertex, due to the nature of the algorithm dividing by distance to vertices or even pixels could make sense but I am not sure.

[Next page](https://forums.unrealengine.com/t/free-curvature-shader/91962.md?page=2)
