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 application displays a splash screen and then the application desktop appears.
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.
The software presents an Explorer® in the directory containing the desired GLSL reference shader.
The software opens the GLSL reference document.
The software presents a dialog that allows you to select which source files to open.
The full path to the fragment shader is copied to the Windows® clipboard.
#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.
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.
The software presents an Explorer® in the directory containing the desired GLSL reference shader.
Select image2D.box and click Open or hit ENTER when you are finished.
The software presents a dialog that allows you to select which source files to open.
The full path to the fragment shader is copied to the Windows® clipboard.
#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.