Understanding and Applying Sobel/Emboss Math in Shader

I’ve been trying to figure out how to generate a Cavity Map in my shader node for the past two days, and while I understand the concept of how it is done, I don’t even remotely understand the math.

I am hoping someone could possibly explain the Math to me in non-mathematician terms, and let me know if it’s even possible. I have created the Sobel PP Material but I’m not looking for a post process effect I want it on my static meshes.

Here’s what I’m looking to achieve;
http://www.bs3d.com/index.php?page=7

And here’s some of the reading I’ve done…but don’t understand haha
http://en.wikipedia.org/wiki/Sobel_operator

That last thing I’m curious about is whether creating the cavity in the shader is even worth it or would a second texture just be more memory efficient.

Probably this. It’ll depend on what the cavity map is for. Let’s say you want to apply it to your diffuse map without a certain precondition (e.g. lighting, view dependency) there would be no reason to generate it in the material or to have a separate texture map.

The sobel filter is rather expensive for real-time usage and so is the overlay blend mode.
You can save a bunch of shader instructions by using a simplified material like this:

,

Thank you this is exactly what I was trying to achieve!

How do you put the TexelSizeX/Y into the constant 2vector node? Also, does this get put into the Base Color input?