In today’s update, I implemented Blinn-Phong specular highlights so the rotating cubes react dynamically to the camera’s viewing angle while keeping the 40x40 reference grid unlit.
Chapters:
00:00 Intro - Day 9 C++ & DirectX 12 Game Engine
00:25 Live Engine Demo - Blinn-Phong Specular Highlights in Real Time
01:25 Step 1 - Expanding SceneConstantBuffer to 256 Bytes (Game.h)
02:10 Step 2 - World-Space Position & Blinn-Phong Shader (shaders.hlsl)
03:00 Step 3 - Uploading Camera Position & Specular Parameters (Game.cpp)
What’s new in Day 9:
- Expanded 256-Byte Constant Buffer: Added cameraPos, shininess (32.0f), and specularStr (0.6f) to SceneConstantBuffer in Game.h while adjusting padding to maintain strict 256-byte alignment.
- World-Space Position Output in VSMain: Updated shaders.hlsl to compute world-space vertex positions (worldPos) and pass them to the Pixel Shader alongside world-space normals.
- Blinn-Phong Specular Lighting in PSMain: Computed the view vector (V = normalize(gCameraPos - input.worldPos)) and halfway vector (H = normalize(L + V)) to combine ambient, Lambertian diffuse, and specular highlights on lit geometry (useLighting = 1.0f), while keeping the grid unshaded (useLighting = 0.0f).
- Per-Frame Camera Upload: Updated Game::Update() to upload the live camera world position and material specular parameters into each cube’s mapped Constant Buffer every frame.
Link video Day 9:https://youtu.be/eN3aWWqpXHA
Current Engine Controls:
- W / A / S / D: Move forward, left, backward, right
- Q / E: Move down / up
- Right Mouse Button + Move: Free look (Yaw & Pitch)
- Left Shift: 2.5x movement speed boost
- Mouse Wheel: Adjust base camera speed
- R: Reset camera to default position and orientation
Tech Stack: C++, DirectX 12, HLSL, DirectXMath, Win32 API, Microsoft GDK.
Follow the daily engine development journey here on Low-Level Code | USA.
CPP #DirectX12 #GameEngine #GraphicsProgramming #EngineProgrammer #LowLevelProgramming #GameDev #MicrosoftGDK hlsl #BlinnPhong