You need the following Simdify® modules to complete this exercise: Simdify® Free Edition
Glslang is amazing but it doesn't support absolutely every single GLSL feature. Shader subroutines are a great example. This means that if you write GLSL code that uses subroutines, or possibly other GLSL features that Glslang does not support, the Module application will present a Glslang compiler error when you rebuild a document. For this reason, we provide a very simple way of fencing code from Glslang. You just wrap the code in preprocessor statements and that's it. In this exercise you'll learn how to use the preprocessor to fence code from Glslang.
The application displays a splash screen and then the application desktop appears. The main menu is composed of three items that contain commands relevant to the current context (which is an empty document). The interface changes when you create a new file or load a file from disk.
The software displays the file dialog in the Module library folder.
The application loads the document.
This copies the absolute path to the fragment shader source code to the Windows® clipboard. For example, a file path like the following: D:\Release6\Content\Library\Shader\User Basic Exercise\460\user_basic_exercise_fragment_shader.glsl is copied to the clipboard.
This is the fragment shader.
// #version 400
// The version number is automatically injected by the application.
// It is included above for reference purposes only.
#include <SPA_Version.glsl>
#include "vertex_attributes.glsl"
#ifndef GLSLANG_IGNORE
subroutine vec4 RenderOutputColor();
subroutine( RenderOutputColor ) vec4 SetFragmentColorRed()
{
return vec4( 1.0, 0.0, 0.0, 1.0 );
}
subroutine( RenderOutputColor ) vec4 SetFragmentColorGreen()
{
return vec4( 0.0, 1.0, 0.0, 1.0 );
}
subroutine ( RenderOutputColor ) vec4 SetFragmentColorBlue()
{
return vec4( 0.0, 0.0, 1.0, 1.0 );
}
subroutine ( RenderOutputColor ) vec4 SetFragmentColorOrange()
{
return vec4( 1.0, 0.6, 0.0, 1.0 );
}
subroutine uniform RenderOutputColor SetFragmentColor;
#endif
in Data { vertexData attributes; } DataIn;
out vec4 fragColor;
void main(void)
{
fragColor = SetFragmentColor();
}
The preprocessor include statement #include <SPA_Version.glsl> is included at the top. To fence Glslang code, you must include this module. The shader subroutine code is wrapped inside #ifndef GLSLANG_IGNORE with a trailing #endif at the end. The Module app doesn't process code inside void main(void) so you don't have to put fences around code in that section of your shader. To fence code from Glslang computation, just include SPA_Version.glsl as shown above, and declare your code inside the preprocessor block as shown.
Note that the because of the code fencing, the Module application build process cannot create subroutine uniform Noise SelectNoise in the document. To create this, simply right click over the <Program> and select Bind Subroutines from the listed options.