Basic Document Structure
You need one of the following products to complete this exercise: Scenome® Platform Binaries
This section describes common document layout and structures you'll encounter throughout these exercises. You can skip this section
and move on to the exercises if you wish.
It's important to know that you don't create these resources manually. Most of these resources are created
by the application when you create a new file. Additional resources, such as uniforms, uniform buffers, or shader buffers,
are automatically created when you modify your GLSL source code and execute the Shader app's document build command. Most of the time you
only need to edit nodes and specify the values you want to use. Sometimes you will create new textures or load textures from disk.
The general philosophy of Scenome is that work should be automated wherever possible.
Overview
Sometimes a simple shader document is just what you need. You can use the basic shader documents that you create to implement
vertex, tessellation, geometry, and fragment shaders.
This document was created with the File » New Shader command and is basically a very simple
vertex and fragment shader. You notice sections for Includes, Locals, Visual Shader, Visual Resources, and
Execute Workload.
Includes
In the Includes section, it's possible to include content from other documents. Most of the time, this is handled automatically
when you are using the Shader application. However there may be times when you wish to import content from another document.
Options are:
-
Includes. This is an <IncludePaletteNode> and you can right click on it to create <FileNode> objects that refer to other documents.
You can right click on the <FileNode> objects to add nodes from other documents. These nodes will be in the form of a <NodeLink>, which is
a type of node that is like a hyperlink from one document to another.
Locals
In the Locals section, it's possible to declare local variables. You might use local variables to store a value that will be used
by a shader, but not necessarily set as a shader constant. Or you might declare a local variable and then use its value to drive events
that modify other nodes in the document.
Options are:
-
Includes. This is a <DataPaletteNode> and you can right click on it to create <VariableNode> objects like <Int32Node>.
Other nodes in the document can use the values stored by these nodes.
Visual Shader
In the Visual Shader section, we connect the <Program> node to the vertex and fragment shader source code.
Private uniforms (uniforms that you should not modify) are found below the <Program>. In this case you can
see uniform mat4x4 modelViewMatrix, and uniform mat4x4 modelViewProjectionMatrix, which are used to
render the mesh. The Visual Shader section separates the <Program> from resources so that you can define
multiple sets of resources used by one <Program>.
Options are:
-
Program. Linked to the vertex and fragment shader source code on disk. You can move the mouse over the <Program> in the application to see the sources file to which it is connected.
The document is automatically updated when you make changes to your shader code. This node's child nodes are also automatically updated when you make changes to your shader code and execute the Shader app's document build command.
-
uniform mat4x4 modelViewMatrix. A <Float32MatrixNode> that captures the model view matrix from the rendering device. Typically used
by the vertex shader to transform vertex shader primitive information to viewspace. For example, you can multiply the normal by the model view matrix
to compute the normal in viewspace.
-
uniform mat4x4 modelViewProjectionMatrix. A <Float32MatrixNode> that captures the model view projection matrix from the rendering device.
Typically this is used to multiply position attributes to compute screenspace positions.
Visual Resources
In the Visual Shader section, we specify resources used to render a <Mesh>. <Mesh> nodes are most often used to provide
a surface to render the results of shaders. This section also includes public uniforms, materials, textures, and samplers.
This structure is used to help keep your document nicely organized.
Options are:
-
Uniforms. This is a <UniformPaletteNode> that stores public uniforms. GLSL has no concept of public or private uniforms, but
we separate uniforms by their location in the document to provide a hint that that you should be careful when modifying certain uniforms.
This node's child nodes are automatically updated when you make changes to your shader code and execute the Shader app's document build command.
-
Materials. A <MaterialPaletteNode> stores a list of <Material> nodes used by a <Mesh>. Typically, only a single
<Material> is used, but multiple <Materials> are supported.
-
Material. A <Material> stores a connection to a <Program>, <MaterialPaletteNode>, and <SamplerPaletteNode>.
These resources are bound to the GPU when the <Mesh> that uses the <Material> is rendered.
-
Textures. A <TexturePaletteNode> stores a list of <Texture> nodes used by various <SamplerNodes>.
-
Samplers. A <SamplerPaletteNode> stores a list of <SamplerNodes> used to bind samplers to the rendering device.
This node's child nodes are automatically updated when you make changes to your shader code and execute the Shader app's document build command.
-
Mesh. A <Mesh> that provides a surface onto which we can render results on screen. You'll notice also that vertex
attributes are defined below the <Mesh>. These are automatically generated and match the vertex attributes defined in the vertex shader.
This node's child nodes are automatically updated when you make changes to your shader code.
-
position. An <AddChannelModifier> that implements per-vertex position attributes. This is automatically updated
when you make changes to a vertex shader.
-
texcoord. An <AddChannelModifier> that implements per-vertex texture coordinate attributes. This is automatically updated
when you make changes to a vertex shader.
-
normal. An <AddChannelModifier> that implements per-vertex normal attributes. This is automatically updated
when you make changes to a vertex shader.
-
color. An <AddChannelModifier> that implements per-vertex color attributes. This is automatically updated
when you make changes to a vertex shader.
-
RectangleGeometryModifier. A <RectangleGeometryModifier> that implements a sheet of polygons onto which the shader is rendered.
-
CalculateSmoothNormals. A <CalculateNormalsModifier> that generates hard or smooth vertex normals. Also used to generate
tangent-space normals if the mesh has the necessary vertex attributes.
Execute Workload
Drawing and workload execution is specified in the Execute Workload section. In this example, you can see a <NodeLink> to a <Mesh>
node. This causes the <Mesh> to be rendered, which renders the <Mesh> object's <Material> nodes. This in turn invokes rendering of
the <Program>, the <SamplerNode> objects and so forth.
Options are:
-
Execute Workload. This is a <GraphicsFeatureNode> that will only render if the host GPU supports the specified GLSL version and
any OpenGL® extensions that may have been specified. You can right click on this node to set the GLSL version and add extensions that are
required to execute the workload.