Home Guides Shader Graph checklist

Shader Graph in s&box: a compile checklist

Updated

A checklist for when a Shader Graph does not compile or the material looks wrong. General practice, not Facepunch documentation.

How the three files fit together

s&box runs on the Source 2 rendering pipeline, which separates shader logic from surface textures across three distinct asset types: the visual node graph (.shdrgrph), the compiled shader program (.vfx), and the material instance (.vmat) applied to Hammer world meshes and ModelDoc props.

When you save a .shdrgrph file in the Shader Graph editor, the engine generates HLSL code and compiles the vertex and pixel stages into a .vfx binary. Material artists then create lightweight .vmat files that point to your shader and override exposed texture slots and scalar sliders without recompiling the underlying shader.

This is a working checklist from general practice, not a Facepunch reference. Node names and options change between versions; check the Facepunch documentation for yours.

Before you build

Decide the shader domain and the blend mode before you place nodes. Changing an opaque world surface into a translucent post-process shader later changes which output pins and depth-buffer states exist.

Decide these first:

  • Shader domain: Surface (world geometry and props), PostProcess (full-screen camera pass), or Blendable (multi-layer Hammer terrain blending).
  • Blend mode: Opaque (fastest, full early-Z depth rejection), Masked / Alpha Test (foliage and chain-link fences), or Translucent (glass, water, holograms—requires depth sorting care).
  • Color spaces: Albedo / Color maps sample in sRGB; Roughness, Metalness, Ambient Occlusion, and Height masks must sample in Linear space; Normal maps use Source 2 tangent-space encoding.
  • Attribute reuse: design one master .shdrgrph per surface family (for example, triplanar world rock or animated neon trim) and drive variations through .vmat parameters.

Expose material attributes

Hardcoding texture paths or scalar constants inside the graph forces you to duplicate the entire shader for every color variation. Instead, mark Texture2D, Float, Vector2, and Color input nodes as exposed Material Attributes with sensible default values and UI ranges (UiGroup, Default, Range).

// Conceptual HLSL output generated from exposed Shader Graph nodes:
CreateInputTexture2D( TextureAlbedo, Srgb, 8, "", "_color", "Surface,10/10", Default3( 1.0, 1.0, 1.0 ) );
CreateInputTexture2D( TextureNormal, Linear, 8, "NormalizeNormals", "_normal", "Surface,10/20", Default3( 0.5, 0.5, 1.0 ) );
CreateInputTexture2D( TextureRoughness, Linear, 8, "", "_rough", "Surface,10/30", Default( 0.5 ) );

float flRoughnessScale < UiType( Slider ); Range( 0.04, 1.0 ); Default( 0.65 ); UiGroup( "Surface,10/40" ); >;
float2 vUvTiling < UiType( VectorText ); Default2( 1.0, 1.0 ); UiGroup( "UV Projection,20/10" ); >;

Compilation checklist

Work down this list in order whenever the Shader Graph editor highlights a broken wire, fails to emit the .vfx binary, or renders the magenta-and-black error checkerboard in the viewport.

  • Every required input of the master Result / Output node is connected, or carries a valid finite default value.
  • Vector dimensions match at every wire connection: a float3/float4 color cannot feed a scalar float1 input without an explicit Swizzle or Split node, and a Texture2D object must pass through a Texture Sample node before math operations.
  • Zero graph cycles: no node chain may loop back into one of its own upstream inputs.
  • Every Texture2D default points to a real texture file inside your project assets folder with exact case-sensitive path spelling (important for Linux dedicated server builds and Workshop packaging).
  • Exposed parameter names are globally unique within the graph; two nodes with the same attribute identifier collide during HLSL code generation.
  • Vertex-stage and pixel-stage operations stay in their legal stage: screen-space derivatives (ddx/ddy) and standard mipmapped texture sampling require the pixel stage, while VertexOffset requires vertex-compatible inputs.
  • Division and normalization are guarded: wrap denominators in max(value, 0.0001) and never normalize a zero-length vector (which produces NaN pixels that bloom into black boxes across the screen).
  • Save the .shdrgrph file and wait for the background shader compiler to report 0 errors before judging the viewport—a failed compile leaves the previous working .vfx binary in memory.

Check it under different lighting

A shader that looks fine under one flat directional light often breaks in dark rooms, under bright skyboxes or in reflection cubemaps. Test every new shader in a scene with a smooth sphere and a flat wall.

What to check in that scene:

  • Roughness floor: keep minimum roughness at or above 0.04 so specular highlights do not alias into single-pixel fireflies.
  • Albedo luminance range: keep dielectric base colors within physically plausible sRGB values (roughly 30 to 240 sRGB) so dynamic lights and Light Modulators do not blow out detail.
  • Distance and grazing angles: inspect the surface from 20 centimeters and 50 meters to check mipmap transitions, anisotropic filtering, and normal-map shimmer.
  • Parameter extremes: drag every exposed slider in the .vmat inspector to 0.0 and 1.0 to confirm no division-by-zero or negative-square-root artifacts appear.
  • GPU profiler pass: open the F11 Performance Hub (perf_hub) on a scene containing 100 instances of the material and verify that GPU frame time remains flat.

Before you publish

Before publishing a map or game package to the Workshop, test the compiled materials on a secondary machine with clean cache directories and medium graphics presets. Commit the .shdrgrph source files, the .vmat definitions and the raw source textures to Git, so anyone working on the project can rebuild the package.

Quick reference

SettingValue
Shader Graph file.shdrgrph node graph, compiles to .vfx
Material file.vmat material that points to the compiled shader
PBR channelsAlbedo, Roughness, Metalness, Tangent Normal, Ambient Occlusion
Live changesSaving the graph hot-reloads it in the s&box Editor

Unofficial and general. The s&box API changes between versions; check the Facepunch documentation before you copy code.