Back to Help

Editing Shader Code

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.


Shader Parameters

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.


Vertex Buffer Data Types

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:


Color Attachments

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.


Consistency Among the Connected

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.


Changes Available in Real Time

Some changes don't require shader recompilation and are available instantly in real time. These include:


Changes Available After a Recompile

Some changes require a recompilation of your shader code before they are reflected in ShaderScope. These include:



Back to Help