8 ms·
Nice article! I have a couple of questions. > [reciprocal square root] it is particularly well supported in SIMD and GPU and is generally about the same speed
by dahart 7y ago
Nice article! I have a couple of questions.
> [reciprocal square root] it is particularly well supported in SIMD and GPU and is generally about the same speed as simple division.
Curious, Raph - why is the erf using f64? Reciprocal square root is well supported for single precision, but not double precision. And the spline fit constants in there are single precision anyway. I’m guessing it’d be a lot faster with no harmful effects as f32. (Seems to work fine on ShaderToy BTW).
Also curious if erf() might be overkill? Did you compare to using a smoothstep()? What are the quality indicators you’re looking for? It seems like I get very close to the same results as your erf approximation if I use smoothstep(0., blurwidth, sqrt(d)) where d is the SDF distance to the box. (With the added benefit that I automatically have a strict bound on the blur.)
- raphlinus 7y agoSure, you'd want to do this with 32 bit floats in production, the f64 was really for prototyping. I didn't compare smoothstep. It's worth doing an analysis of the tradeoff between performance and quality. In any case, I think in practice this erf approximation will be plenty fast, and probably a bit better quality, especially in the tail region.