Hopefully there will be a better way in the future. Conclusion It was a lot of fun to learn about webgl shaders, and it improved my simulation drastically. Aside from frustrating angle problems (which should be uncommon it is quite easy overall.
Unfortunately, I couldn't find the bug just by eyeballing the hlsl. I used a process-of-elimination approach where I got rid of parts of shader code until things rendered properly. Then, I added parts back until I found the code that was causing the problem.
/script Browsers will not recognize the script type, so they won't execute your shaders as JS. In Three. Js, custom shaders use a ShaderMaterial. When you create this material, you supply your custom shaders: material new aderMaterial( uniforms: uniforms, attributes: attributes, vertexShader: tElementById vertexShader.textContent, fragmentShader: tElementById fragmentShader.textContent As you can see, a shader is just text. Js app with custom shaders. Why Use Custom Shaders? Shaders run on the graphics card and give you much lower-level access to how things are rendered. In my case, switching to custom shaders improved performance in my astronomics simulation a thousandfold and made it visually stunning: OpenGL Shader Language (glsl) Webgl shaders are small programs written in a specialized language. Using shaders in Three. Js, include your glsl shaders on your page in script tags, like so: script type"x-shader/x-vertex" id"vertexShader" / Your glsl vertex shader here. /script script type"x-shader/x-fragment" id"fragmentShader" / Your glsl fragment shader here. They are defined in your JS by type and value: / Define a color-typed uniform var uniforms myColor: type: "c value: new lor( 0xffffff ), ; Attributes are defined as arrays with length equal to the number of vertices. This is because in nearly all cases, Windows users are running Microsoft's proprietary DirectX instead of OpenGL. The glsl is automatically translated to hlsl (DirectX's equivalent) via angle. Although angle is great because it makes webgl work on Windows, you may occasionally run into some issues.