先說心得:
Web 3D程式會Eat the World。以後Desktop的3D程式(遊戲除外)會被淘汰,雖然需要很長一段時間。
但Web程式要考慮很多,不要一不小心重踏Insomniac Games的慘痛經驗
https://www.gdcvault.com/play/1024465/Insomniac-s-Web-Tools-A
我來分享一些自己寫Webgl的心得。
首先TypedArrays不好用,Javascript 沒有pointer,所以無法指向某member當base,一定要用subarray()或new ArrayBuffer()來做類似vec3的結構。可是
https://stackoverflow.com/questions/45803829/memory-overhead-of-typed-arrays-vs-strings
所以這樣做的話,記憶體爆炸性成長,效能也差。所以Js的glmatrix library根本是誤導人走錯的方向。
現在我正在準備完全重寫matrix library,(順便用wasm?)適合Js TypedArray的。
Webgl好用,Webgl2更好用,Webgl2-compute出來就真的不得了。如果不介意暫時的相容性問題,請直接使用Webgl2,當你的程式可上線的時候,Webgl2應該是90%+了。
第三programmable vertex pull超贊。OpenGL Insight Chapter21,應該是始祖。
https://github.com/OpenGLInsights/OpenGLInsightsCode/tree/master/Chapter%2021%20Programmable%20Vertex%20Pulling
另外一個example
https://github.com/nlguillemot/ProgrammablePulling
Webgl沒有1d texture要用2d texture來代替,需要確定gpu有vertex texture的支援(99%),然後需要oes_texture_float的extension(80%)。只能用float所以有16million index的限制。
programmable vertex pulling簡化程式,把computation移到gpu剛好適合web,請多多利用。如果有碰到問題,我樂意回答,如果我有時間的話。
我正在寫3d model editing的程式,browser處理幾十萬個polygons是沒問題,現在我改寫用vertex pulling希望能處理幾百萬個polygons。