Skip to content

Commit 9afa1de

Browse files
Revert "* 修改深度检测为less,默认深度值为1(因为我们已经把坐标系改成了左手坐标系)"
This reverts commit 5a7a0c2.
1 parent 5a7a0c2 commit 9afa1de

File tree

7 files changed

+4
-95252
lines changed

7 files changed

+4
-95252
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
\x64
3535
*.user
3636

37-
# nuget
38-
\packages
39-
4037
# =========================
4138
# Operating System Files
4239
# =========================

Chapter 11 Stenciling/Core/Graphics/GraphicsCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void Graphics::InitializeCommonState(void)
159159
DepthStateReadWrite = DepthStateDisabled;
160160
DepthStateReadWrite.DepthEnable = TRUE;
161161
DepthStateReadWrite.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
162-
DepthStateReadWrite.DepthFunc = D3D12_COMPARISON_FUNC_LESS;
162+
DepthStateReadWrite.DepthFunc = D3D12_COMPARISON_FUNC_GREATER_EQUAL;
163163

164164
DepthStateReadOnly = DepthStateReadWrite;
165165
DepthStateReadOnly.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO;

Chapter 11 Stenciling/Core/Graphics/Resource/DepthBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EsramAllocator;
2929
class DepthBuffer : public PixelBuffer
3030
{
3131
public:
32-
DepthBuffer( float ClearDepth = 1.0f, uint8_t ClearStencil = 0 )
32+
DepthBuffer( float ClearDepth = 0.0f, uint8_t ClearStencil = 0 )
3333
: m_ClearDepth(ClearDepth), m_ClearStencil(ClearStencil)
3434
{
3535
m_hDSV[0].ptr = D3D12_GPU_VIRTUAL_ADDRESS_UNKNOWN;

Chapter 11 Stenciling/GameApp.cpp

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,6 @@ void GameApp::Update(float deltaT)
144144
m_MainScissor.top = 0;
145145
m_MainScissor.right = (LONG)Graphics::g_SceneColorBuffer.GetWidth();
146146
m_MainScissor.bottom = (LONG)Graphics::g_SceneColorBuffer.GetHeight();
147-
148-
updateSkull(deltaT);
149-
}
150-
151-
void GameApp::updateSkull(float deltaT)
152-
{
153-
if (GameInput::IsPressed(GameInput::kKey_a))
154-
mSkullTranslation -= { 1.0f * deltaT, 0.0f, 0.0f };
155-
156-
if (GameInput::IsPressed(GameInput::kKey_d))
157-
mSkullTranslation += { 1.0f * deltaT, 0.0f, 0.0f };
158-
159-
if (GameInput::IsPressed(GameInput::kKey_w))
160-
mSkullTranslation += { 0.0f, 1.0f * deltaT, 0.0f };
161-
162-
if (GameInput::IsPressed(GameInput::kKey_s))
163-
mSkullTranslation -= { 0.0f, 1.0f * deltaT, 0.0f };
164-
165-
// y坐标不允许低于地板
166-
float y = (float)mSkullTranslation.GetY();
167-
if (y < 0.0f)
168-
mSkullTranslation.SetY(0.0f);
169-
170-
// 更新最新的skull世界矩阵
171-
auto rotationMatrix = Math::AffineTransform::MakeYRotation(Math::XM_PIDIV2);
172-
auto scallMatrix = Math::AffineTransform::MakeScale({ 0.45f, 0.45f, 0.45f });
173-
auto translateMatrix = Math::AffineTransform::MakeTranslation(mSkullTranslation);
174-
mSkullRitem->modeToWorld = Math::Transpose(Math::Matrix4(translateMatrix * scallMatrix * rotationMatrix));
175147
}
176148

177149
void GameApp::RenderScene(void)
@@ -346,59 +318,7 @@ void GameApp::buildRoomGeo()
346318

347319
void GameApp::buildSkullGeo()
348320
{
349-
std::ifstream fin("Models/skull.txt");
350-
351-
if (!fin)
352-
{
353-
MessageBox(0, L"Models/skull.txt not found.", 0, 0);
354-
return;
355-
}
356-
357-
UINT vcount = 0;
358-
UINT tcount = 0;
359-
std::string ignore;
360-
361-
fin >> ignore >> vcount;
362-
fin >> ignore >> tcount;
363-
fin >> ignore >> ignore >> ignore >> ignore;
364-
365-
std::vector<Vertex> vertices(vcount);
366-
for (UINT i = 0; i < vcount; ++i)
367-
{
368-
fin >> vertices[i].Pos.x >> vertices[i].Pos.y >> vertices[i].Pos.z;
369-
fin >> vertices[i].Normal.x >> vertices[i].Normal.y >> vertices[i].Normal.z;
370-
371-
// Model does not have texture coordinates, so just zero them out.
372-
vertices[i].TexC = { 0.0f, 0.0f };
373-
}
374-
375-
fin >> ignore;
376-
fin >> ignore;
377-
fin >> ignore;
378-
379-
std::vector<std::int32_t> indices(3 * tcount);
380-
for (UINT i = 0; i < tcount; ++i)
381-
{
382-
fin >> indices[i * 3 + 0] >> indices[i * 3 + 1] >> indices[i * 3 + 2];
383-
}
384-
385-
fin.close();
386-
387-
388-
auto geo = std::make_unique<MeshGeometry>();
389-
geo->name = "skullGeo";
390-
391-
geo->createVertex(L"skull vertex", (UINT)vertices.size(), sizeof(Vertex), vertices.data());
392-
geo->createIndex(L"skull index", (UINT)indices.size(), sizeof(std::int32_t), indices.data());
393-
394-
SubmeshGeometry submesh;
395-
submesh.IndexCount = (UINT)indices.size();
396-
submesh.StartIndexLocation = 0;
397-
submesh.BaseVertexLocation = 0;
398-
399-
geo->geoMap["skull"] = submesh;
400-
401-
m_mapGeometries[geo->name] = std::move(geo);
321+
402322
}
403323

404324
void GameApp::buildMaterials()
@@ -426,17 +346,9 @@ void GameApp::buildMaterials()
426346
icemirror->roughness = 0.5f;
427347
icemirror->srv = TextureManager::LoadFromFile(L"ice", true)->GetSRV();
428348

429-
auto skullMat = std::make_unique<Material>();
430-
skullMat->name = "skullMat";
431-
skullMat->diffuseAlbedo = { 1.0f, 1.0f, 1.0f, 1.0f };
432-
skullMat->fresnelR0 = { 0.05f, 0.05f, 0.05f };
433-
skullMat->roughness = 0.3f;
434-
skullMat->srv = TextureManager::LoadFromFile(L"white1x1", true)->GetSRV();
435-
436349
m_mapMaterial["bricks"] = std::move(bricks);
437350
m_mapMaterial["checkertile"] = std::move(checkertile);
438351
m_mapMaterial["icemirror"] = std::move(icemirror);
439-
m_mapMaterial["skullMat"] = std::move(skullMat);
440352
}
441353

