You need the following Simdify® modules to complete this exercise: Simdify® Free Edition
In this exercise you'll learn to use the Outline app and the Module app to create a shader module that implements additive blending. The following table shows the skills required to complete this exercise.
Skill | Description |
---|---|
Starting Applications | You need to be able to access the Windows Start Menu, find applications, and start them. |
Opening Files | You need to be able to open files from disk. |
Tree View | You need to be able use a Windows tree view to expand and contract nodes. You need to be able to right click on the nodes to access node command menus. |
Text Editor | You need to be able to start a text editor such as Notepad, Notepad++, or Visual Studio and open a text file from the hard disk. You need to be able to edit the text file and save the changes. |
In this exercise, you'll learn to create new folders for your shader module project.
The application displays a splash screen and then the application desktop appears.
The application presents the file open dialog in the Outline application library folder. Note that there is a directory called Simdify Data.
The document appears in the Outline app.
The software contracts nodes until you can see all the main child nodes in the hierarchy.
This finds the Module library folder and selects it so that it's easy to see.
The Simdify Data project contains all the information associated with your Simdify installation. Think of it like the 'north star' for everything you're doing with Simdify. You can always find all your documents in this project.
In this exercise, you'll learn to create a new shader module project.
The software creates the folder on disk and adds a new folder to the hierarchy.
The software presents a dialog that allows you to create a new shader module.
The application creates the new shader module.
In this exercise, you'll learn to open the new shader module project in the Module app.
You can see all the files associated with the new shader module.
The Module application loads the new shader module.
If you're interested, you can learn about Simdify document rendering.
In this exercise, you'll learn to implement the additive blend shader.
The software displays a dialog that allows you to select the source file you wish to open. This includes any files #included by the shader. (While GLSL itself doesn't automatically support preprocessing shader source code, Simdify design applications DO allow you to use #include to create modular shaders.)
The application displays a dialog box that informs you the path has been copied to the clipboard.
You'll see path such as: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\430\fragment_shader.glsl
All shaders are separated into two sections. Declarations are stored at global scope. The fragment shader itself is stored inside void main(void). Later, when we add nodes to the document to build our shader module, we're only going to be concerned with things declared at global scope. The body of all shaders is effectively invisible to Simdify design applications such as Module.
// #version 430
// The version number is automatically injected by the application.
// It is included above for reference purposes only.
#include <SPA_Version.glsl>
#include <SPA_Constants.glsl>
#include <Modules/SPA_EditStateFragmentColorOverride.glsl>
#include "vertex_attributes.glsl"
in Data { vertexData attributes; } DataIn;
out vec4 fragColor;
void main(void)
{
fragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
SPA_EditStateFragmentColorOverride( fragColor );
}
Although you can't see it in your shader code, the OpenGL shader compiler on your machine also "inserts" built-in variables so they are visible to your shader.
fragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
This line assigns red to the fragment shader output.
fragColor = vec4( 0.0, 1.0, 0.0, 1.0 );
This line assigns green to the fragment shader output.
// #version 430
// The version number is automatically injected by the application.
// It is included above for reference purposes only.
#include <SPA_Version.glsl>
#include <SPA_Constants.glsl>
#include <Modules/SPA_EditStateFragmentColorOverride.glsl>
#include "vertex_attributes.glsl"
in Data { vertexData attributes; } DataIn;
layout( binding = 0 ) uniform sampler2D lhs;
layout( binding = 1 ) uniform sampler2D rhs;
uniform float blend_opacity;
out vec4 fragColor;
vec4 add_images( vec4 base, vec4 blend, float opacity )
{
return ( base * opacity ) + blend * ( 1.0 - opacity );
}
void main(void)
{
vec4 lhs_sample = texture( lhs, DataIn.attributes.texcoord );
vec4 rhs_sample = texture( rhs, DataIn.attributes.texcoord );
vec4 res = add_images( lhs_sample, rhs_sample, blend_opacity ); // Performs additive blending using a standard algorithm.
fragColor = res;
SPA_EditStateFragmentColorOverride( fragColor );
}
layout( binding = 0 ) uniform sampler2D lhs;
layout( binding = 1 ) uniform sampler2D rhs;
uniform float blend_opacity;
In the next section, we'll create nodes that represent these declarations.
In this exercise, you'll learn to add resources required by the additive blend shader.
The new shader code is running, but we haven't provided the textures and uniforms needed to generate a result. You might see white or black depending on your GPU.
The software presents a dialog that shows you items that have been declared in your shader.
The software adds the items to the hierarchy. You'll notice some of the new items have red lines underneath them. This means that there is an error.
Move your mouse over the <SamplerNode> named layout( binding = 0 ) uniform sampler2D lhs. You'll see a tooltip appear that displays information the error.
To make a long story short, both of the <SamplerNode> objects expect a <Texture>.
In this exercise, you'll learn to load a texture from disk.
The software presents a dialog that allows you to select a texture from disk.
The software adds a <Texture> node to the document and connects the <SamplerNode> to the new <Texture> node.
Previously the rendered square in the middle of the worksheet was rendered with white or black. Note that the rendered square in the middle of the worksheet may change color. It may become white or black. This is because we've provided only a single texture and the shader requires two textures.
You can see the new <Texture> node named additive_lhs.
In this exercise, you'll learn to load a texture from disk.
NOTE: Make sure you are selecting the second sampler, not the first!
The software presents a dialog that allows you to select a texture from disk.
The software adds a <Texture> node to the document and connects the <SamplerNode> to the new <Texture> node.
Now you can see something other than black or white. It shows only one texture because we haven't configured the <Float32Node> that sets the blending opacity. In this case, blending opacity is still 0.0, which means that it will render 100% of one of the textures.
You can see the new <Texture> node named additive_rhs.
In this exercise, you'll learn to configure a uniform.
This displays a property editor that allows you to edit the value of the node.
Now the shader is rendering a useful result.
In this exercise, you'll learn to export the document to the Simdify runtime.
The software displays a dialog that allows you to configure the export parameters. We'll use the default values, which means we don't need to make any changes.
The software exports the document and opens a folder that contains the exported data.
The Simdify Runtime starts and loads the file from disk.
This is your first OpenGL workload running in the Simdify Runtime.
You'll see the export log in the output window.
--- <Executing Export 'C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Additive-Blend-Module-430.box - Invoking Function: Execute'> ---
Processing <Model3D> named Module.
Traversing <Group> named Module.
Processing <IncludePaletteNode> named Includes.
Traversing <Group> named Includes.
Processing <DataPaletteNode> named Locals.
Traversing <Group> named Locals.
Traversing <Group> named Inputs.
Traversing <Group> named Texture Constraint.
Traversing <Group> named Outputs.
Processing <ShaderPaletteNode> named Shaders.
Traversing <Group> named Shaders.
Processing <Program> named Visual.
Traversing <Group> named Visual.
Processing <TexturePaletteNode> named Textures.
Traversing <Group> named Textures.
Processing <Texture> named additive_lhs.
Processing <Texture> named additive_rhs.
Processing <GeometryPaletteNode> named Geometry.
Traversing <Group> named Geometry.
Processing <ParametricMesh> named Mesh.
Traversing <Group> named Mesh.
Processing <ShaderResourceNode> named Visual.
Traversing <Group> named Visual.
Processing <ProgramBindNode> named Bind Visual.
Traversing <Group> named Bind Visual.
Processing <Float32MatrixNode> named uniform mat4x4 modelViewMatrix.
Processing <Float32MatrixNode> named uniform mat4x4 modelViewProjectionMatrix.
Processing <SamplerNode> named layout( binding = 0 ) uniform sampler2D lhs.
Processing <SamplerNode> named layout( binding = 1 ) uniform sampler2D rhs.
Processing <Float32Node> named uniform float blend_opacity.
Processing <ShaderResourceNode> named Render.
Traversing <Group> named Render.
Processing <NodeLink> named Mesh.
Traversing <Group> named Mesh.
Validating <Program>: /Shaders/Visual
Validating vertex shader: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\430\vertex_shader.glsl
Validating fragment shader: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\430\fragment_shader.glsl
Validating <Float32MatrixNode>: /Visual/uniform mat4x4 modelViewMatrix
Validating <Float32MatrixNode>: /Visual/uniform mat4x4 modelViewProjectionMatrix
Validating <SamplerNode>: /Visual/layout( binding = 0 ) uniform sampler2D lhs
Validating <SamplerNode>: /Visual/layout( binding = 1 ) uniform sampler2D rhs
Validating <Float32Node>: /Visual/uniform float blend_opacity
Exporting Document...
Exported <EditModel3D> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Module-91A8A638-8410-4EC7-8709-6D8ED55AA13B.spa_binary_node
Exported <IncludePaletteNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Includes-19FC5DE5-BB8D-4964-931A-D62BED309514.spa_binary_node
Exported <DataPaletteNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Locals-523C30B4-04D4-4169-9A6D-78C2AC94B1A0.spa_binary_node
Exported <ShaderPaletteNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Shaders-1FD306BD-63D5-4389-9F9C-ACBECD4A0442.spa_binary_node
Exported <Program> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Visual-E7274A5C-F421-4C62-9E3F-8E9F58E3E419.spa_binary_node
Exported <TexturePaletteNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Textures-65EFE395-C794-4336-B8A6-8345FDACD875.spa_binary_node
Exported <Texture> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\additive_lhs-250ACD95-4D63-4047-B637-D297E0BACC24.spa_binary_node
Exported <Texture> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\additive_rhs-E319EB15-2608-49CB-AF26-0341884360EE.spa_binary_node
Exported <GeometryPaletteNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Geometry-0C262F07-A870-4B87-AF2B-7D0474E2266A.spa_binary_node
Exported <ParametricMesh> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Mesh-EB1E6E0B-3F48-48DC-8A7E-AC3E37AD331C.spa_binary_node
Exported <ShaderResourceNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Visual-512B61D4-6E6C-4448-AD59-E1A354AB420C.spa_binary_node
Exported <ProgramBindNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Bind_Visual-19884730-8F44-439A-A26E-2EBFA07E801E.spa_binary_node
Exported <Float32MatrixNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\uniform_mat4x4_modelViewMatrix-3A226123-F7DA-46DD-B6E5-278285C663FF.spa_binary_node
Exported <Float32MatrixNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\uniform_mat4x4_modelViewProjectionMatrix-2E389D77-B629-4F22-954D-BFCB95A7BDCF.spa_binary_node
Exported <SamplerNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\layout(_binding_=_0_)_uniform_sampler2D_lhs-09224924-F224-4B4F-824E-41B02B134A0E.spa_binary_node
Exported <SamplerNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\layout(_binding_=_1_)_uniform_sampler2D_rhs-7CECECD8-1930-4182-9A66-D7145B31AD22.spa_binary_node
Exported <Float32Node> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\uniform_float_blend_opacity-3F3A0EA1-9EF0-4931-80E6-9206895C8193.spa_binary_node
Exported <ShaderResourceNode> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Render-4AC8B059-9665-44FF-9A2F-9424373177B9.spa_binary_node
Exported <NodeLink> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Mesh-58AABF99-DF82-4C91-98FA-561E057A217B.spa_binary_node
Exported <Model3D> to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\Additive-Blend-Module-430.spa_binary_graph
Exported to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\E7274A5C-F421-4C62-9E3F-8E9F58E3E419_vertex_shader.glsl
Exported to disk: C:\Users\Installer Test 0\Documents\Scenomics\Library\Module\FBO Image Processing Tiles\Additive-Blend-Module\Export Win64 Additive-Blend-Module-430\E7274A5C-F421-4C62-9E3F-8E9F58E3E419_fragment_shader.glsl
Document export complete.
The export log provides information about the nodes that were visited during the export process and whether or not the export was successful. You don't generally need to pay too much attention to the export log unless there's an error.
Question: what if we want to create a workflow that uses multiple shaders? Answer: we can use the Layout app. The Layout app allows you to build workflows from by creating tiles and connecting their inputs and outputs. This means that for any shader module we want to use with the Layout app, we need to make a model of the shader module's inputs and outputs. This additive blend shader takes two input textures and adds them together, using an opacity value to determine how to blend the two images together. That means we need to create three inputs. For outputs, the additive blend shader module renders to the screen buffer. In that case we can use a <Texture> to model the output.
The software presents a dialog that allows you to set the name of the new constraint.
The software adds the new constraint to the document:
The software presents a dialog that allows you to set the name of the new constraint.
The software adds the new constraint to the document:
The software presents a dialog that allows you to set the name of the new constraint.
The software adds the new constraint to the document:
This shader module writes directly to the screen. For that reason, it can be a little tricky to imagine how we can create output data. The screen is generally going to require RGBA data, but we might have shaders that need to write integer or floating point data. In this case, we'll use texture.
The software presents a dialog that allows you to set the name of the new constraint.
The software adds the new constraint to the document: