欢迎光临散文网 会员登陆 & 注册

TextureBased SDF Slice

2022-08-03 12:21 作者:DeadCyber  | 我要投稿

Background

I want to have 3D font in my game.

    However,it seems my Quadratic Bezier SDF Algorithm is too heavy when I place the 'B' into the scene.You can see from up above,it makes FPS from 50 down to 20. 

    It's very frustrating.Because when I created the font in an empty scene initially,the FPS seems OK to me:

 

quadBezier spline 'B' in an empty scene,500FPS
'B' is created by 1 box and 2 splines

I look back on the empty scene without 'B',wow it's 1000FPS:

1000FPS:SDF Trace simple geometry is very fast

It seems like absolute FPS doesn't mean a thing,the relative proportion does.Our 'B' drop 50%!

Since a spline based 'B' is so heavy,I want to use texture based SDF.

Let's try it!

Generate SDF texture

    The important thing is that you save the value by pixel distance,and do not normalize it,otherwise there'll be a problem.I havn't fully found the reason, but this procedure solve the issue: don't normalize it in SDF Texture

sphereSDF.exr,save SDF in R channel

Calculate SDF Slice in Shader

With a bound condition,we get a single slice.Same view, up to 1000FPS,almost cost free:

FPS just like an empty scene

Get closer,the precision is acceptable.Afterall,it's texture based,can't compare with a 'perfect' spline based one:

TextureBased.Precision is acceptable.
SplineBased.Perfect but too expensive.

Thanks to SDF Trace and TextureBased SDF Slice,allows infinite instances at a relative cheap cost:


TextureBased SDF Slice的评论 (共 条)

分享到微博请遵守国家法律