s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationRenderingShadersClassesMotion
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/Rendering
Rendering

Motion

The Motion class provides functions for calculating motion vectors, reprojection, and performing temporal filtering in HLSL shaders. It is useful for implementing effects like Temporal Anti-Aliasing (TAA), motion blur or general reprojection by blending current and previous frame data.

⚠️ Right now this is limited to camera motion only, moving objects currently do not react to their own motion.

float3 Motion::GetFromWorldPosition(float3 worldPosition)

  • Reprojects a world-space position to screen-space ( Depth in Z ) coordinates using the last frame's depth buffer.

float3 Motion::Get(float2 screenPosition)

  • Returns the position in clip space ( Pixel Position + Depth in Z ) of where this pixel was projected on the previous frame.

float4 Motion::TemporalFilter( uint2 vPositionSs, Texture2D tCurrent, Texture2D tPrev, float flBlendWeight = 0.9f )

  • A traditional Temporal Anti-Aliasing filter, takes the position of the current pixel and the texture of the current frame, and previous frame and using the motion vectors to blend them.
  • It works as follows:
    • Calculate Previous Frame UV Coordinates:
      • Uses motion vectors to find where the current pixel was in the previous frame.
      • Converts screen-space position to UV coordinates for texture sampling.
    • Compute Min and Max Sample Values:
      • Iterates over a 3x3 pixel neighborhood around the current pixel.
      • Finds the minimum and maximum color values to clamp the previous frame's sample.
    • Sample Previous Frame Texture:
      • Samples the previous frame's texture at the calculated UV coordinates using bilinear filtering.
    • Clamp Previous Frame Sample:
      • Ensures the previous frame's data does not introduce artifacts when blending using a bounding box of colors.
    • Blend Samples:
      • Blends the current frame's sample with the clamped previous frame's sample based on the blend weight.

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2024-12-09. Read it rendered on the official docs.

More in Rendering

AmbientLight
Animated Effects
Attributes and Variables
BeamEffect
Beams
Bindless API
C# Shader Nodes
Classes
← All documentation

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.