快速,不准确的正弦函数,无需查找 [英] Fast, inaccurate sin function without lookup

查看:81
本文介绍了快速,不准确的正弦函数,无需查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于海洋着色器,我需要一个快速函数来计算sin(x)的非常近似的值.唯一的要求是它是周期性的,并且大致类似于正弦波.

For an ocean shader, I need a fast function that computes a very approximate value for sin(x). The only requirements are that it is periodic, and roughly resembles a sine wave.

泰勒级数的犯罪太慢了,因为我需要计算x的9阶幂才能得到一个完整的周期.

The taylor series of sin is too slow, since I'd need to compute up to the 9th power of x just to get a full period.

有什么建议吗?

对不起,我没有提到,我不能使用查找表,因为它在顶点着色器上.查找表将包含纹理样本,该纹理样本在顶点着色器上比内置的sin函数要慢. 它不一定要准确,它必须看起来不错.

Sorry I didn't mention, I can't use a lookup table since this is on the vertex shader. A lookup table would involve a texture sample, which on the vertex shader is slower than the built in sin function. It doesn't have to be in any way accurate, it just has to look nice.

推荐答案

使用 Chebyshev 近似根据您需要的条件.如果将输入角度限制为表现良好(-π.. +π或0 ..2π),则这特别容易,因此您不必先将自变量减小为明智的值.您可以使用2或3个字词,而不是9个字词.

Use a Chebyshev approximation for as many terms as you need. This is particularly easy if your input angles are constrained to be well behaved (-π .. +π or 0 .. 2π) so you do not have to reduce the argument to a sensible value first. You might use 2 or 3 terms instead of 9.

这篇关于快速,不准确的正弦函数,无需查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