Source Shader Editor - Node types

From Valve Developer Community
Jump to: navigation, search

This article will provide an overview of nodes that are specific to the shader editor. For a general reference of HLSL arithmetics refer to microsofts official documentation [1]. You can also hover with your mouse pointer over nodes to show a tooltip about their functionality ingame, the same text is available on the 'General' tab in the nodes properties.

Semantics

VS Input

Provides the input data for the vertex shader. Use the node properties dialog to define which semantics should be available. The shader implementation will only request the respective data from the mesh if you actually connect the output jacks with anything. Trying to read something that is not actually provided by the mesh will result in errors when rendering with that shader.

VS Output and PS Input

These nodes are dependent from one another. The data you provide for VS Output node will be linearly interpolated and accessible from the PS Input node. Use the properties dialog of either node to define the datatype per jack and set a custom name if you like for easier readability. If you want to use datatypes that require multiple rows, make sure that you enabled them via the sliders at the top first, otherwise they won't be accessible.

PS Output

The final pixel color of your shader will be sent to this node. You will usually only write to the semantic Color 0, the other three color semantics can allow you to write data to MRTs. The depth output semantic can be used to manipulate the z position (in post-projection space) on pixel shader level, its default is projpos.z/projpos.w.

Math

Invert

Inverts an unsigned, normalized value: 1.0 - input.

Append (Vectors)

Combines two inputs into one. The output can not exceed a four component vector.

Swizzle (Vectors)

Uses arbitrary swizzling on a vector. You can also swizzle with constants and change the vector dimensions as you see fit. Use the properties dialog to define the swizzle operation, supports token channels.

Matrices

ModelViewProj

The model view projection matrix will instantly transform your mesh into projection space, this is the fastest way to project a vertex into the scene.

Model

Transforms a vector from object to world space. Use this operation if you want a straight world transform and read the world position for usage elsewhere.

ViewProj

Transforms a vector from world into projection space. You will usually multiply with this matrix after transforming into world space.

ViewModel

View matrix inverse.
Blank image.pngTodo: Confirm.

Matrix compose

Build a matrix from input vectors.

Textures

Texture sample

Samples color from a texture. You can define a custom name for a parameter to use in the vmt or choose from existing ones.
  • The demo texture you can load will be used for the in-editor previews, not when previewing shaders in the scene or using the shader in a vmt.
  • The fallback texture will be used when the actual material parameter is undefined, this counts for previewing shaders in the scene and actual finalized shaders referenced by vmts.
  • Choosing auto select as lookup mode will either require you to pass a two component vector for UVs or a three component vector for a cubemap dependent from the parameter type and the demo texture you specified. Change the lookup function as you see fit.

Texture transform

Transforms UVs by a matrix. This node is rather expensive and should be used sparingly. Supports the following matrix operations: Scale, translation, rotation. Use its properties dialog to hide the operations that you won't need. You can specifiy a custom center if you want, the default center is at "0.5 0.5".

Sampler object

Creates a new sampler variable in the shader and links a texture to it just like the node Texture sample.

Parallax UV

Calculates new UVs based on a heightmap. Parallax occlusion and relief mapping are supported. The amount of samples can be defined in the node properties.
  • Enabling the world space offset will allow you to override the depth value in post projection space and also update the general world pos for correct parallax'd fog or flashlight calculations.
  • The gradient lookup will be more expensive but yields better results. It's also necessary if you want to vary the amount of samples for the linear search.
The POM technique will solely work on flat geoemtry, while Relief mapping offers limited support for displacements. Make sure that your textures on the displacement are not stretched to achieve good results.

Parallax shadow

Darkens the parallax'd texture based on a fast self occlusion approximation. This node does not utilize a ray intersection technique and therefore provides only rough results.

Constants

Local constants

Define a local value with up to four components. Supports token channels.

Callback constant

Access a callback value defined by the client library.

VParam static

Read from a custom material parameter. Supports token channels for the default values.

VParam mutable

Read from a dynamic material parameter.

Random float

Access a random value with up to four components from the shader implementation library. You can define the amount of components and the min/max value in the node properties.

Array

Supports 1D or 2D arrays of arbitrary size. You can autofill the whole array with gaussian weights or random values.

View data

Access data of the current view setup.

Time

Time in seconds, unaffected by host_timecale.

FB texelsize

Returns 1.0 / backbuffersize for width and height. Useful when mapping textures onto the screen or using uv offsets that are supposed to be a multiple of the texel size.

Fog params

Current fog data.

Lightscale

Scalar to adjust shader luminosity for HDR compatibility.

Bump basis

Necessary when using normalmaps on brushes.

Flashlight pos

The flashlight position. Only valid during the flashlight pass.

Control flow

Refer to [*] for a detailed explanation on how to correctly implement these nodes.

Loop

Iterate the child nodes of the Loop node a given amount of times.

Shader combo

Execute or ignore the contained nodes depending on whether a combo fullfills the given requirements.

Condition

The children of this node will only be executed when the input conditions evalutes to true.

Utility

Declare

Re-declare a variable in the current scope.

Assign

Write the value of the second input into the variable of the first one. Doesn't solve if the variable of input one is read-only.

Pixel fog

Computes the fog factor.

Final output

Blends with fog, writes depth to the alpha channel and scales the color by a lighting scale.

Flashlight

Projects the flashlight onto your geometry. This is meant to replace diffuse (and specular) lighting for the flashlight pass.

Custom code

Allows you to enter custom HLSL into the graph. You can create arbitrary inputs and outputs for the node and handle these inside your custom function. Furthermore it's possible to include headers and create global function/constants which can be referenced from other nodes of this type inside their functions too. Code can either be saved inside the graph file itself or in an external file, which you can include in other graphs.

Utility / Studio model

Vertex lighting

Calculates either the per vertex attenuation for each dynamic light or does the whole lighting calculation per vertex.

Pixelshader lighting

Generates the diffuse lighting per pixel.

Pixelshader specular

Calculates the specular lighting per pixel.

Skinning

A necessarity for (animated) models. Transforms each vertex based on bone weights and replaces the object to world transformation.

Morph

Applies the morphing deltas in object space, used for vertex animations.

Vertex decompress

Performs decompression of normal and tangent data if the geometry that is being used provides a compressed vertex format. A necessity for Swarm model shaders.