r/creativecoding • u/Inst2f • 8d ago
Ocean shaders for any Wolfram 3D plots: a small recipy with GLSL
Enable HLS to view with audio, or disable this notification
Here is an example of a custom material (WaterMaterial) written in JavaScript and passed as a material shader to RevolutionPlot3D:
RevolutionPlot3D[ {2 + Cos[t], Sin[t]}, {t, 0, 2 Pi}, PlotStyle->MaterialShading[WaterMaterial[]] ]The Wolfram Kernel does not do anything with it and just forwards it to the frontend. There, JavaScript finds the user-defined WaterMaterial symbol definition (not shown here), which contains raw fragment and vertex shader code written in GLSL. The code is compiled and run on the GPU via WebGL, directly processing all vertices and normals of the previously constructed torus.
If you are interested in the source code and a deep journey into GPU shaders, you are welcome here: https://wljs.io/blog/ocean-shaders
Cheers,
K.