diff --git a/Assets/Textures/HQGame/structure-blocked.tga b/Assets/Textures/HQGame/structure-blocked.tga deleted file mode 100644 index fe7ecb2..0000000 Binary files a/Assets/Textures/HQGame/structure-blocked.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-carpet.tga b/Assets/Textures/HQGame/structure-carpet.tga deleted file mode 100644 index 943a33c..0000000 Binary files a/Assets/Textures/HQGame/structure-carpet.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.tga b/Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.tga deleted file mode 100644 index 44ddf35..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-deepfloor_bump.tga b/Assets/Textures/HQGame/structure-endgame-deepfloor_bump.tga deleted file mode 100644 index d419164..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-deepfloor_bump.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-dirt.tga b/Assets/Textures/HQGame/structure-endgame-dirt.tga deleted file mode 100644 index 9189409..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-dirt.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-floor_albedo.tga b/Assets/Textures/HQGame/structure-endgame-floor_albedo.tga deleted file mode 100644 index da29f2f..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-floor_albedo.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-floor_bump.tga b/Assets/Textures/HQGame/structure-endgame-floor_bump.tga deleted file mode 100644 index 9f2ae31..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-floor_bump.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-wall_albedo.tga b/Assets/Textures/HQGame/structure-endgame-wall_albedo.tga deleted file mode 100644 index e04662a..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-wall_albedo.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-wall_bump.tga b/Assets/Textures/HQGame/structure-endgame-wall_bump.tga deleted file mode 100644 index d80128b..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-wall_bump.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-endgame-water.tga b/Assets/Textures/HQGame/structure-endgame-water.tga deleted file mode 100644 index 88e7103..0000000 Binary files a/Assets/Textures/HQGame/structure-endgame-water.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-tile.tga b/Assets/Textures/HQGame/structure-tile.tga deleted file mode 100644 index 7b02842..0000000 Binary files a/Assets/Textures/HQGame/structure-tile.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-vrgrid-a.tga b/Assets/Textures/HQGame/structure-vrgrid-a.tga deleted file mode 100644 index 00a994e..0000000 Binary files a/Assets/Textures/HQGame/structure-vrgrid-a.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-vrgrid-b.tga b/Assets/Textures/HQGame/structure-vrgrid-b.tga deleted file mode 100644 index 2b7da23..0000000 Binary files a/Assets/Textures/HQGame/structure-vrgrid-b.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-wall_albedo.tga b/Assets/Textures/HQGame/structure-wall_albedo.tga deleted file mode 100644 index f886617..0000000 Binary files a/Assets/Textures/HQGame/structure-wall_albedo.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-wall_bump.tga b/Assets/Textures/HQGame/structure-wall_bump.tga deleted file mode 100644 index 04449c8..0000000 Binary files a/Assets/Textures/HQGame/structure-wall_bump.tga and /dev/null differ diff --git a/Assets/Textures/HQGame/structure-wood.tga b/Assets/Textures/HQGame/structure-wood.tga deleted file mode 100644 index 5827780..0000000 Binary files a/Assets/Textures/HQGame/structure-wood.tga and /dev/null differ diff --git a/Assets/Textures/PBR/bronze_albedo.png b/Assets/Textures/PBR/bronze_albedo.png new file mode 100644 index 0000000..9b5ec89 Binary files /dev/null and b/Assets/Textures/PBR/bronze_albedo.png differ diff --git a/Assets/Textures/PBR/bronze_metal.png b/Assets/Textures/PBR/bronze_metal.png new file mode 100644 index 0000000..b498af7 Binary files /dev/null and b/Assets/Textures/PBR/bronze_metal.png differ diff --git a/Assets/Textures/PBR/bronze_normals.png b/Assets/Textures/PBR/bronze_normals.png new file mode 100644 index 0000000..3b4d7f8 Binary files /dev/null and b/Assets/Textures/PBR/bronze_normals.png differ diff --git a/Assets/Textures/PBR/bronze_roughness.png b/Assets/Textures/PBR/bronze_roughness.png new file mode 100644 index 0000000..8e6f571 Binary files /dev/null and b/Assets/Textures/PBR/bronze_roughness.png differ diff --git a/Assets/Textures/PBR/cobblestone_albedo.png b/Assets/Textures/PBR/cobblestone_albedo.png new file mode 100644 index 0000000..14f72ab Binary files /dev/null and b/Assets/Textures/PBR/cobblestone_albedo.png differ diff --git a/Assets/Textures/PBR/cobblestone_metal.png b/Assets/Textures/PBR/cobblestone_metal.png new file mode 100644 index 0000000..7ac7d52 Binary files /dev/null and b/Assets/Textures/PBR/cobblestone_metal.png differ diff --git a/Assets/Textures/PBR/cobblestone_normals.png b/Assets/Textures/PBR/cobblestone_normals.png new file mode 100644 index 0000000..e58bde8 Binary files /dev/null and b/Assets/Textures/PBR/cobblestone_normals.png differ diff --git a/Assets/Textures/PBR/cobblestone_roughness.png b/Assets/Textures/PBR/cobblestone_roughness.png new file mode 100644 index 0000000..c5bfff2 Binary files /dev/null and b/Assets/Textures/PBR/cobblestone_roughness.png differ diff --git a/Assets/Textures/PBR/floor_albedo.png b/Assets/Textures/PBR/floor_albedo.png new file mode 100644 index 0000000..8da683a Binary files /dev/null and b/Assets/Textures/PBR/floor_albedo.png differ diff --git a/Assets/Textures/PBR/floor_metal.png b/Assets/Textures/PBR/floor_metal.png new file mode 100644 index 0000000..2861972 Binary files /dev/null and b/Assets/Textures/PBR/floor_metal.png differ diff --git a/Assets/Textures/PBR/floor_normals.png b/Assets/Textures/PBR/floor_normals.png new file mode 100644 index 0000000..936def0 Binary files /dev/null and b/Assets/Textures/PBR/floor_normals.png differ diff --git a/Assets/Textures/PBR/floor_roughness.png b/Assets/Textures/PBR/floor_roughness.png new file mode 100644 index 0000000..6652b35 Binary files /dev/null and b/Assets/Textures/PBR/floor_roughness.png differ diff --git a/Assets/Textures/PBR/paint_albedo.png b/Assets/Textures/PBR/paint_albedo.png new file mode 100644 index 0000000..69ff549 Binary files /dev/null and b/Assets/Textures/PBR/paint_albedo.png differ diff --git a/Assets/Textures/PBR/paint_metal.png b/Assets/Textures/PBR/paint_metal.png new file mode 100644 index 0000000..7ac7d52 Binary files /dev/null and b/Assets/Textures/PBR/paint_metal.png differ diff --git a/Assets/Textures/PBR/paint_normals.png b/Assets/Textures/PBR/paint_normals.png new file mode 100644 index 0000000..89e9be0 Binary files /dev/null and b/Assets/Textures/PBR/paint_normals.png differ diff --git a/Assets/Textures/PBR/paint_roughness.png b/Assets/Textures/PBR/paint_roughness.png new file mode 100644 index 0000000..05e6d87 Binary files /dev/null and b/Assets/Textures/PBR/paint_roughness.png differ diff --git a/Assets/Textures/PBR/rough_albedo.png b/Assets/Textures/PBR/rough_albedo.png new file mode 100644 index 0000000..8a662f8 Binary files /dev/null and b/Assets/Textures/PBR/rough_albedo.png differ diff --git a/Assets/Textures/PBR/rough_metal.png b/Assets/Textures/PBR/rough_metal.png new file mode 100644 index 0000000..72c430e Binary files /dev/null and b/Assets/Textures/PBR/rough_metal.png differ diff --git a/Assets/Textures/PBR/rough_normals.png b/Assets/Textures/PBR/rough_normals.png new file mode 100644 index 0000000..979c8c3 Binary files /dev/null and b/Assets/Textures/PBR/rough_normals.png differ diff --git a/Assets/Textures/PBR/rough_roughness.png b/Assets/Textures/PBR/rough_roughness.png new file mode 100644 index 0000000..9355d3c Binary files /dev/null and b/Assets/Textures/PBR/rough_roughness.png differ diff --git a/Assets/Textures/PBR/scratched_albedo.png b/Assets/Textures/PBR/scratched_albedo.png new file mode 100644 index 0000000..15fc6b4 Binary files /dev/null and b/Assets/Textures/PBR/scratched_albedo.png differ diff --git a/Assets/Textures/PBR/scratched_metal.png b/Assets/Textures/PBR/scratched_metal.png new file mode 100644 index 0000000..9d02e7a Binary files /dev/null and b/Assets/Textures/PBR/scratched_metal.png differ diff --git a/Assets/Textures/PBR/scratched_normals.png b/Assets/Textures/PBR/scratched_normals.png new file mode 100644 index 0000000..da8faec Binary files /dev/null and b/Assets/Textures/PBR/scratched_normals.png differ diff --git a/Assets/Textures/PBR/scratched_roughness.png b/Assets/Textures/PBR/scratched_roughness.png new file mode 100644 index 0000000..61c5e90 Binary files /dev/null and b/Assets/Textures/PBR/scratched_roughness.png differ diff --git a/Assets/Textures/PBR/wood_albedo.png b/Assets/Textures/PBR/wood_albedo.png new file mode 100644 index 0000000..f7ba778 Binary files /dev/null and b/Assets/Textures/PBR/wood_albedo.png differ diff --git a/Assets/Textures/PBR/wood_metal.png b/Assets/Textures/PBR/wood_metal.png new file mode 100644 index 0000000..7ac7d52 Binary files /dev/null and b/Assets/Textures/PBR/wood_metal.png differ diff --git a/Assets/Textures/PBR/wood_normals.png b/Assets/Textures/PBR/wood_normals.png new file mode 100644 index 0000000..e4780c4 Binary files /dev/null and b/Assets/Textures/PBR/wood_normals.png differ diff --git a/Assets/Textures/PBR/wood_roughness.png b/Assets/Textures/PBR/wood_roughness.png new file mode 100644 index 0000000..b00be04 Binary files /dev/null and b/Assets/Textures/PBR/wood_roughness.png differ diff --git a/Camera.cpp b/Camera.cpp index 6174f67..a9985e7 100644 --- a/Camera.cpp +++ b/Camera.cpp @@ -3,7 +3,7 @@ using namespace DirectX; -Camera::Camera(float _x, float _y, float _z, float _aspect, float _fov, float _near, float _far) +Camera::Camera(float _x, float _y, float _z, float _aspect, float _fov, float _near, float _far, float _moveSpeed) { transform.SetPosition(_x, _y, _z); @@ -11,6 +11,7 @@ Camera::Camera(float _x, float _y, float _z, float _aspect, float _fov, float _n fovYRadians = XMConvertToRadians(_fov); clipNear = _near; clipFar = _far; + moveSpeed = _moveSpeed; UpdateViewMatrix(); UpdateProjectionMatrix(); @@ -100,8 +101,8 @@ void Camera::ReadInput(float _dt) if (input.KeyDown(VK_SHIFT)) modify *= 2.0f; if (input.KeyDown(VK_CONTROL)) modify /= 2.0f; - transform.TranslateRelative(moveLat * _dt * modify, 0, moveLong * _dt * modify); - transform.TranslateAbsolute(0, moveVert * _dt * modify, 0); + transform.TranslateRelative(moveLat * _dt * modify * moveSpeed, 0, moveLong * _dt * modify * moveSpeed); + transform.TranslateAbsolute(0, moveVert * _dt * modify * moveSpeed, 0); if (input.MouseLeftDown()) { diff --git a/Camera.h b/Camera.h index d18fe99..d51acab 100644 --- a/Camera.h +++ b/Camera.h @@ -6,7 +6,7 @@ class Camera { public: - Camera(float _x, float _y, float _z, float _aspect, float _fov, float _near, float _far); + Camera(float _x, float _y, float _z, float _aspect, float _fov, float _near, float _far, float _moveSpeed); ~Camera(); void Update(float _dt); @@ -23,6 +23,7 @@ public: void SetFarClip(float _far); private: + float moveSpeed; float aspect; float fovYRadians; float clipNear; diff --git a/DX11Starter.vcxproj b/DX11Starter.vcxproj index c06c975..bb39583 100644 --- a/DX11Starter.vcxproj +++ b/DX11Starter.vcxproj @@ -182,12 +182,24 @@ 5.0 5.0 + + Pixel + Pixel + Pixel + Pixel + Pixel Pixel Pixel Pixel + + Vertex + Vertex + Vertex + Vertex + Pixel Pixel @@ -321,7 +333,9 @@ + + @@ -356,232 +370,6 @@ $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - - false - true - false - true - false - true - false - true - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - $(OutDir)/Assets/Textures/HQGame - - false @@ -914,6 +702,400 @@ $(OutDir)/Assets/Textures/Skies/planets + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + $(OutDir)/Assets/Textures/PBR + + diff --git a/DX11Starter.vcxproj.filters b/DX11Starter.vcxproj.filters index 9ad1d9c..d963d1f 100644 --- a/DX11Starter.vcxproj.filters +++ b/DX11Starter.vcxproj.filters @@ -37,6 +37,9 @@ {f0ccea00-427b-47f7-8fce-7110b649b668} + + {5a00f65f-2015-451b-9c46-5131e9fd2555} + @@ -130,6 +133,12 @@ Shaders + + Shaders + + + Shaders + @@ -159,54 +168,6 @@ Assets\Textures\HQGame - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - - - Assets\Textures\HQGame - Assets\Textures\HQGame @@ -276,6 +237,90 @@ Assets\Textures\Skies\planets + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + + + Assets\Textures\PBR + @@ -294,5 +339,11 @@ Shaders + + Shaders + + + Shaders + \ No newline at end of file diff --git a/Game.cpp b/Game.cpp index 04b19dd..39f9cb9 100644 --- a/Game.cpp +++ b/Game.cpp @@ -34,7 +34,7 @@ Game::Game(HINSTANCE hInstance) CreateConsoleWindow(500, 120, 32, 120); printf("Console window created successfully. Feel free to printf() here.\n"); #endif - camera = std::make_shared(0.0f, 0.0f, -20.0f, (float)width / height, 60, 0.01f, 1000.0f); + camera = std::make_shared(0.0f, 0.0f, -10.0f, (float)width / height, 60, 0.01f, 1000.0f, 5.0f); } // -------------------------------------------------------- @@ -74,14 +74,20 @@ void Game::LoadShadersAndMaterials() { vertexShader = std::make_shared(device, context, GetFullPathTo_Wide(L"VertexShader.cso").c_str()); pixelShader = std::make_shared(device, context, GetFullPathTo_Wide(L"SimplePixelShader.cso").c_str()); + vertexShaderPBR = std::make_shared(device, context, GetFullPathTo_Wide(L"SimpleVertexPBR.cso").c_str()); + pixelShaderPBR = std::make_shared(device, context, GetFullPathTo_Wide(L"SimplePixelPBR.cso").c_str()); XMFLOAT3 white = XMFLOAT3(1.0f, 1.0f, 1.0f); materials = { - std::make_shared(white, 0, vertexShader, pixelShader), - std::make_shared(white, 0, vertexShader, pixelShader), - std::make_shared(white, 0, vertexShader, pixelShader), - std::make_shared(white, 0, vertexShader, pixelShader), + std::make_shared(false, white, 0, vertexShader, pixelShader), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), }; } @@ -113,30 +119,51 @@ void Game::LoadTextures() materials[0]->PushSampler("BasicSampler", sampler); materials[0]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); materials[0]->hasReflectionMap = true; - materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_emissive.png", TEXTYPE_EMISSIVE, device.Get(), context.Get()); + materials[0]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[0]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[0]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); materials[1]->PushSampler("BasicSampler", sampler); - materials[1]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); - materials[1]->hasReflectionMap = true; - materials[1]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[1]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[1]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); materials[2]->PushSampler("BasicSampler", sampler); - materials[2]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); - materials[2]->hasReflectionMap = true; - materials[2]->LoadTexture(L"Assets/Textures/WithNormals/rock.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[2]->LoadTexture(L"Assets/Textures/WithNormals/rock_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[2]->LoadTexture(L"Assets/Textures/WithNormals/rock_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); materials[3]->PushSampler("BasicSampler", sampler); - materials[3]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); - materials[3]->hasReflectionMap = true; - materials[3]->LoadTexture(L"Assets/Textures/WithNormals/cushion.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[3]->LoadTexture(L"Assets/Textures/WithNormals/cushion_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[3]->LoadTexture(L"Assets/Textures/WithNormals/cushion_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[4]->PushSampler("BasicSampler", sampler); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[5]->PushSampler("BasicSampler", sampler); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[6]->PushSampler("BasicSampler", sampler); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[7]->PushSampler("BasicSampler", sampler); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); } // -------------------------------------------------------- @@ -147,13 +174,13 @@ void Game::LoadLighting() ambient = XMFLOAT3(0.1f, 0.1f, 0.15f); lights = { - Light::Directional(XMFLOAT3(1, 0.5f, 0.5f), XMFLOAT3(1, 1, 1), 0.75f), - Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.75f), - Light::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.75f), - Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.5f, 10), - Light::Point(XMFLOAT3(1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.25f, 10), - Light::Point(XMFLOAT3(0, 2, 0), XMFLOAT3(1, 0, 0), 0.25f, 10), - Light::Point(XMFLOAT3(-27.5f, 0, 0), XMFLOAT3(1, 1, 0.5f), 5, 20), + Light::Directional(XMFLOAT3(1, 0.5f, -0.5f), XMFLOAT3(1, 1, 1), 1.0f), + Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.25f), + Light::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.25f), + Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10), + Light::Point(XMFLOAT3(1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10), + Light::Point(XMFLOAT3(0, 2, 0), XMFLOAT3(1, 0, 0), 0.35f, 10), + Light::Point(XMFLOAT3(-27.5f, 0, 0), XMFLOAT3(1, 1, 0.5f), 0.35f, 20), }; } @@ -187,31 +214,29 @@ void Game::CreateBasicGeometry() }; entities = { - std::make_shared(materials[1], shapes[0]), - std::make_shared(materials[2], shapes[1]), - std::make_shared(materials[3], shapes[2]), + std::make_shared(materials[1], shapes[3]), std::make_shared(materials[2], shapes[3]), - std::make_shared(materials[1], shapes[4]), - std::make_shared(materials[0], shapes[5]), - std::make_shared(materials[0], shapes[6]), + std::make_shared(materials[3], shapes[3]), + std::make_shared(materials[4], shapes[3]), + std::make_shared(materials[5], shapes[3]), + std::make_shared(materials[6], shapes[3]), + std::make_shared(materials[7], shapes[3]), + std::make_shared(materials[0], shapes[3]), }; - entities[6]->GetMaterial()->SetEmitAmount(0.75f); - for (int i = 0; i < entities.size(); ++i) { - entities[i]->GetTransform()->SetPosition((-(int)(entities.size() / 2) + i) * 5, 0, 0); - entities[i]->GetMaterial()->SetRoughness(0.60f); + entities[i]->GetTransform()->SetPosition((-(int)(entities.size() / 2) + i + 0.5f) * 2.5f, 0, 0); } skybox = std::make_shared( - shapes[0], - std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxVertexShader.cso").c_str()), - std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxPixelShader.cso").c_str()), - demoCubemap, - sampler, - device - ); + shapes[0], + std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxVertexShader.cso").c_str()), + std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxPixelShader.cso").c_str()), + demoCubemap, + sampler, + device + ); } diff --git a/Game.h b/Game.h index ceed40c..acac3b8 100644 --- a/Game.h +++ b/Game.h @@ -47,6 +47,8 @@ private: // Shaders and shader-related constructs std::shared_ptr pixelShader; std::shared_ptr vertexShader; + std::shared_ptr pixelShaderPBR; + std::shared_ptr vertexShaderPBR; // A2 shapes std::vector> shapes; diff --git a/Helpers.hlsli b/Helpers.hlsli index 4e9a634..ff263fa 100644 --- a/Helpers.hlsli +++ b/Helpers.hlsli @@ -4,6 +4,12 @@ // from environment map demo static const float F0_NON_METAL = 0.04f; +// Minimum roughness for when spec distribution function denominator goes to zero +static const float MIN_ROUGHNESS = 0.0000001f; // 6 zeros after decimal + +// Handy to have this as a constant +static const float PI = 3.14159265359f; + // gets view vector, needed once per shader float3 getView(float3 cameraPosition, float3 pixelWorldPosition) { diff --git a/HelpersPBR.hlsli b/HelpersPBR.hlsli new file mode 100644 index 0000000..da7acfe --- /dev/null +++ b/HelpersPBR.hlsli @@ -0,0 +1,104 @@ +#ifndef __SHADER_HELPERS_PBR__ +#define __SHADER_HELPERS_PBR__ + +// Lambert diffuse BRDF - Same as the basic lighting diffuse calculation! +// - NOTE: this function assumes the vectors are already NORMALIZED! +float DiffusePBR(float3 normal, float3 dirToLight) +{ + return saturate(dot(normal, dirToLight)); +} + +// Calculates diffuse amount based on energy conservation +// +// diffuse - Diffuse amount +// specular - Specular color (including light color) +// metalness - surface metalness amount +// +// Metals should have an albedo of (0,0,0)...mostly +// See slide 65: http://blog.selfshadow.com/publications/s2014-shading-course/hoffman/s2014_pbs_physics_math_slides.pdf +float3 DiffuseEnergyConserve(float3 diffuse, float3 specular, float metalness) +{ + return diffuse * ((1 - saturate(specular)) * (1 - metalness)); +} + +// GGX (Trowbridge-Reitz) +// +// a - Roughness +// h - Half vector +// n - Normal +// +// D(h, n) = a^2 / pi * ((n dot h)^2 * (a^2 - 1) + 1)^2 +float SpecDistribution(float3 n, float3 h, float roughness) +{ + // Pre-calculations + float NdotH = saturate(dot(n, h)); + float NdotH2 = NdotH * NdotH; + float a = roughness * roughness; + float a2 = max(a * a, MIN_ROUGHNESS); // Applied after remap! + + // ((n dot h)^2 * (a^2 - 1) + 1) + float denomToSquare = NdotH2 * (a2 - 1) + 1; + // Can go to zero if roughness is 0 and NdotH is 1; MIN_ROUGHNESS helps here + + // Final value + return a2 / (PI * denomToSquare * denomToSquare); +} + +// Fresnel term - Schlick approx. +// +// v - View vector +// h - Half vector +// f0 - Value when l = n (full specular color) +// +// F(v,h,f0) = f0 + (1-f0)(1 - (v dot h))^5 +float3 Fresnel(float3 v, float3 h, float3 f0) +{ + // Pre-calculations + float VdotH = saturate(dot(v, h)); + + // Final value + return f0 + (1 - f0) * pow(1 - VdotH, 5); +} + +// Geometric Shadowing - Schlick-GGX (based on Schlick-Beckmann) +// - k is remapped to a / 2, roughness remapped to (r+1)/2 +// +// n - Normal +// v - View vector +// +// G(l,v) +float GeometricShadowing(float3 n, float3 v, float roughness) +{ + // End result of remapping: + float k = pow(roughness + 1, 2) / 8.0f; + float NdotV = saturate(dot(n, v)); + + // Final value + return NdotV / (NdotV * (1 - k) + k); +} + +// Microfacet BRDF (Specular) +// +// f(l,v) = D(h)F(v,h)G(l,v,h) / 4(n dot l)(n dot v) +// - part of the denominator are canceled out by numerator (see below) +// +// D() - Spec Dist - Trowbridge-Reitz (GGX) +// F() - Fresnel - Schlick approx +// G() - Geometric Shadowing - Schlick-GGX +float3 MicrofacetBRDF(float3 n, float3 l, float3 v, float roughness, float3 specColor) +{ + // Other vectors + float3 h = normalize(v + l); + + // Grab various functions + float D = SpecDistribution(n, h, roughness); + float3 F = Fresnel(v, h, specColor); + float G = GeometricShadowing(n, v, roughness) * GeometricShadowing(n, l, roughness); + + // Final formula + // Denominator dot products partially canceled by G()! + // See page 16: http://blog.selfshadow.com/publications/s2012-shading-course/hoffman/s2012_pbs_physics_math_notes.pdf + return (D * F * G) / (4 * max(dot(n, v), dot(n, l))); +} + +#endif \ No newline at end of file diff --git a/LightsPBR.hlsli b/LightsPBR.hlsli new file mode 100644 index 0000000..939c496 --- /dev/null +++ b/LightsPBR.hlsli @@ -0,0 +1,29 @@ +#ifndef __SHADER_LIGHTS_PBR__ +#define __SHADER_LIGHTS_PBR__ + +// Gets the RGB value of a pixel with a directional light +float3 directionalLightPBR(Light light, float3 normal, float3 view, float roughness, float metalness, float3 surfaceColor, float3 specularColor) +{ + float3 lightDirection = normalize(light.Direction); + float diffuse = DiffusePBR(normal, lightDirection); + float3 specular = MicrofacetBRDF(normal, lightDirection, view, roughness, specularColor); + + float3 balancedDiff = DiffuseEnergyConserve(diffuse, specular, metalness); + + return (balancedDiff * surfaceColor + specular) * light.Intensity * light.Color; +} + +// Gets the RGB value of a pixel with a point light +float3 pointLightPBR(Light light, float3 normal, float3 view, float roughness, float metalness, float3 surfaceColor, float3 specularColor, float3 worldPosition) +{ + float3 lightDirection = normalize(light.Position - worldPosition); + float attenuation = getAttenuation(light.Position, worldPosition, light.Range); + float diffuse = DiffusePBR(normal, lightDirection); + float3 specular = MicrofacetBRDF(normal, lightDirection, view, roughness, specularColor); + + float3 balancedDiff = DiffuseEnergyConserve(diffuse, specular, metalness); + + return (balancedDiff * surfaceColor + specular) * attenuation * light.Intensity * light.Color; +} + +#endif diff --git a/Material.cpp b/Material.cpp index 9ca9fbd..1186d06 100644 --- a/Material.cpp +++ b/Material.cpp @@ -1,11 +1,13 @@ #include "Material.h" Material::Material( + bool _pbr, DirectX::XMFLOAT3 _tint, float _roughness, std::shared_ptr _vertexShader, std::shared_ptr _pixelShader) { + pbr = _pbr; tint = _tint; roughness = _roughness; vertexShader = _vertexShader; @@ -25,37 +27,8 @@ Material::~Material() void Material::Activate(Transform* _transform, std::shared_ptr _camera, DirectX::XMFLOAT3 _ambient, std::vector _lights) { - vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix()); - vertexShader->SetMatrix4x4("worldInvTranspose", _transform->GetWorldMatrixInverseTranspose()); - vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix()); - vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix()); - vertexShader->CopyAllBufferData(); - vertexShader->SetShader(); - - pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); - pixelShader->SetFloat("roughness", GetRoughness()); - pixelShader->SetFloat2("scale", GetUVScale()); - pixelShader->SetFloat2("offset", GetUVOffset()); - pixelShader->SetFloat3("ambient", _ambient); - pixelShader->SetFloat("emitAmount", GetEmitAmount()); - pixelShader->SetFloat3("tint", GetTint()); - pixelShader->SetFloat("lightCount", (int)_lights.size()); - pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap); - pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap); - pixelShader->SetInt("hasNormalMap", (int)hasNormalMap); - pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap); - pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size()); - pixelShader->CopyAllBufferData(); - pixelShader->SetShader(); - - for (auto& t : textures) - { - pixelShader->SetShaderResourceView(t.first.c_str(), t.second.Get()); - } - for (auto& s : samplers) - { - pixelShader->SetSamplerState(s.first.c_str(), s.second.Get()); - } + if (pbr) ActivatePBR(_transform, _camera, _ambient, _lights); + else ActivateStandard(_transform, _camera, _ambient, _lights); } DirectX::XMFLOAT3 Material::GetTint() @@ -160,3 +133,65 @@ void Material::PushTexture(std::string _name, Microsoft::WRL::ComPtr _camera, DirectX::XMFLOAT3 _ambient, std::vector _lights) +{ + vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix()); + vertexShader->SetMatrix4x4("worldInvTranspose", _transform->GetWorldMatrixInverseTranspose()); + vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix()); + vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix()); + vertexShader->CopyAllBufferData(); + vertexShader->SetShader(); + + pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); + pixelShader->SetFloat("roughness", GetRoughness()); + pixelShader->SetFloat2("scale", GetUVScale()); + pixelShader->SetFloat2("offset", GetUVOffset()); + pixelShader->SetFloat3("ambient", _ambient); + pixelShader->SetFloat("emitAmount", GetEmitAmount()); + pixelShader->SetFloat3("tint", GetTint()); + pixelShader->SetFloat("lightCount", (int)_lights.size()); + pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap); + pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap); + pixelShader->SetInt("hasNormalMap", (int)hasNormalMap); + pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap); + pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size()); + pixelShader->CopyAllBufferData(); + pixelShader->SetShader(); + + for (auto& t : textures) + { + pixelShader->SetShaderResourceView(t.first.c_str(), t.second.Get()); + } + for (auto& s : samplers) + { + pixelShader->SetSamplerState(s.first.c_str(), s.second.Get()); + } +} + +void Material::ActivatePBR(Transform* _transform, std::shared_ptr _camera, DirectX::XMFLOAT3 _ambient, std::vector _lights) +{ + vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix()); + vertexShader->SetMatrix4x4("worldInvTranspose", _transform->GetWorldMatrixInverseTranspose()); + vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix()); + vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix()); + vertexShader->CopyAllBufferData(); + vertexShader->SetShader(); + + pixelShader->SetFloat2("scale", GetUVScale()); + pixelShader->SetFloat2("offset", GetUVOffset()); + pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); + pixelShader->SetFloat("lightCount", (int)_lights.size()); + pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size()); + pixelShader->CopyAllBufferData(); + pixelShader->SetShader(); + + for (auto& t : textures) + { + pixelShader->SetShaderResourceView(t.first.c_str(), t.second.Get()); + } + for (auto& s : samplers) + { + pixelShader->SetSamplerState(s.first.c_str(), s.second.Get()); + } +} diff --git a/Material.h b/Material.h index 3375880..9f1d5bd 100644 --- a/Material.h +++ b/Material.h @@ -2,6 +2,7 @@ #include #include +#include #include "DXCore.h" #include "SimpleShader.h" #include "Transform.h" @@ -14,11 +15,14 @@ constexpr auto TEXTYPE_NORMAL = "Normal"; constexpr auto TEXTYPE_EMISSIVE = "Emissive"; constexpr auto TEXTYPE_SPECULAR = "Specular"; constexpr auto TEXTYPE_REFLECTION = "Reflection"; +constexpr auto TEXTYPE_ROUGHNESS = "Roughness"; +constexpr auto TEXTYPE_METALNESS = "Metalness"; class Material { public: Material( + bool _pbr, DirectX::XMFLOAT3 _tint, float _roughness, std::shared_ptr _vertexShader, @@ -56,6 +60,18 @@ public: bool hasNormalMap; bool hasReflectionMap; private: + void ActivateStandard( + Transform* _transform, + std::shared_ptr _camera, + DirectX::XMFLOAT3 _ambient, + std::vector _lights); + void ActivatePBR( + Transform* _transform, + std::shared_ptr _camera, + DirectX::XMFLOAT3 _ambient, + std::vector _lights); + + bool pbr; DirectX::XMFLOAT3 tint; float roughness; float emitAmount; diff --git a/SimplePixelPBR.hlsl b/SimplePixelPBR.hlsl new file mode 100644 index 0000000..7bcfd8f --- /dev/null +++ b/SimplePixelPBR.hlsl @@ -0,0 +1,63 @@ +#include "Defines.hlsli" +#include "Helpers.hlsli" +#include "HelpersPBR.hlsli" +#include "Lights.hlsli" +#include "LightsPBR.hlsli" + +#define MAX_LIGHTS 128 + +cbuffer ExternalData : register(b0) +{ + float2 offset; + float2 scale; + + float3 cameraPosition; + float lightCount; + + Light lights[MAX_LIGHTS]; +} + +Texture2D Albedo : register(t0); +Texture2D Normal : register(t1); +Texture2D Roughness : register(t2); +Texture2D Metalness : register(t3); +TextureCube Reflection : register(t4); +SamplerState Sampler : register(s0); + +float4 main(VertexToPixel input) : SV_TARGET +{ + input.normal = normalize(input.normal); + input.tangent = normalize(input.tangent); + + float3 view = normalize(cameraPosition - input.worldPosition); + + float4 albedo = pow(Albedo.Sample(Sampler, input.uv), 2.2f); + + float3 N = Normal.Sample(Sampler, input.uv).rgb * 2 - 1; + float3 T = normalize(input.tangent - input.normal * dot(input.tangent, input.normal)); + float3 B = cross(T, input.normal); + float3x3 TBN = float3x3(T, B, input.normal); + input.normal = mul(N, TBN); + + float roughness = Roughness.Sample(Sampler, input.uv).r; + float metalness = Metalness.Sample(Sampler, input.uv).r; + float3 specular = lerp(F0_NON_METAL.rrr, albedo.rgb, metalness); + + float3 light = float3(0, 0, 0); + for (int i = 0; i < lightCount; i++) + { + switch (lights[i].Type) + { + case LIGHT_TYPE_DIRECTIONAL: + light += directionalLightPBR(lights[i], input.normal, view, roughness, metalness, albedo, specular); + break; + case LIGHT_TYPE_POINT: + light += pointLightPBR(lights[i], input.normal, view, roughness, metalness, albedo, specular, input.worldPosition); + break; + } + } + + float3 final = light; + + return float4(pow(final, 1.0f / 2.2f), albedo.a); +} \ No newline at end of file diff --git a/SimplePixelShader.hlsl b/SimplePixelShader.hlsl index 7c986d6..7427528 100644 --- a/SimplePixelShader.hlsl +++ b/SimplePixelShader.hlsl @@ -52,7 +52,7 @@ float4 main(VertexToPixel input) : SV_TARGET // view only needs calculated once, so pre-calculate here and pass it to lights float3 view = getView(cameraPosition, input.worldPosition); - float4 albedo = Albedo.Sample(BasicSampler, input.uv).rgba; + float4 albedo = pow(Albedo.Sample(BasicSampler, input.uv).rgba, 2.2f); float specular = 1; if (hasSpecularMap > 0) specular = Specular.Sample(BasicSampler, input.uv).r; float3 emit = float3(1, 1, 1); @@ -83,5 +83,5 @@ float4 main(VertexToPixel input) : SV_TARGET final = lerp(final, reflCol, getFresnel(input.normal, view, F0_NON_METAL)); } - return float4(final, albedo.a); + return float4(pow(final, 1.0f/2.2f), albedo.a); } diff --git a/SimpleVertexPBR.hlsl b/SimpleVertexPBR.hlsl new file mode 100644 index 0000000..f1c97c0 --- /dev/null +++ b/SimpleVertexPBR.hlsl @@ -0,0 +1,24 @@ +#include "Defines.hlsli" + +cbuffer ExternalData : register(b0) +{ + matrix world; + matrix worldInvTranspose; + matrix view; + matrix projection; +} + +VertexToPixel main(VertexShaderInput input) +{ + VertexToPixel output; + + matrix worldViewProjection = mul(projection, mul(view, world)); + output.screenPosition = mul(worldViewProjection, float4(input.localPosition, 1.0f)); + + output.uv = input.uv; + output.normal = normalize(mul((float3x3)worldInvTranspose, input.normal)); + output.tangent = normalize(mul((float3x3)worldInvTranspose, input.tangent)); + output.worldPosition = mul(world, float4(input.localPosition, 1)).xyz; + + return output; +}