Created
August 12, 2019 17:12
-
-
Save julhe/b8c5b69be69f7da5e01aa698a5be9aec to your computer and use it in GitHub Desktop.
Simple Filtering for SDFs Masks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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