Accessing Sample Files

You need the following Simdify® modules to complete this exercise: Simdify® Free Edition

In this exercise you'll learn how to access shader samples. There are two groups of samples: reference shaders and library shaders. You can alway access library shaders by starting the Module application and selecting File > Open from the main menu. Then you can simply select the directory containing the shader module you wish to open.

The GLSL reference library is very large. The reference library included with Simdify Free Edition contains several hundred sample documents, and the version included with Simdify Texture+ contains around 5000 sample shaders designed to provide working samples that render nearly every OpenGL pixel format and texture topology in all GLSL versions that support them. To access sample documents, the Module application includes a command on the file menu that makes it easy to explore the GLSL reference library and find exactly what you're looking for.

Start The Module Application

  1. Start the Module app. (Start > Programs > Scenomics > Module) or (Windows® key and then type 'Module' to find the app icon.)

    The application displays a splash screen and then the application desktop appears.

    This is a picture of the desktop.

Open Reference Document — sampler2D.box

  1. Examine the main menu and select File > Open From GLSL Reference Library....

    The software presents a dialog that allows you to choose the GLSL version, pixel format, and topology of the GLSL reference shader you wish to locate. The third option allows you to open the reference document in the application or to open an Explorer® window to the location of the GLSL reference shader.

    This is a picture of the reference shader selector dialog.
  2. Set Select GLSL Version to 430.
  3. Set Select Sampler Type to sampler2D.
  4. Click OK or hit ENTER when you are finished.

    The software presents an Explorer® in the directory containing the desired GLSL reference shader.

    This is a picture of the file open dialog.
  5. Select sampler2D.box and click Open or hit ENTER when you are finished.

    The software opens the GLSL reference document.

    This is a picture of the GLSL reference document.
  6. Examine the hierarchy and find the <Program> node named Visual.
  7. Right click over the <Program> node named Visual and select Copy Source Path > Fragment Shader from the listed options.

    The software presents a dialog that allows you to select which source files to open.

    This is a picture of the GLSL reference document.
  8. Select fragment_shader.glsl and click OK or hit ENTER when you are ready.

    The full path to the fragment shader is copied to the Windows® clipboard.

  9. Start a text editor such as Notepad, Notepad++, or Microsoft Visual Studio.
  10. In the text editor, select the option to open a file and use CTRL + V to paste the path to the fragment shader into the part of the dialog that specifies which file to open.
  11. Open the shader source file.
    #include <SPA_Version.glsl>
    #include <SPA_Constants.glsl>
    #include <Modules/SPA_EditStateFragmentColorOverride.glsl>
    #include "vertex_attributes.glsl"
    
    in Data
    {
       vertexData attributes;
    } DataIn;
    
    uniform float format_min = float( 0.0 );
    uniform float format_max = float( 1.0 );
    layout( binding = 0 ) uniform sampler2D pixel_data;
    
    out vec4 fragColor;
    
    void main(void)
    {
       vec4 pix = texture( pixel_data, DataIn.attributes.texcoord );
       fragColor = pix;
       SPA_EditStateFragmentColorOverride( fragColor );
    }

    This reference shader shows you how to write code that uses <sampler2D>. Notice also at the end, the call to SPA_EditStateFragmentColorOverride( fragColor ). This is important for shaders that need to use the fragment picking systems, such as shaders you wish to debug.

Open Reference Document — image2D.box

  1. Examine the main menu and select File > Open From GLSL Reference Library....

    The software presents a dialog that allows you to choose the pixel format and topology of the GLSL reference shader you wish to locate. The third option allows you to open the reference document in the application or to open an Explorer® window to the location of the GLSL reference shader.

    This is a picture of the reference shader selector dialog.
  2. Set Select GLSL Version to 430.
  3. Set Select Sampler Type to image2D.
  4. Click OK or hit ENTER when you are finished.

    The software presents an Explorer® in the directory containing the desired GLSL reference shader.

    This is a picture of the file open dialog.

    Select image2D.box and click Open or hit ENTER when you are finished.

    This is a picture of the GLSL reference document.
  5. Examine the hierarchy and find the <Program> node named Visual.
  6. Right click over the <Program> node named Visual and select Copy Source Path > Fragment Shader from the listed options.

    The software presents a dialog that allows you to select which source files to open.

    This is a picture of the GLSL reference document.
  7. Select fragment_shader.glsl and click OK or hit ENTER when you are ready.

    The full path to the fragment shader is copied to the Windows® clipboard.

  8. Start a text editor such as Notepad, Notepad++, or Microsoft Visual Studio.
  9. In the text editor, select the option to open a file and use CTRL + V to paste the path to the fragment shader into the part of the dialog that specifies which file to open.
  10. Open the shader source file.
    #include <SPA_Version.glsl>
    #include <SPA_Constants.glsl>
    #include <Modules/SPA_EditStateFragmentColorOverride.glsl>
    #include "vertex_attributes.glsl"
    
    in Data
    {
       vertexData attributes;
    } DataIn;
    
    uniform float format_min = float( 0.0 );
    uniform float format_max = float( 1.0 );
    layout( rgba8, binding = 0 ) readonly uniform image2D pixel_data;
    
    out vec4 fragColor;
    
    void main(void)
    {
       ivec2 src_dims = imageSize( pixel_data );
       ivec2 coords = ivec2( DataIn.attributes.texcoord * vec2( src_dims ) );
       vec4 pix = imageLoad( pixel_data, coords );
    #if SPA_GL_VENDOR == SPA_GL_INTEL
       fragColor = vec4( pix.b, pix.g, pix.r, pix.a );
    #else
       fragColor = pix;
       SPA_EditStateFragmentColorOverride( fragColor );
    #endif
    }

    This reference shader shows you how to write code that uses <image2D>. Since it's <image2D>, notice how we convert the fractional texture coordinates to integer values that we can pass to imageLoad(...). Notice also at the end, the call to SPA_EditStateFragmentColorOverride( fragColor ). This is important for shaders that need to use the fragment picking systems, such as shaders you wish to debug.