442354
void GameApp::buildRenderItem()
@@ -467,14 +379,4 @@ void GameApp::buildRenderItem()
467379
mirrorRItem->geo = m_mapGeometries["roomGeo"].get();
468380
mirrorRItem->mat = m_mapMaterial["icemirror"].get();
469381
m_vecRenderItems[(int)RenderLayer::Opaque].push_back(std::move(mirrorRItem));
470-
471-
// skull
472-
auto skullRItem = std::make_unique<RenderItem>();
473-
skullRItem->IndexCount = m_mapGeometries["skullGeo"]->geoMap["skull"].IndexCount;
474-
skullRItem->StartIndexLocation = m_mapGeometries["skullGeo"]->geoMap["skull"].StartIndexLocation;
475-
skullRItem->BaseVertexLocation = m_mapGeometries["skullGeo"]->geoMap["skull"].BaseVertexLocation;
476-
skullRItem->geo = m_mapGeometries["skullGeo"].get();
477-
skullRItem->mat = m_mapMaterial["skullMat"].get();
478-
mSkullRitem = skullRItem.get();
479-
m_vecRenderItems[(int)RenderLayer::Opaque].push_back(std::move(skullRItem));
480382
}

Chapter 11 Stenciling/GameApp.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class GameApp : public GameCore::IGameApp
2828
void buildMaterials();
2929
void buildRenderItem();
3030

31-
void updateSkull(float deltaT);
32-
3331
void drawRenderItems(GraphicsContext& gfxContext, std::vector<std::unique_ptr<RenderItem>>& ritems);
3432

3533
private:
@@ -61,10 +59,6 @@ class GameApp : public GameCore::IGameApp
6159
};
6260
std::unordered_map<int, GraphicsPSO> m_mapPSO;
6361

64-
// render item skull point
65-
RenderItem* mSkullRitem = nullptr;
66-
Math::Vector3 mSkullTranslation = { 0.0f, 1.0f, -5.0f };
67-
6862
// 摄像机
6963
// 以(0, 0, -m_radius) 为初始位置
7064
Math::Camera m_Camera;
@@ -76,7 +70,7 @@ class GameApp : public GameCore::IGameApp
7670
float m_radius = 27.0f;
7771

7872
// x方向弧度,摄像机的x坐标增加,则m_xRotate增加
79-
float m_xRotate = -Math::XM_PIDIV4 / 2.0f;
73+
float m_xRotate = 0.0f;
8074
float m_xLast = 0.0f;
8175
float m_xDiff = 0.0f;
8276

0 commit comments

Comments
 (0)