正弦波近似 http://blog.csdn.net/ring0hx/article/details/44492415
2016-01-11 16:15
531 查看
float4 SmoothCurve( float4 x ) { return x * x *( 3.0 - 2.0 * x ); } float4 TriangleWave( float4 x ) { return abs( frac( x + 0.5 ) * 2.0 - 1.0 ); } float4 SmoothTriangleWave( float4 x ) { return SmoothCurve( TriangleWave( x ) ); }
在做一些游戏效果的时候经常需要用到正弦波,它平滑又有周期性,但是sin的计算开销略大。作为优化,在GPU Gem上看到一个用三次函数平滑三角波得到近似正弦波的方法不错:
float4 SmoothCurve( float4 x ) { return x * x *( 3.0 - 2.0 * x ); } float4 TriangleWave( float4 x ) { return abs( frac( x + 0.5 ) * 2.0 - 1.0 ); } float4 SmoothTriangleWave( float4 x ) { return SmoothCurve( TriangleWave( x ) ); }
1
2
3
4
5
6
7
8
9
三角波TriangleWave 函数图
平滑函数SmoothCurve 函数图
最后得到的SmoothTriangleWave函数图
相关文章推荐
- [leetcode oj 70]Climbing Stairs
- Shallow heap & Retained heap
- 人工智能之统计学基础-回归与方差分析
- 人工智能之卡尔曼滤波进阶
- 自定义View时,用到Paint Canvas的一些温故,自定义Loading控件(动画五,“六边形”的旋转跳跃)
- 自定义View时,用到Paint Canvas的一些温故,自定义Loading控件(动画五,“六边形”的旋转跳跃)
- 总结baiduTemplate和djangoTemplate的学习
- Keychain
- 人工智能之卡尔曼滤波入门
- HDOJ 1021 Fibonacci Again
- Leetcode 11 - Container With Most Water
- Xamarin部署时遇到错误: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]
- show show detail present modally present as popover
- Could not find main method from given launch configuration
- Debug Assertion Failed! Expression: _pFirstBlock == pHead
- [看书日记20160111]没心情啊。。Messenger,AIDL
- hdu1302The Snail(水)
- RAID基础
- readwrite、readonly、retain、copy、assign、nonatomic的作用以及使用场景
- 2434: [Noi2011]阿狸的打字机 fail树+dfs序+树状数组