Download

Q: What is/does the rcp function perform in the shader code?

I have been going through some of the shader code and I keep coming across this rcp() and I have no idea what it does or is supposed to do. Where can I find the definition of this function?

I was looking at this post https://www.unrealengine.com/blog/physically-based-shading-on-mobile and at the bottom the code references this function. Thanks for your help :slight_smile:


half D_Approx( half Roughness, half RoL )
{
half a = Roughness * Roughness;
half a2 = a * a;
float rcp_a2 = rcp(a2);
// 0.5 / ln(2), 0.275 / ln(2)
half c = 0.72134752 * rcp_a2 + 0.39674113;
return rcp_a2 * exp2( c * RoL - c );
}

I’m pretty sure it’s just an approximation of 1/x.

Thanks plyb! I didn’t realize it was a SM5.0 only thing