Custom Shaders
HyprWin custom shaders control the pixels in the move and resize preview overlay. HyprWin supplies the target rectangle, colors, settings, and timing; your HLSL function returns the color and opacity of each canvas pixel.
Only the pixel shader is customizable.
Set hw.settings.shader to an HLSL file to replace the built-in overlay pixel
shader:
hw.settings.shader = "shaders/custom.hlsl"The path is resolved relative to hyprwin.lua. Set it to nil or an empty
string to restore the built-in shader.
Requirements
Section titled “Requirements”Custom shaders require d3dcompiler_47.dll either beside hyprwin.exe or
available from Windows System32.
Check availability from Lua:
local status = hw.debug.shader_compiler_status()hw.log("info", status.diagnostics)HyprWin ships shaders/hyprwin_shader_api.hlsl beside the executable. Place
custom shaders in that directory so the include resolves both in HyprWin and
in your HLSL language server.
If HLSL is new to you, read Techniques after completing the minimal shader.
Minimal shader
Section titled “Minimal shader”#include "hyprwin_shader_api.hlsl"
float rounded_box_distance(float2 p, float2 halfSize, float radius) { float2 q = abs(p) - halfSize + radius; return length(max(q, 0.0f)) + min(max(q.x, q.y), 0.0f) - radius;}
float4 hyprwin_pixel(HyprWinPixelInput input) { float2 p = input.screenPosition - runtime.rectCenter; float d = rounded_box_distance(p, runtime.rectHalfSize, settings.cornerRadius); float borderDistance = d + 1.0f; float width = max(settings.borderThickness, 1.0f); float aa = max(fwidth(borderDistance), 0.5f); float border = smoothstep(-aa, 0.0f, borderDistance) * smoothstep(width + aa, width - aa, borderDistance);
float t = dot(p, settings.gradientDirection) / (runtime.gradientScale * 2.0f) + 0.5f; float4 color = hyprwin_sample_palette(t); float alpha = saturate(border * color.a); return float4(color.rgb * alpha, alpha);}Include the shipped shaders/hyprwin_shader_api.hlsl file. The
header source
is also available on GitHub.
The API header provides the ps_main entry point. A custom file implements
hyprwin_pixel. HyprWin compiles it for shader model ps_5_0 with strict
compilation and warnings-as-errors.
The minimal example follows the built-in shader’s positioning convention. The visible border overlaps the target rectangle by one physical pixel. See Border masks for the detailed positioning rules.
This convention is recommended, not required. A custom pixel shader receives the full virtual-desktop canvas and may draw inside the target rectangle or anywhere else on that canvas.
Output alpha
Section titled “Output alpha”Return premultiplied RGBA:
return float4(rgb * alpha, alpha);The overlay uses premultiplied alpha composition. Returning unmodified RGB with partial alpha produces incorrect blending.
HyprWinPixelInput.screenPosition contains canvas-local pixel coordinates from
SV_Position. Pixel centers are offset by one half pixel, as defined by the
Direct3D system-value semantic.
Useful coordinate forms are:
float2 canvasUv = input.screenPosition / max(runtime.canvasSize, 1.0f);float2 windowPx = input.screenPosition - runtime.rectCenter;float2 windowUv = windowPx / max(runtime.rectHalfSize, 1.0f);canvasUvnormally spans0.0through1.0across the virtual-desktop overlay.windowPxis measured in pixels from the target rectangle center.windowUvis approximately-1.0through1.0across the target rectangle.
Do not assume runtime.rectCenter equals runtime.canvasSize / 2; the target can be anywhere
on a multi-monitor virtual desktop.
Runtime values
Section titled “Runtime values”The HyprWinParams constant buffer is bound at b0.
| Field | Type | Description |
|---|---|---|
runtime.canvasSize |
float2 |
Overlay canvas width and height. |
runtime.rectCenter |
float2 |
Target rectangle center in canvas coordinates. |
runtime.rectHalfSize |
float2 |
Half width and half height of the target rectangle. |
runtime.gradientScale |
float |
At least 1, based on target rectangle half-size length. |
runtime.sessionType |
uint |
0 none, 1 drag, 2 resize. |
runtime.timeSeconds |
float |
Shader animation time. |
runtime.deltaSeconds |
float |
Time since the previous rendered frame. |
runtime.sessionSeconds |
float |
Time since the current drag or resize session began. |
User settings
Section titled “User settings”These values come from the active Lua settings:
| Field | Type | Description |
|---|---|---|
settings.gradientDirection |
float2 |
Direction derived from the current gradient angle. |
settings.borderThickness |
float |
hw.settings.border. |
settings.cornerRadius |
float |
hw.settings.corner_radius scaled by the grabbed window’s DPI. |
settings.outerAlpha |
float |
Outer border-edge opacity and exterior glow strength from hw.settings.outer_alpha. |
settings.glowFalloff |
float |
hw.settings.glow_falloff. |
settings.colorCount |
uint |
Active palette count from 1 through 16. |
settings.colors |
float4[16] |
Normalized RGBA palette values. |
runtime.timeSeconds is continuous while the overlay renderer exists and wraps after
one hour. runtime.sessionSeconds resets when the operation changes between no
operation, dragging, and resizing. runtime.deltaSeconds is zero on the first rendered
frame after timing is reset.
Palette helpers
Section titled “Palette helpers”| Function | Description |
|---|---|
hyprwin_palette_count() |
Clamped active color count. |
hyprwin_palette_color(index) |
Palette color with index clamped to the last color. |
hyprwin_sample_palette(t) |
Interpolate across the palette with saturated t. |
The palette colors include their configured alpha. Most shaders use the sampled RGB and calculate final coverage separately:
float4 palette = hyprwin_sample_palette(t);float alpha = saturate(mask * palette.a);return float4(palette.rgb * alpha, alpha);Compilation and cache
Section titled “Compilation and cache”Compiled shaders are cached under shader-cache/ beside the executable.
Reload the HyprWin configuration after changing shader source. Compilation errors are written to the log, and a failed compilation does not install new bytecode.
Continue learning
Section titled “Continue learning”- Techniques explains distance fields, anti-aliasing, glow, animation, performance, and useful HLSL references.