Shader Designer

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Shader Designer.

This document describes how to work with the Visual Studio Shader Designer to create, modify, and export custom visual effects that are known as shaders.

You can use the Shader Designer to create custom visual effects for your game or app even if you don't know HLSL programming. To create a shader in the Shader Designer, you just lay it out as a graph; that is, you add to the design surface nodes that represent data and operations and then make connections between them to define how the operations process the data. At each operation node, a preview of the effect up to that point is provided so that you can visualize its result. Data flows through the nodes toward a final node that represents the output of the shader.

The Shader Designer supports these shader formats:

Format NameFile ExtensionSupported Operations (View, Edit, Export)
Directed Graph Shader Language.dgslView, Edit
HLSL Shader (source code).hlslExport
HLSL Shader (bytecode).csoExport
C++ header (HLSL bytecode array).hExport

This section describes how to add a DGSL shader to your Visual Studio project and provides basic information to help you get started.

To add a DGSL shader to your project

  1. In Solution Explorer, open the shortcut menu for the project that you want to add the shader to, and then choose Add, New Item.

  2. In the Add New Item dialog box, under Installed, select Graphics, and then select Visual Shader Graph (.dgsl).

  3. Specify the Name of the shader file, and the Location where you want it to be created.

  4. Choose the Add button.

The default shader

Each time that you create a DGSL shader, it begins as a minimal shader that has just a Point Color node that's connected to the Final Color node. Although this shader is complete and functional, it doesn't do much. Therefore, the first step in creating a working shader is often to delete the Point Color node or disconnect it from the Final Color node to make room for other nodes.

The following sections describe how to use the Shader Designer to work with custom shaders.

Shader Designer toolbars

The Shader Designer toolbars contain commands that help you work with DGSL shader graphs.

Commands that affect the state of the Shader Designer are located on the Shader Designer Mode toolbar in the main Visual Studio window. Design tools and commands are located on the Shader Designer toolbar on the Shader Designer design surface.

Here's the Shader Designer Mode toolbar:

The Shader Designer modal toolbar.

This table describes the items on the Shader Designer Mode toolbar, which are listed in the order in which they appear from left to right:

Toolbar ItemDescription
SelectEnables interaction with nodes and edges in the graph. In this mode, you can select nodes and move or delete them, and you can establish edges or break them.
PanEnables movement of a shader graph relative to the window frame. To pan, select a point on the design surface and move it around.

In Select mode, you can press and hold Ctrl to activate Pan mode temporarily.
ZoomEnables the display of more or less shader-graph detail relative to the window frame. In Zoom mode, select a point on the design surface and then move it right or down to zoom in, or left or up to zoom out.

In Select mode, you can press and hold Ctrl to zoom in or out by using the mouse wheel.
Zoom to FitDisplays the full shader graph in the window frame.
Real-Time Rendering ModeWhen real-time rendering is enabled, Visual Studio redraws the design surface, even when no user action is performed. This mode is useful when you work with shaders that change over time.
Preview with sphereWhen enabled, a model of a sphere is used to preview the shader. Only one preview shape at a time can be enabled.
Preview with cubeWhen enabled, a model of a cube is used to preview the shader. Only one preview shape at a time can be enabled.
Preview with CylinderWhen enabled, a model of a cylinder is used to preview the shader. Only one preview shape at a time can be enabled.
Preview with coneWhen enabled, a model of a cone is used to preview the shader. Only one preview shape at a time can be enabled.
Preview with teapotWhen enabled, a model of a teapot is used to preview the shader. Only one preview shape at a time can be enabled.
Preview with planeWhen enabled, a model of a plane is used to preview the shader. Only one preview shape at a time can be enabled.
ToolboxAlternately shows or hides the Toolbox.
PropertiesAlternatively shows or hides the Properties window.
AdvancedContains advanced commands and options.

 Export: Enables the export of a shader in several formats.

 Export As: Exports the shader as either HLSL source code or as compiled shader bytecode. For more information about how to export shaders, see How to: Export a Shader.

 Graphics Engines: Enables the selection of the renderer that is used to display the design surface.

 Render with D3D11: Uses Direct3D 11 to render the Shader Designer design surface.

 Render with D3D11WARP: Uses Direct3D 11 Windows Advanced Rasterization Platform (WARP) to render the Shader Designer design surface.

 View: Enables the selection of additional information about the Shader Designer.

 Frame Rate: When enabled, displays the current frame rate in the upper-right corner of the design surface. The frame rate is the number of frames that are drawn per second. This option is useful when you enable the Real-Time Rendering Mode option.
System_CAPS_ICON_tip.jpg Tip

You can choose the Advanced button to run the last command again.

Working with nodes and connections

Use Select mode to add, remove, reposition, connect, and configure nodes. Here's how to perform these basic operations:

