Skip to content

revitalyr/Directx9_DOF_shader_with_custom_engine

Repository files navigation

DirectX 9 Depth of Field Post-Process Demo

Demonstration of Depth of Field (DOF) implementation as a post-processing effect in a custom DirectX 9 rendering engine.

Technical Overview

Architecture

  • Engine Layer: Modular rendering system with render target management, camera, and resource handling
  • Demo Layer: Scene management and DOF effect implementation
  • Shader Layer: HLSL pixel shaders for Gaussian blur post-processing

Key Features

  • Multi-pass render-to-texture pipeline
  • Separable Gaussian blur (horizontal + vertical passes)
  • Split-screen comparison (blurred vs sharp)
  • Debug visualization modes

Implementation Details

Render Pipeline

  1. Scene Pass: Render geometry to off-screen texture
  2. Horizontal Blur: Apply 5-tap Gaussian blur horizontally
  3. Vertical Blur: Apply 5-tap Gaussian blur vertically
  4. Composite: Display split-screen or full-screen result

Blur Shader

  • 5-tap weighted Gaussian kernel
  • Separable implementation for performance
  • Configurable blur radius via shader constants

Build Requirements

  • Visual Studio 2022 or later
  • Windows SDK 10.0+
  • DirectX SDK (June 2010)
  • vcpkg (for WIL library)

Building

Quick Build

quick_build.bat

Manual Build

cl /EHsc /O2 /std:c++latest ^
    /I"D:\tools\vcpkg\installed\x64-windows\include" ^
    /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared" ^
    /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um" ^
    /DWIN32 /D_WINDOWS /DUNICODE /D_UNICODE ^
    main.cpp engine/*.cpp demo/*.cpp ^
    /link ^
    "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\um\x64\d3d9.lib" ^
    "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\um\x64\d3dx9.lib" ^
    user32.lib gdi32.lib ^
    /out:DirectX9_DOF_Demo.exe

Controls

  • F1: Split-screen mode (blur left, sharp right)
  • F2: Full-screen blur only
  • F3: Full-screen sharp only
  • ESC: Exit

Project Structure

├── engine/          # Core rendering engine
│   ├── RendererDX9  # DirectX 9 device management
│   ├── RenderTarget # Render-to-texture wrapper
│   ├── Camera       # View/projection matrices
│   └── FullscreenQuad # Post-process quad rendering
├── demo/            # Demo scene implementation
│   └── DemoScene    # Scene management and DOF logic
├── shaders/         # HLSL shader files
│   ├── blur_h_ps.hlsl  # Horizontal Gaussian blur
│   ├── blur_v_ps.hlsl  # Vertical Gaussian blur
│   └── scene_*.hlsl    # Scene rendering shaders
└── main.cpp         # Application entry point

Technical Notes

Render Target Configuration

  • Scene RT: A8R8G8B8 with D24S8 depth buffer
  • Blur RTs: A8R8G8B8 without depth (post-process only)

Shader Model

  • Vertex Shaders: vs_2_0
  • Pixel Shaders: ps_2_0

Performance Considerations

  • Separable blur reduces complexity from O(n²) to O(2n)
  • Render targets sized to match backbuffer (1024x768)
  • No dynamic memory allocation in render loop

Limitations

  • Fixed resolution (1024x768)
  • Simplified scene geometry (test triangles)
  • No depth-based DOF blending (split-screen demonstration only)
  • DirectX 9 constraints (Shader Model 2.0)

License

Educational demonstration project.

About

DirectX 9 Depth of Field post-processing demo with Gaussian blur implementation in a custom rendering engine. Demonstrates render-to-texture pipeline, separable blur shaders, and modular engine architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors