A Windows desktop application that creates a liquid glass lens effect in real-time using Rust, Win32, Direct3D 11, and DXGI Desktop Duplication, applying refraction, chromatic dispersion, rim lighting, shadows, and anti-aliasing through pixel shaders.

Stars

3

7-day growth

No data

Forks

1

Open issues

0

License

No data

Last updated

2026-07-30

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It demonstrates a performant real-time desktop distortion effect with multi-monitor support, per-monitor DPI awareness, and SDF-based anti-aliasing, all implemented in a single Rust source file with centralized parameters for easy tweaking.

Who it is for

  • Windows desktop graphics developers
  • Rust programmers interested in Win32 and Direct3D interop
  • Hobbyists and artists exploring real-time screen effects
  • Developers studying DXGI Desktop Duplication and pixel shader techniques

Use cases

  • Creating a stylish desktop widget or screensaver with a liquid lens effect
  • Demonstrating real-time refraction and chromatic aberration on a live desktop
  • Learning or prototyping shader-based post-processing effects on Windows
  • Adding a decorative glass overlay to presentations or streaming setups

Strengths

  • Real-time capture and rendering of the desktop with minimal latency using DXGI Desktop Duplication
  • Supports multiple monitors and virtual desktop coordinates, including negative regions
  • Per-Monitor V2 DPI awareness ensures correct scaling on high-DPI displays
  • All visual parameters are conveniently listed at the top of the source file for quick iteration

Considerations

  • Only works on Windows 10/11 with a Direct3D 11 capable GPU
  • The lens window captures desktop content but does not allow interaction with underlying UI elements
  • Performance may vary with GPU capabilities and screen resolution; no automation tests are included

README quick start

Liquid Glass

一个使用 Rust、Win32、Direct3D 11 和 DXGI Desktop Duplication 实现的 Windows 桌面液态玻璃透镜。程序实时捕获透镜所在的显示器,通过像素着色器生成折射、色散、 边缘光、阴影和抗锯齿效果。

功能

  • 实时桌面折射和液态玻璃效果
  • 可拖动的胶囊形透镜
  • 支持多显示器和虚拟桌面负坐标
  • 透镜跨屏后自动切换桌面捕获源
  • Per-Monitor V2 DPI 感知
  • 基于 SDF 像素导数的轮廓抗锯齿
  • 捕获排除,透镜窗口不会递归出现在自己的画面中
  • 所有常用视觉参数集中在 Rust 源文件顶部

环境要求

  • Windows 10 或 Windows 11
  • 支持 Direct3D 11 和 DXGI Desktop Duplication 的显卡及驱动
  • Rust 工具链,推荐使用 stable-x86_64-pc-windows-msvc
  • Visual Studio Build Tools,并安装 Desktop development with C++ 组件

安装 Rust 后,可以确认当前工具链:

rustup default stable-x86_64-pc-windows-msvc
rustc --version
cargo --version

运行

开发模式:

cargo run

构建发布版本:

cargo build --release

生成的程序位于:

target\release\liquid-glass.exe

这是 Windows GUI 程序,启动后不会显示控制台窗口。

操作

  • 在透镜区域按住鼠标左键并拖动,可以移动透镜。
  • Esc 退出程序。
  • 透镜可以移动到主显示器左侧或上方的屏幕。

调整效果

所有常用参数都位于 src/main.rs 顶部。修改后重新运行 cargo run 或重新构建即可。

尺寸

参数说明
LENS_W透镜宽度,单位为物理像素
LENS_H透镜高度,单位为物理像素,同时决定胶囊圆角半径

阴影

参数增大后的效果
SHADOW_OFFSET_Y阴影向下移动
SHADOW_SOFTNESS阴影扩散得更宽、更柔和
SHADOW_OPACITY阴影更深

折射

参数说明
REFRACTION_CORE_X中心低形变区域的横向范围
REFRACTION_CORE_Y中心低形变区域的纵向范围
REFRACTION_RADIUS折射映射形状的圆角程度
REFRACTION_TRANSITION折射从中心到边缘的过渡范围
REFRACTION_BIAS增大后边缘折射更明显

边缘和颜色

参数增大后的效果
EDGE_EFFECT_WIDTH高光、暗边和色散向内部延伸得更宽
CHROMATIC_OFFSET红蓝通道分离更明显
COLOR_CONTRAST透镜内画面对比度更高
COLOR_GAIN整体颜色更亮
COLOR_LIFT黑位和暗部被抬高

光照和抗锯齿

参数说明
TOP_LIGHT_POSITION顶部高光的纵向作用位置
TOP_LIGHT_STRENGTH顶部高光强度
LOWER_SHADOW_POSITION底部暗边开始作用的位置
LOWER_SHADOW_STRENGTH底部暗边强度
AA_DERIVATIVE_SCALE根据像素导数计算的抗锯齿宽度系数
AA_MIN_HALF_WIDTH最小抗锯齿半宽;增大后轮廓更柔和

如果高分辨率屏幕上的边缘仍然偏硬,可以小幅同时提高 AA_DERIVATIVE_SCALEAA_MIN_HALF_WIDTH。数值过大会让轮廓变得模糊。

项目结构

liquid-glass/
|-- Cargo.toml       # 包信息、Windows API 功能依赖
|-- Cargo.lock       # 锁定的依赖版本
`-- src/
    `-- main.rs      # Win32 窗口、桌面捕获、D3D11 渲染和 HLSL 着色器

实现概要

程序创建两个顶层窗口:一个覆盖虚拟桌面的透明渲染窗口,以及一个与透镜位置同步的 输入窗口。DXGI Desktop Duplication 捕获透镜中心所在的显示器,D3D11 像素着色器 使用有符号距离场计算胶囊轮廓,并完成折射和透明度合成。

多显示器坐标统一使用 Windows 虚拟桌面坐标,因此位于主屏左侧或上方的显示器所产生 的负坐标也能正确处理。

检查

cargo fmt -- --check
cargo check
cargo

Description

windows liquid glass

Related repositories

Similar projects matched by category, topics, and programming language.

l0ng-ai
Featured
l0ng-ai GitHub avatar

tty7

tty7 is a fast, GPU-accelerated terminal workbench with persistent sessions, built-in input tools, SSH support, and coding agent awareness.

Developer ToolsCLI & Terminal
359
steelbrain
Featured
steelbrain GitHub avatar

reims-vgpu

reims-vgpu is an experimental virtual GPU for macOS guests that uses QEMU to decode the guest's GPU command stream and execute it through Metal or Vulkan, leveraging the built-in AppleParavirtGPU driver without requiring custom kexts.

Desktop Apps
143
Blaizzy
Featured
Blaizzy GitHub avatar

nativ

Nativ is a native macOS app that lets you run AI models locally on Apple silicon, offering chat, model management, performance analytics, and an OpenAI/Anthropic-compatible API server.

AI & Machine LearningAI Vision & Audio
985