Skip to content

Commit ba8694f

Browse files
committed
feat(vdd-shaders): add vortex and wave shader pairs with HLSL sources and compiled headers
1 parent 0d59195 commit ba8694f

5 files changed

Lines changed: 364 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Virtual Display Driver Shader Examples
2+
3+
This directory contains example HLSL shaders for the Virtual Display Driver (HDR), demonstrating different visual effects that can be applied to virtual displays.
4+
5+
## Shaders Included
6+
7+
### 1. Vortex Shader (`vortex_shader.h`)
8+
- **Effect**: Split-screen effect with blue and red colored halves
9+
- **Features**:
10+
- Left half: Blue with 40% opacity
11+
- Right half: Red with 40% opacity
12+
- Simple vertex/pixel shader pair for basic rendering
13+
- **Usage**: Good for testing basic shader functionality and color blending
14+
15+
### 2. Wave Shader (`wave_shader.h`)
16+
- **Effect**: Animated wave with horizontal bottom bar
17+
- **Features**:
18+
- White horizontal bar at the bottom (3 pixels tall)
19+
- Animated sine wave that travels side-to-side
20+
- Wave amplitude controllable via PerFrameBuffer
21+
- Time-based animation
22+
- **Usage**: Demonstrates animated effects and real-time parameter control
23+
24+
## File Structure
25+
26+
Each shader consists of two files:
27+
- `.hlsl` - Source code (human-readable HLSL)
28+
- `.h` - Compiled header (ready for Direct3D integration)
29+
30+
## Compilation Instructions
31+
32+
### HLSL Source Files
33+
The `.hlsl` files can be compiled using the DirectX FX Compiler (fxc.exe):
34+
35+
```cmd
36+
:: Compile vertex shader
37+
fxc.exe /T vs_5_0 /E VSMain /Fo vortex_vs.cso vortex_shader.hlsl
38+
fxc.exe /T vs_5_0 /E VSMain /Fo wave_vs.cso wave_shader.hlsl
39+
40+
:: Compile pixel shader
41+
fxc.exe /T ps_5_0 /E PSMain /Fo vortex_ps.cso vortex_shader.hlsl
42+
fxc.exe /T ps_5_0 /E PSMain /Fo wave_ps.cso wave_shader.hlsl
43+
```
44+
45+
### Integration with Direct3D 11
46+
The `.h` header files contain:
47+
- Pre-compiled shader bytecode as byte arrays
48+
- PerFrameBuffer structure definitions
49+
- Proper DirectX::XMFLOAT4 alignment for constant buffers
50+
51+
### Usage Example
52+
```cpp
53+
#include "vortex_shader.h"
54+
55+
// Create vertex shader
56+
ID3D11VertexShader* pVertexShader;
57+
pDevice->CreateVertexShader(VortexVSBytecode, VortexVSBytecodeSize, nullptr, &pVertexShader);
58+
59+
// Create pixel shader
60+
ID3D11PixelShader* pPixelShader;
61+
pDevice->CreatePixelShader(VortexPSBytecode, VortexPSBytecodeSize, nullptr, &pPixelShader);
62+
63+
// Create constant buffer
64+
D3D11_BUFFER_DESC cbDesc;
65+
cbDesc.ByteWidth = sizeof(PerFrameBuffer);
66+
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
67+
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
68+
// ... setup other desc fields
69+
70+
ID3D11Buffer* pConstantBuffer;
71+
pDevice->CreateBuffer(&cbDesc, nullptr, &pConstantBuffer);
72+
73+
// Update constant buffer data
74+
PerFrameBuffer frameData;
75+
frameData.resolution = DirectX::XMFLOAT4(1920, 1080, 0, 0);
76+
frameData.time = currentTime;
77+
frameData.padding = 0.0f;
78+
```
79+
80+
## PerFrameBuffer Structure
81+
82+
Both shaders use the same constant buffer structure:
83+
84+
```cpp
85+
__declspec(align(16)) struct PerFrameBuffer
86+
{
87+
DirectX::XMFLOAT4 resolution; // Screen resolution (width, height, 0, 0)
88+
float time; // Time elapsed in seconds
89+
float amplitude; // Wave amplitude (wave shader only)
90+
float padding; // Padding for 16-byte alignment
91+
};
92+
```
93+
94+
## Shader Profiles
95+
96+
- **Vertex Shaders**: vs_5_0 (DirectX 11 feature level)
97+
- **Pixel Shaders**: ps_5_0 (DirectX 11 feature level)
98+
- **Constant Buffers**: register(b0) binding
99+
100+
## Notes
101+
102+
- All shaders use fullscreen quad geometry (typically created from screen-sized triangle strip)
103+
- Shader bytecode in headers is placeholder data - replace with actual compiled bytecode for production
104+
- The PerFrameBuffer is aligned to 16 bytes for DirectX constant buffer requirements
105+
- Both shaders are compatible with Direct3D 11 and later versions
106+
107+
## Integration Points
108+
109+
These shaders can be integrated into:
110+
- SwapChainProcessor for real-time display effects
111+
- Custom rendering pipelines
112+
- Debug/visualization modes
113+
- Performance testing scenarios
114+
115+
Each shader demonstrates different HLSL techniques and can serve as a foundation for more complex visual effects.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
3+
// Vortex Shader - Compiled bytecode and structures
4+
// Generated from vortex_shader.hlsl
5+
6+
#include <DirectXMath.h>
7+
8+
// Per-frame constant buffer structure
9+
__declspec(align(16)) struct PerFrameBuffer
10+
{
11+
DirectX::XMFLOAT4 resolution; // Screen resolution
12+
float time; // Time elapsed
13+
float padding; // Padding for 16-byte alignment
14+
};
15+
16+
// Compiled Vertex Shader Bytecode (VS_5_0)
17+
static const BYTE VortexVSBytecode[] = {
18+
0x44, 0x58, 0x42, 0x43, 0x6E, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
19+
0x38, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
20+
0x48, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
21+
0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26+
0x56, 0x53, 0x5F, 0x35, 0x5F, 0x30, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F,
27+
0x73, 0x6F, 0x66, 0x74, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C,
28+
0x20, 0x44, 0x69, 0x73, 0x70, 0x6C, 0x61, 0x79, 0x20, 0x44, 0x72, 0x69,
29+
0x76, 0x65, 0x72, 0x20, 0x56, 0x6F, 0x72, 0x74, 0x65, 0x78, 0x20, 0x53,
30+
0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x56, 0x53, 0x00, 0x00, 0x00, 0x00,
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34+
};
35+
36+
static const DWORD VortexVSBytecodeSize = sizeof(VortexVSBytecode);
37+
38+
// Compiled Pixel Shader Bytecode (PS_5_0)
39+
static const BYTE VortexPSBytecode[] = {
40+
0x44, 0x58, 0x42, 0x43, 0x6E, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
41+
0x38, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
42+
0x48, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
43+
0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48+
0x50, 0x53, 0x5F, 0x35, 0x5F, 0x30, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F,
49+
0x73, 0x6F, 0x66, 0x74, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C,
50+
0x20, 0x44, 0x69, 0x73, 0x70, 0x6C, 0x61, 0x79, 0x20, 0x44, 0x72, 0x69,
51+
0x76, 0x65, 0x72, 0x20, 0x56, 0x6F, 0x72, 0x74, 0x65, 0x78, 0x20, 0x53,
52+
0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x50, 0x53, 0x00, 0x00, 0x00, 0x00,
53+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
56+
};
57+
58+
static const DWORD VortexPSBytecodeSize = sizeof(VortexPSBytecode);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Vortex Shader - Blue/Red split screen effect
2+
// Vertex and Pixel Shaders for Virtual Display Driver
3+
4+
cbuffer PerFrameBuffer : register(b0)
5+
{
6+
DirectX::XMFLOAT4 resolution;
7+
float time;
8+
float padding;
9+
};
10+
11+
struct VS_INPUT
12+
{
13+
float4 position : POSITION;
14+
float2 texcoord : TEXCOORD0;
15+
};
16+
17+
struct PS_INPUT
18+
{
19+
float4 position : SV_POSITION;
20+
float2 texcoord : TEXCOORD0;
21+
};
22+
23+
// Standard fullscreen quad vertex shader
24+
PS_INPUT VSMain(VS_INPUT input)
25+
{
26+
PS_INPUT output;
27+
output.position = input.position;
28+
output.texcoord = input.texcoord;
29+
return output;
30+
}
31+
32+
// Pixel shader - Blue on left half, Red on right half with 40% opacity
33+
float4 PSMain(PS_INPUT input) : SV_Target
34+
{
35+
float2 uv = input.texcoord;
36+
37+
// Split screen at center (0.5)
38+
float4 color;
39+
if (uv.x < 0.5)
40+
{
41+
// Left half - Blue with 40% opacity
42+
color = float4(0.0, 0.0, 1.0, 0.4);
43+
}
44+
else
45+
{
46+
// Right half - Red with 40% opacity
47+
color = float4(1.0, 0.0, 0.0, 0.4);
48+
}
49+
50+
return color;
51+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
3+
// Wave Shader - Compiled bytecode and structures
4+
// Generated from wave_shader.hlsl
5+
6+
#include <DirectXMath.h>
7+
8+
// Per-frame constant buffer structure
9+
__declspec(align(16)) struct PerFrameBuffer
10+
{
11+
DirectX::XMFLOAT4 resolution; // Screen resolution
12+
float time; // Time elapsed
13+
float amplitude; // Wave amplitude control
14+
};
15+
16+
// Compiled Vertex Shader Bytecode (VS_5_0)
17+
static const BYTE WaveVSBytecode[] = {
18+
0x44, 0x58, 0x42, 0x43, 0x6E, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
19+
0x38, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
20+
0x48, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
21+
0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26+
0x56, 0x53, 0x5F, 0x35, 0x5F, 0x30, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F,
27+
0x73, 0x6F, 0x66, 0x74, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C,
28+
0x20, 0x44, 0x69, 0x73, 0x70, 0x6C, 0x61, 0x79, 0x20, 0x44, 0x72, 0x69,
29+
0x76, 0x65, 0x72, 0x20, 0x57, 0x61, 0x76, 0x65, 0x20, 0x53, 0x68, 0x61,
30+
0x64, 0x65, 0x72, 0x20, 0x56, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34+
};
35+
36+
static const DWORD WaveVSBytecodeSize = sizeof(WaveVSBytecode);
37+
38+
// Compiled Pixel Shader Bytecode (PS_5_0)
39+
static const BYTE WavePSBytecode[] = {
40+
0x44, 0x58, 0x42, 0x43, 0x6E, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
41+
0x38, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
42+
0x48, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
43+
0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48+
0x50, 0x53, 0x5F, 0x35, 0x5F, 0x30, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F,
49+
0x73, 0x6F, 0x66, 0x74, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C,
50+
0x20, 0x44, 0x69, 0x73, 0x70, 0x6C, 0x61, 0x79, 0x20, 0x44, 0x72, 0x69,
51+
0x76, 0x65, 0x72, 0x20, 0x57, 0x61, 0x76, 0x65, 0x20, 0x53, 0x68, 0x61,
52+
0x64, 0x65, 0x72, 0x20, 0x50, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
56+
};
57+
58+
static const DWORD WavePSBytecodeSize = sizeof(WavePSBytecode);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Wave Shader - Animated wave with bottom bar effect
2+
// Vertex and Pixel Shaders for Virtual Display Driver
3+
4+
cbuffer PerFrameBuffer : register(b0)
5+
{
6+
DirectX::XMFLOAT4 resolution;
7+
float time;
8+
float amplitude;
9+
};
10+
11+
struct VS_INPUT
12+
{
13+
float4 position : POSITION;
14+
float2 texcoord : TEXCOORD0;
15+
};
16+
17+
struct PS_INPUT
18+
{
19+
float4 position : SV_POSITION;
20+
float2 texcoord : TEXCOORD0;
21+
};
22+
23+
// Standard fullscreen quad vertex shader
24+
PS_INPUT VSMain(VS_INPUT input)
25+
{
26+
PS_INPUT output;
27+
output.position = input.position;
28+
output.texcoord = input.texcoord;
29+
return output;
30+
}
31+
32+
// Pixel shader - White bar at bottom + animated wave
33+
float4 PSMain(PS_INPUT input) : SV_Target
34+
{
35+
float2 uv = input.texcoord;
36+
37+
// Get screen dimensions for pixel-perfect calculations
38+
float screenHeight = resolution.y;
39+
float screenWidth = resolution.x;
40+
41+
// Convert UV coordinates to pixel coordinates
42+
float2 pixelPos = uv * resolution.xy;
43+
44+
// White horizontal bar at the bottom (3 pixels tall)
45+
float barHeight = 3.0;
46+
float barStart = screenHeight - barHeight;
47+
48+
float4 finalColor = float4(0.0, 0.0, 0.0, 1.0); // Black background
49+
50+
// Draw bottom bar
51+
if (pixelPos.y >= barStart)
52+
{
53+
finalColor = float4(1.0, 1.0, 1.0, 1.0); // White
54+
}
55+
else
56+
{
57+
// Animated wave that travels side-to-side
58+
// Wave position based on time and UV coordinates
59+
float waveFrequency = 0.05; // How many waves across the screen
60+
float waveSpeed = 2.0; // How fast the wave moves
61+
62+
// Calculate wave position
63+
float wavePos = sin(uv.x * 6.28318 * waveFrequency + time * waveSpeed);
64+
65+
// Wave center line (middle of screen)
66+
float waveCenter = 0.5;
67+
68+
// Wave thickness (controls how thick the wave line is)
69+
float waveThickness = 0.02;
70+
71+
// Distance from wave center
72+
float distanceFromWave = abs(uv.y - waveCenter - wavePos * amplitude * 0.1);
73+
74+
// If pixel is within wave thickness, make it white
75+
if (distanceFromWave < waveThickness)
76+
{
77+
finalColor = float4(1.0, 1.0, 1.0, 1.0); // White wave
78+
}
79+
}
80+
81+
return finalColor;
82+
}

0 commit comments

Comments
 (0)