Print Entire Translation Unit

You need one of the following products to complete this exercise: Simdify® Free Edition, Simdify® Compute+ Module

During shader development, it can be very useful to print out the entire translation for a particular shader stage, which includes the results of preprocessing.

This exercise requires the Simdify® Compute+ Module, but you can do the same thing with any <Program> node.

Start The Layout application

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

    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.

    This is a picture of the desktop.

Open Additive Blend Sample

  1. Select File » Open from the main menu.

    The software displays the file dialog in the \Shader folder.

    This is a picture of the new project dialog.
  2. Enter the directory named Additive Blend and open the file named Additive Blend.box.

    The application loads the document.

    This is a picture of the additive blend shader.

Print The Fragment Shader Translation Unit

  1. Right click over the <Program> named Program and select Dump Shader Code... from the listed options.

    The application displays a dialog that allows you to choose the shader stage source code to print.

    This is a picture of the select shader source code dialog.
  2. Select the fragment shader source code from the Source option and click OK or hit ENTER when you are finished.

    The software saves the translation unit to disk and copies the file path to the Windows® clipboard.

  3. Start a text editor such as Notepad, Notepad++®, or Visual Studio®.
  4. Select the option to open a file from disk and use CTRL+V to paste the file path from the clipboard into the File name control in the dialog.

    (There will be a section of the dialog that allows you to enter the name of the file you wish to open.)

  5. Click OK or Open (or whatever option is available in your text editor) to open the file.

    #version 430 core
    // Enable this code to globally manage minimum version.
    /*
    #if __VERSION__ < 400
    #error Minimum GLSL version 400 not available. Your hardware does not support GLSL #version 400!
    #endif
    */
    
    #define GLSLANG_IGNORE
    #undef GLSLANG_IGNORE
    // file "D:\\Release6\\Content\\Library\\Shader\\Additive Blend\\430\\additive_blend_fragment_shader.glsl"
    #line 2
    // file "D:\\Release6\\Content\\Includes\\SPA_Constants.glsl"
    #line 1
    #ifndef SPA_CONSTANTS
    #define SPA_CONSTANTS
    
    /////////////////////////////////////////////////////////////////////////////////
    // Global Constant Declarations
    /////////////////////////////////////////////////////////////////////////////////
    
    /* ABOUT: This file contains global constants and other data you wish to make
    available to all shaders. */
    
    /* Controls editing-mode rendering output. This is implemented in the fragment
    program in particular. A non-zero w component indicates the rendering operations
    must generate a selection highlight (0.5) or a feedback geometry identifier (1.0). */
    uniform vec4 SPA_EditState;
    
    /* This indicates an offset for geometry indices or primitive id. Sum with the
    primitive ID to obtain a unique ID per primitive. See SPA_GPEmitFeedbackID() in
    SPA_Geometry.glsl. */
    uniform int SPA_BaseObjectID;
    
    /* This value indicates whether or not the editing mode output requires unique
    geometry indices. When false, it suppresses unique IDs. See SPA_GPEmitFeedbackID in
    SPA_Geometry.glsl. */
    uniform bool SPA_UsePerObjectID;
    
    // This value sets the maximum light count, as defined by the application.
    const int maxLightCount = int( 32 );
    
    /* The maximum light count for a shader. Must be less than or equal to
    maxLightCount. */
    const int lightCount = int( 32 );
    
    /* Energy Conservation */
    const float kPi               = float( 3.14159265 );
    const float kShininess        = float( 16.0 );
    const float lowerConservation = float( 2.0 );
    const float upperConservation = float( lowerConservation * 4.0 );
    
    /* Gamma */
    const float gamma = float( 2.2 );
    
    /* Min/Max Ranges */
    const int i8_min     = int( -127 );
    const int i8_max     = int( 127 );
    const int i16_min    = int( -32768 );
    const int i16_max    = int( 32768 );
    const int i32_min    = int( -2147483647 );
    const int i32_max    = int( 2147483647 );
    
    const uint ui8_min   = uint( 0 );
    const uint ui8_max   = uint( 255 );
    const uint ui16_min  = uint( 0 );
    const uint ui16_max  = uint( 65536 );
    const uint ui32_min  = uint( 0 );
    const uint ui32_max  = uint( 4294967295 );
    const float nfp_min  = float( 0.0 );
    const float nfp_max  = float( 1.0 );
    
    // WARNING: These must match enum Guides in ModelOpt.h!
    // These constants indicate values for M_SPA_Guide, which Simdify defines
    // to shader programs to signal that a particular Guide rendering option
    // is enabled. These guides require altering geometry and fragment processing
    // to augment mesh rendering with requested guides.
    #define G_FaceNormals 2
    #define G_VertexNormals 128
    #define G_Handles 1024
    #define G_Tangents 4096
    #define G_Vertices 8192
    #define G_Edges 16384
    #define G_HiddenEdges 32768
    
    // !SPA_CONSTANTS
    #endif
    // file "D:\\Release6\\Content\\Library\\Shader\\Additive Blend\\430\\additive_blend_fragment_shader.glsl"
    #line 3
    // file "D:\\Release6\\Content\\Includes\\Modules/SPA_EditStateFragmentColorOverride.glsl"
    #line 1
    #ifndef SPA_EDIT_STATE_FRAGMENT_COLOR_OVERRIDE
    #define SPA_EDIT_STATE_FRAGMENT_COLOR_OVERRIDE
    
    /////////////////////////////////////////////////////////////////////////////////
    // Application Edit State
    /////////////////////////////////////////////////////////////////////////////////
    
    // This function overrides output colors to support selection and
    // feedback pick rendering. Call this on the output value immediately
    // before assigning it to the fragment shader output ( EX: fragColor, gl_FragColor ).
    // The function returns true during selection or feedback rendering, and
    // false otherwise.
    bool SPA_EditStateFragmentColorOverride( inout vec4 colorOutput )
    {
       bool a_bIsEditState = SPA_EditState.a > 0.0;
    
    #if M_SPA_Guide == G_Vertices
       colorOutput = vec4( 1.0, 1.0, 1.0, 1.0 );
    #elif M_SPA_Guide == G_Edges
       colorOutput = vec4( 1.0, 1.0, 1.0, 1.0 );
    #elif M_SPA_Guide == G_FaceNormals
       colorOutput = vec4( 1.0, 1.0, 1.0, 1.0 );
    #elif M_SPA_Guide == G_VertexNormals
       colorOutput = vec4( 1.0, 1.0, 1.0, 1.0 );
    #elif M_SPA_Guide == G_Tangents
       colorOutput = vec4( 0.5, 0.5, 0.5, 1.0 );
    #else
       if( SPA_EditState.a == 0.5 )
       {
          colorOutput = SPA_EditState;
       }
       else
       if( SPA_EditState.a == 1.0 )
       {
          // If we have a geometry program, it is required to generate IDs that
          // are unique per-object and/or per-primitive, based on the
          // SPA_UserPerObjectID flag.
          // If we don't have a geometry program, we must generate the per-object
          // and per-primitive IDs ourselves.
          int primitiveId;
          #if M_SPA_GeometryProgramPresent
          primitiveId = gl_PrimitiveID;
          #else
          primitiveId = SPA_BaseObjectID + (SPA_UsePerObjectID ? gl_PrimitiveID : 0);
          #endif
    
          colorOutput.x = float( int( primitiveId / 65536 ) & 255 ) / 255.0;
          colorOutput.y = float( int( primitiveId >> 8 ) & 255 ) / 255.0;
          colorOutput.z = float( primitiveId & 255 ) / 255.0;
          colorOutput.w = 1.0;
       }
    #endif
       return a_bIsEditState;
    }
    
    // !SPA_EDIT_STATE_FRAGMENT_COLOR_OVERRIDE
    
    #endif
    // file "D:\\Release6\\Content\\Library\\Shader\\Additive Blend\\430\\additive_blend_fragment_shader.glsl"
    #line 4
    // file "D:\\Release6\\Content\\Library\\Shader\\Additive Blend\\430\\additive_blend_attributes.glsl"
    #line 1
    // Declare per-vertex attributes.
    struct vertexData
    {
       vec4 position;
       vec2 texcoord;
       vec3 normal;
       vec4 color;
       vec3 normalViewspace;
       vec3 positionViewspace;
    };
    // file "D:\\Release6\\Content\\Library\\Shader\\Additive Blend\\430\\additive_blend_fragment_shader.glsl"
    #line 5
    
    layout( rgba32f ) uniform image2D dst_image;
    
    uniform float format_min = float( 0.0 );
    uniform float format_max = float( 1.0 );
    
    in Data { vertexData attributes; } DataIn;
    out vec4 fragColor;
    
    void main(void)
    {
       ivec2 srcDims = imageSize( dst_image );
       ivec2 coords = ivec2( DataIn.attributes.texcoord * srcDims );
       vec4 pix = imageLoad( dst_image, coords );
       fragColor = pix;
    }
             

    This shows the translation unit with annotations for preprocessing line numbers.