To perform basic operations in Select mode
  • Here's how:

    • To add a node to the graph, select it in the Toolbox and then move it to the design surface.

    • To remove a node from the graph, select it and then press Delete.

    • To reposition a node, select it and then move it to a new location.

    • To connect two nodes, move an output terminal of one node to an input terminal of the other node. Only terminals that have compatible types can be connected. A line between the terminals shows the connection.

    • To remove a connection, on the shortcut menu for either one of the connected terminals, choose Break Links.

    • To configure the properties of a node, select the node, and then, in the Properties window, specify new values for the properties.

Previewing shaders

To help you understand how a shader will appear in your app, you can configure how your effect is previewed. To approximate your app, you can choose one of several shapes to render, configure textures and other material parameters, enable animation of time-based effects, and examine the preview from different angles.

Shapes

The Shader Designer includes six shapes—a sphere, a cube, a cylinder, a cone, a teapot, and a plane—that you can use to preview your shader. Depending on the shader, certain shapes might give you a better preview.

To choose a preview shape
  • On the Shader Designer Modes toolbar, choose the shape that you want.

Textures and material parameters

Many shaders rely on textures and material properties to produce a unique appearance for each kind of object in your app. To see what your shader will look like in your app, you can set the textures and material properties that are used to render the preview to match the textures and parameters that you might use in your app.

To bind a different texture to a texture register, or to modify other material parameters
  1. In Select mode, select an empty area of the design surface. This causes the Properties window to display the global shader properties.

  2. In the Properties window, specify new values for the texture and parameter properties that you want to change.

Here are the shader parameters that you can modify:

ParameterProperties
Texture 1Texture 8Access: Public to allow the property to be set from the Model Editor; otherwise, Private.

 Filename: The full path of the texture file that is associated with this texture register.
Material AmbientAccess: Public to allow the property to be set from the Model Editor; otherwise, Private.

 Value: The diffuse color of the current pixel due to indirect – or ambient – lighting.
Material DiffuseAccess: Public to allow the property to be set from the Model Editor; otherwise, Private.

 Value: A color that describes how the current pixel diffuses direct lighting.
Material EmissiveAccess: Public to allow the property to be set from the Model Editor; otherwise, Private.

 Value: The color contribution of the current pixel due to self-provided lighting.
Material SpecularAccess: Public to allow the property to be set from the Model Editor; otherwise, Private.

 Value: A color that describes how the current pixel reflects direct lighting.
Material Specular PowerAccess: Public to allow the property to be set from the Model Editor; otherwise, Private.

 Value: The exponent that defines the intensity of specular highlights on the current pixel.

Time-based effects

Some shaders have a time-based component that animates the effect. To show what the effect looks like in action, the preview has to be updated several times per second. By default, the preview is only updated when the shader is changed; to change this behavior so that you can view time-based effects, you have to enable real-time rendering.

To enable real-time rendering
  • On the Shader Designer toolbar, choose Real time Rendering.

Examining the effect

Many shaders are affected by variables such as viewing angle or directional lighting. To examine how the effect responds as these variables change, you can rotate the preview shape freely and observe how the shader behaves.

To rotate the shape
  • Press and hold Alt, and then select any point on the design surface and move it.

Exporting shaders

Before you can use a shader in your app, you have to export it in a format that DirectX understands.

You can export shaders as HLSL source code or as compiled shader bytecode. HLSL source code is exported to a text file that has an .hlsl file name extension. Shader bytecode can be exported either to a raw binary file that has a .cso file name extension, or to a C++ header (.h) file that encodes the shader bytecode into an array.

For more information about how to export shaders, see How to: Export a Shader.

CommandKeyboard shortcuts
Switch to Select modeCtrl+G, Gtrl+Q

S
Switch to Zoom modeCtrl+G, Ctrl+Z

Z
Switch to Pan modeCtrl+G, Ctrl+P

K
Select allCtrl+A
Delete the current selectionDelete
Cancel the current selectionEscape
Zoom inCtrl+Mouse wheel forward

Plus Sign (+)
Zoom outCtrl-Mouse wheel backward

Minus Sign (-)
Pan the design surface upMouse wheel backward

PageDown
Pan the design surface downMouse wheel forward

PageUp
Pan the design surface leftShift+Mouse wheel backward

Mouse wheel left

Shift+PageDown
Pan the design surface rightShift+Mouse wheel forward

Mouse wheel right

Shift+PageUp
Move the keyboard focus to another nodeThe Arrow keys
Select the node that has keyboard focus (adds the node to the selection group)Shift+Spacebar
Toggle selection of the node that has keyboard focusCtrl+Spacebar
Toggle current selection (if no nodes are selected, select the node that has keyboard focus)Spacebar
Move the current selection upShift+Up Arrow
Move the current selection downShift+Down Arrow
Move the current selection leftShift+Left Arrow
Move current selection rightShift+Right Arrow.
TitleDescription
Working with 3-D Assets for Games and AppsProvides an overview of the Visual Studio tools that you can use to work with textures and images, 3-D models, and shader effects.
Image EditorDescribes how to use the Visual Studio Image Editor to work with textures and images.
Model EditorDescribes how to use the Visual Studio Model Editor to work with 3-D models.
Show: