You can use any valid Metal Shader Language in your shader code with ShaderScope, and with a few exceptions (see below) you can type any shader you'd like, including your own structs for things like data, color output, etc. ShaderScope uses Apple's own Metal compiler, so any MSL code version 3.2 or earlier should work just fine, though there are a few restrictions related to how ShaderScope works.
When you edit and recompile your code, ShaderScope will attempt to detect any new shader parameters you've added (and those you've removed) as well as data types (typically structs) related to alternate vertex buffer types and multiple color attachment output.
When you add or remove shader parameters from your code, you must click the Recompile button (or use command B) before those changes are reflected in the user interface. This is important when you're adding a parameter and want to connect an input (3D model, texture, number, etc.) to it. You won't see it reflected on the parameter list menu until you click Recompile.
ShaderScope's standard vertex data type includes many of the primary vertex properties a shader would need. If you find you want to specify your vertices in different ways you are welcome to do so. If you do this you should be sure to change the data type for your shader parameters that accept vertices to reflect this new type, and that the input type is something Metal can pass vertex data (either [[stage_in]] or a correctly typed [[buffer(#)]] parameter).
Also be aware that because ShaderScope processes the 3D model files and sets which properties are available to your shaders, anything beyond these five are unavailable:
| Position | |
| UV Coordinates | If present in the model file |
| Normal vector | If present in the model file |
| Tangent | Computed; useful for normal maps |
| Bitangent | Computed; useful for normal maps |
By default any render pass you add in ShaderScope will render to color attachment 0. If you would like to specify others and/or render to multiple color attachments, ShaderScope supports that.
In your shader code, simply add a struct that specifies multiple color attachments, change the return type of your fragment shader to that new type, and update your fragment shader code to write color values to each element in your new struct before returning it.
ShaderScope manages the destination textures for color (and depth) attachments, so if you add or change any attachments ShaderScope will add/remove the appropriate number of destination textures and attach them to the relevant render pass.
When rendering to multiple color attachments, it's important to note that Metal requires that all render pipeline states that draw during a particular render pass write to the same color attachments.
ShaderScope will track this as you connect render pipeline states to your render passes, and if there are any inconsistencies you will see a message on your render pass letting you know what they are.
Some changes don't require shader recompilation and are available instantly in real time. These include:
| 3D Models | Changing a parameter's input from one file to another |
| Textures | Changing a parameter's input from one file to another |
| Numeric Values | Sliding the numeric shader input's slider and/or updating its range will be instantly visible on all views that render that shader's output |
| Timer-based Values | These are fed each frame into your shader and can be seen updating each relevant render in real time, including changes to duration and speed |
Some changes require a recompilation of your shader code before they are reflected in ShaderScope. These include:
| Changing the code of the shader function itself |
| Shader parameters (name, data type, address space, etc.) |
| Color attachment render targets (adding / removing) |
| Compute shader output textures (adding / removing) |