https://github.com/pecas-dev/dx3dcube
Cube with fading shaders made with DirectX 11 from scratch in C++.
https://github.com/pecas-dev/dx3dcube
cpp directx-11 graphics-programming
Last synced: 8 months ago
JSON representation
Cube with fading shaders made with DirectX 11 from scratch in C++.
- Host: GitHub
- URL: https://github.com/pecas-dev/dx3dcube
- Owner: Pecas-Dev
- Created: 2024-06-11T17:00:08.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-02T01:06:14.000Z (about 1 year ago)
- Last Synced: 2025-04-06T22:51:12.504Z (12 months ago)
- Topics: cpp, directx-11, graphics-programming
- Language: C++
- Homepage: https://juanfgutierrezc.wixsite.com/portfolio/cpp-projects
- Size: 20.5 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 3D Cube with Fading Shader using DirectX11 in C++
## Project Description
**Cube with fading shader made with DirectX 11 from scratch in C++.**
This project demonstrates the creation of a 3D cube rendered using DirectX 11. The project is built entirely from scratch, including window creation, the graphical rendering pipeline, and a simple input system to rotate the cube using the WASD or arrow keys.

---
## Features
- **Window Creation**: Set up from scratch to create a rendering window.
- **Rendering Pipeline**: Implementation of the entire DirectX 11 rendering pipeline.
- **Input System**: Custom input system for rotating the cube using WASD or arrow keys.
- **Shaders**: Custom vertex and pixel shaders to create a fading color effect on the cube.
## Shaders
### - Vertex Shader
The vertex shader transforms the 3D coordinates of each vertex into 2D screen coordinates and passes color information to the pixel shader.
```hlsl
struct VS_INPUT
{
float4 position : POSITION;
float3 color : COLOR;
float3 color1 : COLOR1;
};
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float3 color : COLOR;
float3 color1 : COLOR1;
};
cbuffer constant : register(b0)
{
row_major float4x4 m_world;
row_major float4x4 m_view;
row_major float4x4 m_proj;
unsigned int m_time;
};
VS_OUTPUT vsmain(VS_INPUT input)
{
VS_OUTPUT output = (VS_OUTPUT) 0;
output.position = mul(input.position, m_world);
output.position = mul(output.position, m_view);
output.position = mul(output.position, m_proj);
output.color = input.color;
output.color1 = input.color1;
return output;
}
```
### - Pixel Shader
The pixel shader interpolates the colors between color and color1 based on a sine wave function to create a fading effect.
```hlsl
struct PS_INPUT
{
float4 position: SV_POSITION;
float3 color: COLOR;
float3 color1: COLOR1;
};
cbuffer constant: register(b0)
{
row_major float4x4 m_world;
row_major float4x4 m_view;
row_major float4x4 m_proj;
unsigned int m_time;
};
float4 psmain(PS_INPUT input) : SV_TARGET
{
return float4(lerp(input.color, input.color1, (float)((sin((float)(m_time / (float)500.0f)) + 1.0f) / 2.0f)),1.0f);
}
```
## Directory Structure
- Graphics: Contains all graphics-related source and include files such as constant buffer, device context, index buffer, pixel shader, swap chain, vertex buffer, vertex shader, and graphics engine.
- Input: Contains input system and input listener scripts.
- Window: Handles window creation.
- App: Manages the execution of the graphics engine and other scripts.
- main.cpp: Entry point of the application.
## Installation & Running
1. Clone the repository: `git clone https://github.com/Pecas-Dev/DX3DCube.git`
2. Open `DX3DCube.sln` in **Visual Studio**.
3. Choose your configuration (Debug/Release) and platform (x64/x86).
4. Build the solution.
5. Run the program.
## Controls
- W / Up Arrow: Rotate the cube up.
- A / Left Arrow: Rotate the cube left.
- S / Down Arrow: Rotate the cube down.
- D / Right Arrow: Rotate the cube right.
## Credits
This project was created by _**Pecas Dev**_.