News for hackers. Stuff that matters.
Re:Show HN: A simple infinite world in WebGL by erkaman on Thursday July 28, 2016 @03:36PM (#12182582)
In this demo, I implemented an infinitely continuing, vaporwave-like world in WebGL. If you can't run it for some reason, a recorded gif of the demo can be found here: https://github.com/Erkaman/wireframe-world.

As for the implementation, it is not very difficult stuff; I divide up the world into chunks(just like in Minecraft), and as the camera traverses the world, the chunks that become out of range are thrown away and are no longer rendered. And in the far away horizon I keep adding new chunks, to give the illusion that the world is infinite.

So it is not very complicated stuff; the source code is only ~450LOC, which can be found here: https://github.com/Erkaman/wireframe-world/blob/gh-pages/wir.... It is relatively well-commented, so it should be easy to understand, I hope.

Re:Show HN: A simple infinite world in WebGL by degenerate on Thursday July 28, 2016 @09:20PM (#12184486)
Thanks for these! My personal favorite retro-synth mix right now: https://soundcloud.com/quicksexfm/qsfm25
Re:Show HN: A simple infinite world in WebGL by bottled_poe on Friday July 29, 2016 @01:52AM (#12185212)
I blindly clicked this at work. Big mistake.
Re:Show HN: A simple infinite world in WebGL by govindpatel on Friday July 29, 2016 @04:24AM (#12185584)
haha. same think happened to me. But I took my headphone out and started to listen to this. It turned out to be good one. :)
Re:Show HN: A simple infinite world in WebGL by erkaman on Friday July 29, 2016 @01:52AM (#12185214)
Thank you for the links! Since I did not really know where to find CC-licensed music, I did include any music.
Re:Show HN: A simple infinite world in WebGL by chronial on Friday July 29, 2016 @04:48AM (#12185651)
You absolutely should – the music made this a lot more awesome :).
Re:Show HN: A simple infinite world in WebGL by thristian on Thursday July 28, 2016 @06:20PM (#12183630)
If you can, you should really turn on anisotropic filtering, so that the grid-lines on the horizontal surfaces don't go all blurry.
Re:Show HN: A simple infinite world in WebGL by fitzwatermellow on Thursday July 28, 2016 @10:08PM (#12184639)
Thanks for posting. This brings back a lot of fond memories for me. The good old days when I was still teaching myself DirectX and OpenGL. Copying and updating ancient demoscene tutorials. These sorts of vector terrain flythroughs, infinite wormholes, looping roller coasters, dancing sinewave text animations and eternally zooming julia sets were my bread and better for understanding geometry and shading. The Moment of Zen here is, as you noted, how little actual code is required to build a world. Keep going ;)
Re:Show HN: A simple infinite world in WebGL by userbinator on Thursday July 28, 2016 @11:23PM (#12184864)
Indeed, keep going, and you may reach this level of awesome:

https://www.youtube.com/watch?v=_YWMGuh15nE

(Quite realistic terrain generated by a 4 kilobyte binary, along with music. Source code and its discussion here: https://news.ycombinator.com/item?id=11848097)

Re:Show HN: A simple infinite world in WebGL by david-given on Friday July 29, 2016 @03:27AM (#12185446)
The author then went on to produce a WebGL version in ShaderToy: https://www.shadertoy.com/view/MdX3Rr

He also wrote ShaderToy...

Re:Show HN: A simple infinite world in WebGL by erkaman on Friday July 29, 2016 @01:42AM (#12185194)
Inigio Quillez' homepage has lots of cool articles about this kind of stuff, so please check it out: http://www.iquilezles.org/www/index.htm
Re:Show HN: A simple infinite world in WebGL by jackfrodo on Thursday July 28, 2016 @04:04PM (#12182759)
>var f = 0.0015974 Where did this number come from? Is it arbitrary?
Re:Show HN: A simple infinite world in WebGL by erkaman on Thursday July 28, 2016 @04:57PM (#12183099)
Just arbitrary hand-tweaking. It was chosen because I though it looked good. When doing procedural generation like this, you basically just tweak constants 'til it looks good. There's no deeper reason behind it.
Re:Show HN: A simple infinite world in WebGL by Eyght on Thursday July 28, 2016 @05:53PM (#12183487)
I'm hoping that this kind of interaction will be part of one of our first encounters with aliens, sometime in the far future. The aliens would ask why we had done something a certain way and the human answer would be: "Because it looks good".
Re:Show HN: A simple infinite world in WebGL by tonmoy on Thursday July 28, 2016 @07:34PM (#12184000)
Another example: bootstrap
Re:Show HN: A simple infinite world in WebGL by ReFruity on Friday July 29, 2016 @06:01AM (#12185826)
Next step is to extract these constants for user to play with.
Re:Show HN: A simple infinite world in WebGL by asimuvPR on Thursday July 28, 2016 @03:58PM (#12182725)
It is really nice. Thanks for sharing.

Is there any particular reason you did this?

Re:Show HN: A simple infinite world in WebGL by erkaman on Thursday July 28, 2016 @04:56PM (#12183089)
I just wanted to try making something vaporwave-like. I really like the aesthetics of it.
Re:Show HN: A simple infinite world in WebGL by mkishi on Thursday July 28, 2016 @04:06PM (#12182771)
It starts visually glitching out after 10 seconds or so, for me. Doesn't really ruin the experience, but as it appears to get more pronounced with time, I don't think we'll reach infinity. :)
Re:Show HN: A simple infinite world in WebGL by _nalply on Thursday July 28, 2016 @05:09PM (#12183191)
After some time the glitches are reset and the process restarts.
Re:Show HN: A simple infinite world in WebGL by bartread on Thursday July 28, 2016 @06:19PM (#12183628)
It's very cool up until everything starts going a bit see through - although it does still look good even then.

Funny when I read the word "glitching" I assumed it would be a framerate hitch, which might be cause by GC, but I did a quick timeline grab and it seems OK for desktop. Collects about 12MB every 10-12 seconds. That might have more of an impact on mobile of course, especially Android.

I'm having that kind of issue with a game I'm working on - in my case I'm being way too cowboy about creating and throwing away JS objects for particles (only in 2D on a canvas) and it's causing GC framerate glitches on Android.

Re:Show HN: A simple infinite world in WebGL by deejbee on Friday July 29, 2016 @10:30AM (#12187036)
From what I've experienced and read about, it seems the best approach is not to create/destroy objects at run time since it can be an expensive operation and cause frame rate issues. It's better to hide them and build as many as you can when the app is started up.
Re:Show HN: A simple infinite world in WebGL by failrate on Friday July 29, 2016 @02:22PM (#12188799)
Yes, object pools are a good solution for elements like bullets in bullet hell games and similar applications.
Re:Show HN: A simple infinite world in WebGL by ben_jones on Thursday July 28, 2016 @04:12PM (#12182802)
"If you can't run it for some reason, a recorded gif of the demo can be found here"

WebGL in a nutshell.

Re:Show HN: A simple infinite world in WebGL by mwiedmann on Thursday July 28, 2016 @04:17PM (#12182828)
The .js file is over 10,000 lines of code. How did it get so bloated from your 450 lines of code?
Re:Show HN: A simple infinite world in WebGL by evan_ on Thursday July 28, 2016 @04:30PM (#12182910)
It includes imported libraries, primarily regl[1] which is 8228 lines long.

[1]: https://github.com/mikolalysenko/regl/blob/gh-pages/dist/reg...

Re:Show HN: A simple infinite world in WebGL by erkaman on Thursday July 28, 2016 @04:59PM (#12183116)
I didn't spend much time optimising the size. I thought it loaded fast enough for me. But maybe it doesn't load as fast on a slow connection...
Re:Show HN: A simple infinite world in WebGL by eshyong on Thursday July 28, 2016 @04:22PM (#12182854)
It's probably a bundled JS file containing all of his dependencies.
Re:Show HN: A simple infinite world in WebGL by robotmlg on Thursday July 28, 2016 @04:19PM (#12182841)
Node
Re:Show HN: A simple infinite world in WebGL by klodolph on Thursday July 28, 2016 @04:37PM (#12182964)
While the tooling uses Node, the bloat comes from the bundle which includes canvas-fit, regl, and gl-mat4.
Re:Show HN: A simple infinite world in WebGL by whostolemyhat on Friday July 29, 2016 @04:30AM (#12185599)
Since when do libraries used in your code classify as 'bloat'?