5 ms·
For anyone interested in playing around with SDFs, my friend and I made this open source library to make working with them more efficient, and you can write sha
by tehsauce 3y ago
For anyone interested in playing around with SDFs, my friend and I made this open source library to make working with them more efficient, and you can write shaders using javascript https://github.com/shader-park/shader-park-core https://github.com/shader-park/shader-park-core
- deleted 3y ago[deleted]
- CyberDildonics 3y agoWhy would you write a shader using javascript and not the dedicated shading language built into every web browser?
- tehsauce 3y agoGLSL is great! But it is very limited in many aspects. Js enables us to create a more ergonomic APIs for SDFs similar to processing/p5. You can easily mix the glsl and js code, and it also allows you to directly implement transformations on SDF functions, like revolving or extruding a 2D SDF into a 3D one with a transformation function: https://shaderpark.com/sculpture/-NeEtQ1JEccER6MjPQzq https://shaderpark.com/sculpture/-NeEtQ1JEccER6MjPQzq It's not meant to be a replacement for glsl, just to open up some cool new possibilities!
- CyberDildonics 3y agoTo be clear you are talking about generating SDF data in javascript, you aren't actually writing shaders in javascript like you said earlier.
- tehsauce 3y agoIt’s not obvious in that previous example, but you can also write shaders in js, in addition to the built in abstractions for SDFs. https://shaderpark.com/sculpture/-Nc57ho13qXl3G7fQ2wy https://shaderpark.com/sculpture/-Nc57ho13qXl3G7fQ2wy There are some limitations but again the point is just to explore new possibilities!
- CyberDildonics 3y agoThe first question was why anyone would write a shader in javascript, then it turned out it wasn't actually shaders written in javascript. Now you're telling me you can again, but the question is still why.
- tehsauce 3y agoThe first example was a js shader too but because it also included glsl it could have been easy to miss that. So the second example just emphasizes that better. Regarding why, see my first answer or feel free to browse the thousands of other examples on the site!
- CyberDildonics 3y agoWhy do you keep calling these shaders? Javascript isn't running on the GPU and it isn't doing any rendering. If making SDF data is called a shader, all scene setup is not and geometry creation would be the same.
- tehsauce 3y agoMaybe another example will be helpful :) https://shaderpark.com/sculpture/-M_TY8dwxuyliltrFjP2 https://shaderpark.com/sculpture/-M_TY8dwxuyliltrFjP2 No SDFs involved in this one.
- CyberDildonics 3y agoAgain, just passing around a javascript function doesn't mean it's a shader. Javascript isn't running the GPU and javascript isn't doing any rendering.
- tehsauce 3y agoShaderpark does a bit more than "pass around" javascript functions, it transpiles them to glsl. Believe it or not, web browsers themselves only transpile webgl shaders to other high level shader languages: hlsl on windows, msl on macos/ios, and glsl or sprir-v on linux. The os then compiles these to bytecode, and the driver finally compiles them to machine code which is sent to the GPU. So a webgl glsl shader isn't "running the gpu" or "doing rendering" any more than a js shader. They're both just high level languages at the top of a compilation chain ultimately targeting the GPU.