3 ms·
He links to shadertoy[1] with the code. it looks like the code is in C? how is it rendering in the browser? [1]: https://www.shadertoy.com/view/WsSBzh https://
by devmunchies 6y ago
He links to shadertoy[1] with the code. it looks like the code is in C? how is it rendering in the browser?
[1]: https://www.shadertoy.com/view/WsSBzh https://www.shadertoy.com/view/WsSBzh
- detaro 6y agoIt's not C, it's GLSL shader language, which is used in the browser through WebGL.
- coldtea 6y ago>it looks like the code is in C? how is it rendering in the browser? Plus, C could be compiled into WASM with emscripten, and be hooked to render on a Canvas or WebGL or something.
- Netcob 6y agoYou write GLSL, which is a shader language. Specifically, in this case, you write code that determines the color of a pixel given its coordinates (and some other input variables). On Shadertoy, they use WebGL to create a little rendering pipeline that in the simplest configuration renders two triangles to form a rectangle, using your GLSL code. Since it's WebGL (should be supported by all modern browsers, mobile included), that code is executed directly on your GPU. In more complex Shadertoy scenarios, you can do multiple passes where you render to different buffers and then use those buffers as textures in other passes. One of the uses of that is keeping state between frames, which would not be possible in a purely shader-based system otherwise. For example, if you have some sort of player character you move around the world, you may use one pixel to store the position, another to store the rotation and so on. Or you can use the image output from the previous frame as the input for the next frame to compute IIR functions, simulate cellular automatons and so on. I think by now you can even render to cube maps and multiple viewports (for VR). There's even a "sound" shader you can write that is called once and then renders a waveform for one minute and then plays that back while displaying the regular shader.