top | item 16036232

How to make a rain on a windshield shader in ShaderToy [video]

133 points| adamnemecek | 8 years ago |youtube.com

31 comments

order
[+] MichailP|8 years ago|reply
Is there a blazingly fast library for ray object intersection? Ideally usable from python? As I understand, ShaderToy uses implicit object description, and calculates ray object intersection numerically. It is somewhat of a abuse of OpenGL, since a scene in ShaderToy only has 2 triangles covering the screen, and the rest is calculated using pixel shader which calculates ray object intersections. I would like to have result of this intermediate calculation (point of ray object intersection).
[+] dahart|8 years ago|reply
NVidia's Optix has very fast ray-object intersection via GPU. I don't think there are python bindings though, it's C++ and CUDA.

ShaderToy doesn't come with object descriptions, nor with any specific intersection routines. This is just arbitrary glsl (GPU) code that people are doing cool tricks with. You can do regular ray tracing in ShaderToy, for example here's one of mine ray tracing (not ray marching) spheres: https://www.shadertoy.com/view/XllBRf

You don't get a BVH with ShaderToy, unless you manually write something clever yourself. You need a BVH to make blazingly fast ray object intersections, in general.

That said, it's worth understanding the ray marching algorithm that many folks on ShaderToy are using, because it's very very fast, if you can accept the limitations it comes with, and it does give you the hit location in space.

[+] boulos|8 years ago|reply
There's Embree, but I don't know (or think) they would have thought to make Python bindings. I'm not sure how fast Mitsuba is, but since Wenzel wrote his own C++ to Python wrapper I'd wager that there are Python bindings for that.

What's your use case?

[+] 127|8 years ago|reply
I don't know if you can consider it blazingly fast, but Blender has ray intersections from Python, and IIRC it was fast enough to make a 256x256x256 voxel grid in a couple of seconds with raycasts.
[+] dahart|8 years ago|reply
I just love the feel of this shader, it's not as complicated as some of the other nutty shaders you can find on ShaderToy, but it does a lot with a little and has such a nice chill vibe, especially with the music.

When I first saw it, I thought the raindrops must be pretty expensive, but the video shows how cheap they are to compute. There's a nice tiling trick so that the shader only evaluates one drop per pixel, but the tiling grid is moving so it's harder to see where the bounds are.

He's also using the Desmos math webapp to design some of the functions, which is a great reminder for me, I keep forgetting about it, and I need a good function plotter handy when I'm working on shaders.

[+] Scene_Cast2|8 years ago|reply
I also like Shadron, it has quite a bit more capability (being able to use your own textures is pretty important! I can actually get work done with Shadron, can't do that reasonably with shadertoy). The downsides are the small community size and no automatic sharing / GitHub / OSS integration.

Other features include UI sliders, image saving, pretty decent library, unlimited flexible layers, way easier debugging, and lots more. I'm a huge fan, I'd love for more people to use it too.

[+] erikpukinskis|8 years ago|reply
I don’t fully understand the code but this appears to be a very brute force way of doing it, which slows down as you add more raindrops, pixels, and lights.

I suspect you could do the same with signed distance fields in a way that runs in constant time irrespective of the number of drops at least.

You could also then scale and distort the car lights and add as many as you like without affecting performance either.

[+] ttoinou|8 years ago|reply
It's already constant time but he calls the function twice in order to have big bubbles and little bubbles overlapped
[+] johansch|8 years ago|reply
Intrigued by this I visited https://www.shadertoy.com/. There does seem to be a thriving community there.

Problem is, the browse pages have a 4x3 grid of live WebGL previews (rather than e.g. static images) of the shadertoys.

On my home desktop pc (win10, i4790k@4Ghz, GTX1070, 24 GB) running Chrome this means that inevitably, on page one or two, at least one of the shadertoys will use so much GPU computation that it starves out all other functionality, like being able to switch tabs etc.

[+] aphextron|8 years ago|reply
I've tried to bring this point up in the past as well. All they would need to do is add an MP4 rendering job to replace those with video. Although the transcoding would be quite expensive, I'm sure IQ could set up a donation system.
[+] adamnemecek|8 years ago|reply
I think that you can opt for image previews if you create an account. It’s in the options (maybe). The feature is there, I just don’t remember where.
[+] antoineMoPa|8 years ago|reply
I'm trying to code shadergif https://shadergif.com to fix this but of course, the only community I have yet is "me" and I don't have all shadertoy features. I render gifs and preview videos to avoid spamming GPUs.

The code is open source so anyone who wants new features can actually code it (after all, it's a coder community, why not let it code the tool that shadertoy is).

[+] gfody|8 years ago|reply
if you sign in, there's a 'use previews' option in config that will replace the live previews with thumbnails