Since version 2.5 of the Video SDK, you can apply a custom video transformation with an HLSL pixel shader. The functionality is provided by the MFShader plugin.
The plugin requires GPU pipeline mode. Enable it before creating the SDK objects that will process frames:
var factory = new MFFactoryClass();
factory.PropsSet("gpu_pipeline", "true");The shader must be an HLSL pixel shader with PS as the entry point. The shader source is assigned with the shader property:
m_objShader.PropsSet("shader", shaderString);To check whether the shader was compiled and initialized, read shader_state:
m_objShader.PropsGet("shader_state", out string state);Possible states are:
- not_inited
- failed
- inited
- failed_to_render
If the shader is not valid, the plugin returns an error state. The plugin is not a shader debugger, so validate syntax separately with a Direct3D/HLSL tool such as https://www.shadertoy.com/ or with D3DCompile. Shadertoy can be useful for ideas, but its examples are GLSL and must be converted to HLSL manually.
Shader initialization can cause a short one-time drop because the shader is compiled. Depending on the system, this usually takes around 10-30 ms.
MFormats Usage
In MFormats, process an MFFrame directly with IMFProcess.ProcessFrame. Optional UI parameters can be passed as frame side data named shader_data.
byte[] shaderData = BuildConstantBuffer();
IntPtr dataPtr = Marshal.AllocHGlobal(shaderData.Length);
try
{
Marshal.Copy(shaderData, 0, dataPtr, shaderData.Length);
frame.MFDataSet("shader_data", shaderData.Length, dataPtr.ToInt64());
MFFrame processedFrame;
int framesRest;
((IMFProcess)m_objShader).ProcessFrame(frame, out processedFrame, out framesRest, "");
}
finally
{
Marshal.FreeHGlobal(dataPtr);
}MPlatform Usage
In MPlatform, add MFShader to the object graph like other plugins. For a file source, the graph can be:
var source = new MFileClass();
var preview = new MPreviewClass();
var shader = new MFShaderClass();
shader.PropsSet("shader", shaderString);
source.PluginsAdd(shader, 0);
preview.ObjectStart(source);
preview.PreviewWindowSet("", previewPanel.Handle.ToInt64());
preview.PreviewEnable("", 1, 1);If the shader uses tunable constants, add a lightweight plugin before MFShader that writes the current constant buffer to each frame as shader_data, then add MFShader after it:
source.PluginsAdd(shaderDataPlugin, 0);
source.PluginsAdd(shader, 0);The WPF MPlatform sample included with this article uses this pattern: MFile -> ShaderDataPlugin -> MFShader -> MPreview/MRenderer.
Shader Parameters
A common approach is to declare a constant buffer in HLSL and pack UI values into float4 slots:
cbuffer ShaderParams : register(b0)
{
float4 p0;
float4 p1;
};
float4 PS(PS_INPUT input) : SV_Target
{
float amount = p0.x;
return inputTexture.Sample(inputSampler, input.Tex) * amount;
}The sample shader library stores each effect in a separate *.shader.json file next to its HLSL file. The JSON describes the effect, its category, and the UI controls that map to constant-buffer slots.
Shader Library Overview
The expanded WPF samples include a reusable shaders folder with 62 JSON/HLSL effects. Each shader can be loaded by the sample, applied to the video, and tuned from the UI without changing the application code.
The library covers common broadcast and streaming workflows such as color correction, keying, scaling, deinterlacing, overlays, crop/aspect work, monitoring aids, denoise/repair, HDR/SDR tone mapping, and stylized effects. The complete catalog below lists every included shader and its live controls.
Complete Shader Catalog
The shaders folder contains one JSON/HLSL pair for each effect below. The JSON file stores the shader name, category, description, HLSL file name, and the UI parameters that the samples expose for live tuning.
Preview GIFs are small documentation previews generated from synthetic source material. They show the intended visual direction of each effect; exact output depends on the source video, GPU pipeline, shader parameters, and host graph.
| Preview | Shader | Category | Purpose | Live controls |
|---|---|---|---|---|
|
|
Analog Signal Interference | Retro / Analog | Smooth RF-style wave distortion, line noise, desaturation, and color drift. | Wave Displacement, Line Noise, Speed, Desaturation |
|
|
Anamorphic De-Squeeze Preview | Camera Assist | Preview horizontal de-squeeze for anamorphic camera feeds with optional crop dimming. | Squeeze Factor, Zoom, Outside Dim |
|
|
Banding Reducer / Fine Dither | Video Repair | Adds subtle animated grain and micro-dither to reduce visible gradients and banding. | Strength, Animate, Luma Only |
|
|
Bilateral Denoise | Production Core | Edge-preserving spatial denoise for noisy camera feeds, compressed sources, and low-light material. | Strength, Range Sigma, Spatial Sigma, Radius, Detail Restore |
|
|
Bloom / Glow | Finishing | Highlight bloom for glamour camera looks, neon overlays, and bright UI/game sources. | Threshold, Intensity, Radius, Saturation |
|
|
Box Blur | Blur / Detail | Single-pass blur useful for background softening and quick privacy masks. | Radius, Mix |
|
|
Broadcast Safe Limiter | QC / Compliance | Softly clamps RGB and luma toward common video-safe levels for fast confidence checks. | Black Level, White Level, Softness, Mix |
|
|
Cartoon / Cel Shade | Stylize | Posterized lighting with dark edge lines for comic and toon looks. | Tone Levels, Edge Strength, Edge Threshold, Saturation |
|
|
Channel Inspector | QC / Monitoring | Diagnostic channel viewer for red, green, blue, alpha, luma, or saturation. | Mode, False Color |
|
|
Chroma Bleed Reducer | Video Repair | Reduces horizontal chroma bleed by smoothing color difference while preserving luma detail. | Radius, Amount |
|
|
Chroma Key Matte Preview | Keying / QC | Visualizes a green-screen key matte and optional spill suppression for setup checks. | Key Red, Key Green, Key Blue, Threshold, Softness, Spill Suppress, Matte View |
|
|
Clipping Warning | QC / Monitoring | Flashes underexposed and clipped highlights for fast signal checks. | Black Clip, White Clip, Opacity, Flash |
|
|
Color Bars / Ramp Generator | Delivery Looks | Generates SMPTE-like color bars and grayscale ramp over the current frame for output path checks. | Mix, Show Ramp |
|
|
Color Corrector | Camera / Program | Primary color controls for quick camera matching, playback normalization, and program feed trims. | Exposure, Contrast, Saturation, Gamma, Lift, Gain |
|
|
Color Space / Range Converter | Production Core | RGB matrix and legal/full range conversion for Rec.601, Rec.709, and Rec.2020 style program normalization. | Input Standard, Output Standard, Input Range, Output Range, Clamp Output, Mix |
|
|
Crop / Aspect Guides | Graphics / Layout | Shows common social and broadcast crop guides: 16:9, 9:16, 1:1, 4:5, or custom aspect. | Target Aspect, Line Width, Outside Dim, Line Opacity |
|
|
Crop / Pad / Aspect Transform | Production Core | Actual crop, scale-to-aspect, and padding transform for fitting source pictures into delivery frames. | Crop Left, Crop Right, Crop Top, Crop Bottom, Target Aspect, Zoom, Pad Opacity, Show Bounds, Pad Red, Pad Green, Pad Blue |
|
|
CRT Monitor | Retro / Analog | CRT-style curvature, scanlines, phosphor mask, vignette, and mild highlight bloom. | Curvature, Scanlines, Phosphor Mask, Vignette, Glow |
|
|
Deinterlace Line Blend | Video Repair | Simple line-blend deinterlace preview for interlaced or combed source material. | Blend, Field Parity, Show Processed Lines |
|
|
Digital Glitch | Retro / Analog | Block displacement, RGB drift, and random corruption inspired by OBS glitch filters. | Amount, Block Height, Speed, Color Drift |
|
|
Directional Blur | Blur / Detail | Linear motion-style blur in any direction. | Distance, Angle, Mix |
|
|
Drop Shadow | Graphics / Layout | Offset dark shadow based on alpha or luma. Works best on keyed/graphic sources, but can stylize full-frame video too. | Offset X, Offset Y, Softness, Opacity |
|
|
Dual Zebra Exposure | Camera Assist | Two zebra overlays for skin/gray reference and highlight clipping at the same time. | Low Threshold, High Threshold, Opacity, Stripe Size |
|
|
Duotone | Stylize | Maps luma between two colors for branded or editorial looks. | Shadow Red, Shadow Green, Shadow Blue, Highlight Red, Highlight Green, Highlight Blue, Mix |
|
|
Edge-Adaptive Deinterlace | Production Core | Directional interpolation deinterlace for combed/interlaced sources, preserving edges better than line blend. | Strength, Field Parity, Edge Bias, Show Processed Lines |
|
|
Edge Outline / Stroke | Graphics / Layout | Creates an outline from alpha or image edges; useful for keyed people, overlays, and stylized video. | Edge Threshold, Width, Red, Green, Blue, Opacity |
|
|
External Overlay Composite | Production Core | Generic second-texture overlay compositor for pipelines that bind an overlay source to texture register t1. | Opacity, Blend Mode, Black Key, Key Softness, Center X, Center Y, Scale X, Scale Y |
|
|
False Color Exposure | Camera Assist | Maps luma to false-color exposure bands for fast broadcast/camera checks. | Black Clip, Gray Point, White Clip, Mix |
|
|
Focus Peaking | Camera Assist | Highlights high-frequency detail for focus checks on camera feeds. | Threshold, Intensity, Width, Mono Preview |
|
|
Halftone | Stylize | Comic-print dot screen driven by image luminance. | Cell Size, Contrast, Color Mode |
|
|
HDR-to-SDR Tone Map Preview | Delivery Looks | Simple tone-map preview for high dynamic range or overbright sources displayed in SDR. | Exposure, Shoulder, Saturation, Mix |
|
|
Hot Pixel Suppressor | Video Repair | Suppresses isolated bright or dark pixels using a local neighborhood median approximation. | Threshold, Amount |
|
|
Improved Chroma Keyer | Keying / QC | Green/blue keyer with similarity, smoothness, edge soften, despill, and matte preview. | Key Red, Key Green, Key Blue, Similarity, Smoothness, Despill, Edge Soften, Matte View |
|
|
Lanczos Scale Preview | Production Core | High-quality resampling preview for scale/crop decisions using a tunable Lanczos-style filter. | Scale X, Scale Y, Center X, Center Y, Filter Lobes, Compare Split, Show Bounds, Mix |
|
|
Lens Distortion | Creative / Utility | A tunable barrel or pincushion warp based on the original custom shader sample idea. | Power, Zoom, Center X, Center Y |
|
|
Letterbox / Pillarbox Matte | Graphics / Layout | Adds clean aspect-ratio mattes for framing checks, previews, or program-style outputs. | Target Aspect, Opacity, Feather, Matte Red, Matte Green, Matte Blue |
|
|
Lower-Third Spotlight | Streaming Production | Dims the background while preserving a configurable lower-third or title area. | Top, Bottom, Dim Amount, Feather |
|
|
Luma Waveform Overlay | QC / Monitoring | Approximate luma waveform overlay for quick exposure distribution checks. | Overlay Height, Opacity, Sample Density, Background Dim |
|
|
Luminance Key | Keying / QC | Creates alpha from brightness for overlays, light leaks, footage masks, and source compositing workflows. | Low Cut, High Cut, Invert, Matte View |
|
|
LUT-Style Color Grade | Camera / Program | Single-shader film grade inspired by OBS color/LUT workflows: contrast curve, teal-orange balance, fade, and grain. | Contrast, Teal / Orange, Fade, Grain |
|
|
Median Despeckle | Production Core | Median-style spot cleanup for salt-and-pepper noise, sensor speckles, and isolated compression hits. | Threshold, Mix, Always Filter, Show Mask |
|
|
Ordered Dither | Stylize | Bayer-style ordered dithering for retro computer, newspaper, and banding-control looks. | Levels, Strength, Monochrome |
|
|
Pixelate / Mosaic | Blur / Detail | Fast square mosaic pixelation for privacy, stylized transitions, or low-res looks. | Block Size, Mix |
|
|
Posterize | Stylize | Reduces color levels for poster, comic, and low-bandwidth looks. | Levels, Gamma, Mix |
|
|
Privacy Region Mosaic | Streaming Production | Pixelates a configurable rectangular region for privacy, passwords, scoreboards, or sensitive feeds. | Center X, Center Y, Width, Height, Block Size, Feather |
|
|
RGB Parade Overlay | QC / Monitoring | Approximate RGB parade overlay for channel balance and clipping checks. | Overlay Height, Opacity, Sample Density, Background Dim |
|
|
RGB Split / Chromatic Aberration | Optics | Manual or radial channel separation for lens errors, impact hits, and glitch looks. | Amount, Radial, Angle |
|
|
Rounded Corners / Mask | Graphics / Layout | Rounds frame corners with optional border and background fill. | Radius, Feather, Border Width, Border Opacity |
|
|
Rule of Thirds / Center Cross | Camera Assist | Composition overlay with rule-of-thirds grid, center cross, and optional horizon line. | Grid Opacity, Center Opacity, Line Width, Horizon Line |
|
|
Safe Area Guides | Graphics / Layout | Draws action-safe and title-safe overlays for graphics placement and playout checks. | Action Safe, Title Safe, Line Width, Outside Dim, Line Opacity |
|
|
Safe Gamut Warning | QC / Monitoring | Highlights RGB/luma values outside configurable legal broadcast bounds. | Low Limit, High Limit, Opacity, Show Legal Only |
|
|
Scanlines | Retro / Analog | Animated horizontal scanlines with tunable period, speed, and brightness floor. | Period, Intensity, Speed, Brightness Floor |
|
|
Selective Color | Camera / Program | Keeps a chosen hue in color while desaturating the rest, or boosts only the selected hue. | Target Hue, Hue Width, Outside Saturation, Inside Boost |
|
|
Sharpen / Detail | Finishing | A lightweight unsharp mask for soft feeds, archive material, and confidence previews. | Amount, Radius, Highlight Protect, Mix |
|
|
Skin Tone Assist | Camera Assist | Highlights likely skin-tone hue/luma regions for camera matching and quick white-balance checks. | Target Hue, Hue Width, Opacity, Dim Others |
|
|
Thermal / Night Vision | Stylize | Switchable thermal palette and green night-vision look with animated noise. | Thermal Mode, Gain, Noise, Vignette |
|
|
Vectorscope Overlay | QC / Monitoring | Approximate vectorscope overlay for hue/saturation distribution checks. | Scope Size, Opacity, Sample Grid, Background Dim |
|
|
VHS / Bad TV | Retro / Analog | Tape jitter, chroma offset, head-switching noise, scanline shimmer, and desaturation. | Frame Jitter, Chroma Shift, Noise, Head Switch, Desaturate |
|
|
Vignette Focus | Creative | Subtle edge falloff for interviews, studio inserts, and screen content that needs center emphasis. | Strength, Radius, Softness, Center Lift |
|
|
White Balance Trim | Camera / Program | Temperature and tint correction for matching camera feeds or fixing mixed lighting in playback. | Temperature, Tint, Vibrance, Preserve Luma |
|
|
Zebra Exposure | Camera Assist | Overlays diagonal highlight stripes above a luma threshold for exposure checks. | Threshold, Stripe Size, Opacity, Rolloff |
|
|
Zoom Blur | Blur / Detail | Radial zoom blur for impact effects, transitions, and stylized highlights. | Strength, Center X, Center Y, Mix |
Some shaders are diagnostic or preview-oriented. For example, the waveform, RGB parade, and vectorscope shaders are useful for visual checks in the sample, but they are not a replacement for engineering-grade measurement scopes. The External Overlay Composite shader expects an additional overlay texture bound to t1; the sample UI loads and tunes the shader, but does not currently provide a second media source to that texture register.
Samples
The original MFormats SDK sample is installed here:
c:\Program Files (x86)\Medialooks\MFormats SDK\Samples\C#\Sample Custom Shader\
The expanded WPF samples in this package are:
MFormatsShaderLibrary- explicit frame processing sample.MPlatformShaderLibrary- plugin object-graph sample.shaders- reusable JSON/HLSL shader library.