TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to draw oscilloscope lines with WebGL

143 pointsby nochover 7 years ago

10 comments

ridiculous_fishover 7 years ago
Drawing lines in WebGL is pretty hard. Here&#x27;s my Schrödinger wavefunction visualizer (<a href="http:&#x2F;&#x2F;ridiculousfish.com&#x2F;wavefiz&#x2F;" rel="nofollow">http:&#x2F;&#x2F;ridiculousfish.com&#x2F;wavefiz&#x2F;</a>) where I learned too much about it.<p>Note these lines are in actual 3d space: you can rotate the scene using the circle control towards the bottom.<p>WebGL supports lines natively, but Windows Chrome ignores the thickness (<a href="https:&#x2F;&#x2F;bugs.chromium.org&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=60124" rel="nofollow">https:&#x2F;&#x2F;bugs.chromium.org&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=60124</a>) so I had to find a different approach on Chrome.<p>The approach I used is per Matt Deslauriers (<a href="https:&#x2F;&#x2F;mattdesl.svbtle.com&#x2F;drawing-lines-is-hard" rel="nofollow">https:&#x2F;&#x2F;mattdesl.svbtle.com&#x2F;drawing-lines-is-hard</a>) . The essential idea is to construct a zero-width line, then use a vertex shader to push each vertex along the line&#x27;s normal in screen space (not model space). Now represent each vertex twice, and push each one in opposite directions, and you get a nice width.<p>A fragment shader is used to soften the edges.<p>Here&#x27;s my vertex shader, which is the meat of the drawing: <a href="https:&#x2F;&#x2F;github.com&#x2F;ridiculousfish&#x2F;wavefiz&#x2F;blob&#x2F;master&#x2F;ts&#x2F;polyline.ts#L306" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ridiculousfish&#x2F;wavefiz&#x2F;blob&#x2F;master&#x2F;ts&#x2F;pol...</a>
absrndover 7 years ago
&quot;it might be weird to store the same point 4 times in a buffer, but I could not find a better way&quot;<p>Couldn&#x27;t you use a geometry shader to convert points into triangles (or quads)?
评论 #16037523 未加载
Fifer82over 7 years ago
I am a flash guy. I used to do BitmapData fun (wonderfl) which was offly related to “processing”. How can I enter webgl?<p>Webgl and “shadertoy” is why I am in computing, I am not here for Angular but this is how I make money.<p>My fascination is pointless processing of pixels and without it I feel bored.<p>I need to learn webgl but there seems no definite guide.
评论 #16043405 未加载
tw1010over 7 years ago
I find this post intriguing not just for the actual effect, but as yet another little signal of the slow and steady mixing of serious-ish mathematics (though mostly applied maths) into engineering culture; which there was almost no trace of only a few years ago.
评论 #16039156 未加载
评论 #16039211 未加载
flannelheadover 7 years ago
Works really well even on my old-ish smartphone (2014). WebGL is really interesting, too bad I still have yet to find the time to get a grasp of it. But blog posts like this are very inspiring!
Exumaover 7 years ago
This song is fucking incredible and unique... OMG
Pica_soOover 7 years ago
If you port this shader for rendering to texture, you can make quite nice rail-gun trails.
banachtarskiover 7 years ago
I don&#x27;t understand why&#x27;d you do it this way. I would draw a full screen quad and evaluate if a pixel should be lit or not in screen space in a frag&#x2F;pixel shader.
评论 #16039165 未加载
thethirdoneover 7 years ago
With bloom turned on, it looks really good.
评论 #16038527 未加载
grzmover 7 years ago
(2015)