Skip to content

Instantly share code, notes, and snippets.

@julhe
Created August 12, 2019 17:12
Show Gist options
  • Save julhe/b8c5b69be69f7da5e01aa698a5be9aec to your computer and use it in GitHub Desktop.
Save julhe/b8c5b69be69f7da5e01aa698a5be9aec to your computer and use it in GitHub Desktop.
Simple Filtering for SDFs Masks
#define inverseLerp(a,b,x) ((x-a)/(b-a))
...
half rawSdf = _Mask.Sample(sampler_Mask, i.uv).r ;
half texelCoverage = fwidth(i.uv) * _Mask_TexelSize.zw; // calculate texelCoverage
texelCoverage = saturate(texelCoverage); //clamp texelCoverage to [0..1]
// you can also use smoothstep(), but inverseLerp uses less instructions
half filteredSdf = saturate(inverseLerp(-texelSize, texelSize, rawSdf * 2.0 - 1.0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment