Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MKXJun committed Feb 25, 2023
2 parents 191146b + f892dc4 commit 51d02db
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 12 deletions.
6 changes: 6 additions & 0 deletions MarkdownFiles/Updates/Updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
- ModelManager初步支持PBR
- 调整Material类

2023/2/25 Ver2.38.4

- 修复项目32的报错问题
- 处理Transform获取欧拉角时的死锁问题
- EffectHelper类少量调整

2022/9/3 Ver2.38.3

- 调整d3dFormat.h
Expand Down
11 changes: 10 additions & 1 deletion Project 10-17/Common/Transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,21 @@ void Transform::LookTo(const XMFLOAT3& direction, const XMFLOAT3& up)

XMFLOAT3 Transform::GetEulerAnglesFromRotationMatrix(const XMFLOAT4X4& rotationMatrix)
{
DirectX::XMFLOAT3 rotation{};
// 死锁特殊处理
if (fabs(1.0f - fabs(rotationMatrix(2, 1))) < 1e-5f)
{
rotation.x = copysignf(DirectX::XM_PIDIV2, -rotationMatrix(2, 1));
rotation.y = -atan2f(rotationMatrix(0, 2), rotationMatrix(0, 0));
return rotation;
}

// 通过旋转矩阵反求欧拉角
float c = sqrtf(1.0f - rotationMatrix(2, 1) * rotationMatrix(2, 1));
// 防止r[2][1]出现大于1的情况
if (isnan(c))
c = 0.0f;
XMFLOAT3 rotation;

rotation.z = atan2f(rotationMatrix(0, 1), rotationMatrix(1, 1));
rotation.x = atan2f(-rotationMatrix(2, 1), c);
rotation.y = atan2f(rotationMatrix(2, 0), rotationMatrix(2, 2));
Expand Down
3 changes: 1 addition & 2 deletions Project 10-17/Common/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ class Transform
// 沿着某一方向观察
void LookTo(const DirectX::XMFLOAT3& direction, const DirectX::XMFLOAT3& up = { 0.0f, 1.0f, 0.0f });

private:
// 从旋转矩阵获取旋转欧拉角
DirectX::XMFLOAT3 GetEulerAnglesFromRotationMatrix(const DirectX::XMFLOAT4X4& rotationMatrix);
static DirectX::XMFLOAT3 GetEulerAnglesFromRotationMatrix(const DirectX::XMFLOAT4X4& rotationMatrix);

private:
DirectX::XMFLOAT3 m_Scale = { 1.0f, 1.0f, 1.0f }; // 缩放
Expand Down
2 changes: 2 additions & 0 deletions Project 19-/32 SSAO/ShadowEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ void ShadowEffect::SetMaterial(const Material& material)
MeshDataInput ShadowEffect::GetInputData(const MeshData& meshData)
{
MeshDataInput input;
input.pInputLayout = pImpl->m_pCurrInputLayout.Get();
input.topology = pImpl->m_CurrTopology;
input.pVertexBuffers = {
meshData.m_pVertices.Get(),
meshData.m_pNormals.Get(),
Expand Down
2 changes: 2 additions & 0 deletions Project 19-/32 SSAO/SkyboxEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ void XM_CALLCONV SkyboxEffect::SetProjMatrix(DirectX::FXMMATRIX P)
MeshDataInput SkyboxEffect::GetInputData(const MeshData& meshData)
{
MeshDataInput input;
input.pInputLayout = pImpl->m_pCurrInputLayout.Get();
input.topology = pImpl->m_CurrTopology;
input.pVertexBuffers = {
meshData.m_pVertices.Get(),
meshData.m_pNormals.Get(),
Expand Down
7 changes: 7 additions & 0 deletions Project 19-/Common/EffectHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,13 @@ HRESULT EffectHelper::Impl::UpdateShaderReflection(std::string_view name, ID3D11
m_CBuffers.emplace(std::make_pair(sibDesc.BindPoint, CBufferData(sibDesc.Name, sibDesc.BindPoint, cbDesc.Size, nullptr)));
m_CBuffers[sibDesc.BindPoint].CreateBuffer(device);
}
// 存在不同shader间的cbuffer大小不一致的情况,应当以最大的为准
// 例如当前shader通过宏开启了cbuffer最后一个变量导致多一个16 bytes,而另一个shader关闭了该变量
else if (it->second.cbufferData.size() < cbDesc.Size)
{
m_CBuffers[sibDesc.BindPoint] = CBufferData(sibDesc.Name, sibDesc.BindPoint, cbDesc.Size, nullptr);
m_CBuffers[sibDesc.BindPoint].CreateBuffer(device);
}

// 标记该着色器使用了当前常量缓冲区
if (cbDesc.Variables > 0)
Expand Down
28 changes: 22 additions & 6 deletions Project 19-/Common/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ class Transform
float cosZ_cosX = 1 - 2 * (m_Rotation.x * m_Rotation.x + m_Rotation.z * m_Rotation.z);

DirectX::XMFLOAT3 rotation;
if (fabs(sinX) >= 1.0f)
// 死锁特殊处理
if (fabs(sinX - 1.0f) < 1e-5f)
{
rotation.x = copysignf(DirectX::XM_PI / 2, sinX);
rotation.y = 2.0f * atan2f(m_Rotation.y, m_Rotation.w);
rotation.z = 0.0f;
}
else
{
rotation.x = asinf(sinX);
rotation.y = atan2f(sinY_cosX, cosY_cosX);
rotation.z = atan2f(sinZ_cosX, cosZ_cosX);
rotation.y = atan2f(sinY_cosX, cosY_cosX);
rotation.z = atan2f(sinZ_cosX, cosZ_cosX);
}

return rotation;
}
Expand Down Expand Up @@ -229,16 +236,25 @@ class Transform
XMMATRIX InvView = XMMatrixInverse(nullptr, View);
XMStoreFloat4(&m_Rotation, XMQuaternionRotationMatrix(InvView));
}
private:

// 从旋转矩阵获取旋转欧拉角
DirectX::XMFLOAT3 GetEulerAnglesFromRotationMatrix(const DirectX::XMFLOAT4X4& rotationMatrix)
static DirectX::XMFLOAT3 GetEulerAnglesFromRotationMatrix(const DirectX::XMFLOAT4X4& rotationMatrix)
{
DirectX::XMFLOAT3 rotation{};
// 死锁特殊处理
if (fabs(1.0f - fabs(rotationMatrix(2, 1))) < 1e-5f)
{
rotation.x = copysignf(DirectX::XM_PIDIV2, -rotationMatrix(2, 1));
rotation.y = -atan2f(rotationMatrix(0, 2), rotationMatrix(0, 0));
return rotation;
}

// 通过旋转矩阵反求欧拉角
float c = sqrtf(1.0f - rotationMatrix(2, 1) * rotationMatrix(2, 1));
// 防止r[2][1]出现大于1的情况
if (isnan(c))
c = 0.0f;
DirectX::XMFLOAT3 rotation{};

rotation.z = atan2f(rotationMatrix(0, 1), rotationMatrix(1, 1));
rotation.x = atan2f(-rotationMatrix(2, 1), c);
rotation.y = atan2f(rotationMatrix(2, 0), rotationMatrix(2, 2));
Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

### 命令行构建

在Win10系统下,若安装cmake的时候添加了环境变量,则可以直接运行`build_msvc.cmd`来生成项目并构建项目,完成后打开build文件夹可以找到解决方案
在Win10系统下,若安装cmake的时候添加了环境变量,则可以直接运行`build_msvc.cmd`来生成项目并构建项目,完成后打开build文件夹可以找到解决方案,然后切换到Release x64就可以直接运行。

### GUI构建

Expand Down Expand Up @@ -71,7 +71,25 @@

作为教程演示项目,这里并不是以实现一个软引擎为目标。建议读者在跟随教程学习的同时要动手实践。

## 打包教程示例程序

以项目31的程序(Release x64)为例,其文件结构应为:

```cpp
Project 31
|----Model/ (挑出项目用到的模型)
|----Texture/ (挑出项目用到的纹理)
|----31 Shadow Mapping/ (此处命名自由发挥,比如bin)
|----31 Shadow Mapping.exe
|----imgui.ini
|----assimp-vc14*-mt.dll (从build/Assimp/bin/Release(或Debug)复制一份)
|----Shaders/
```



## 支持/赞赏博主

**博客和项目维护不易,如果本系列教程对您有所帮助,希望能够扫码支持一下博主。**

![](MarkdownFiles/002.png)![](MarkdownFiles/003.png)
Expand All @@ -82,7 +100,7 @@

## 最近更新

2022/9/7 Ver2.39.0
2022/9/7 Ver2.39.0(未公开master)

- **添加项目 PBR,目前仅支持延迟渲染**
- 调整TextureMnager的读取配置选项,初步支持HDR
Expand All @@ -93,4 +111,9 @@
- ModelManager初步支持PBR
- 调整Material类

2023/2/25 Ver2.38.4
- 修复项目32的报错问题
- 处理Transform获取欧拉角时的死锁问题
- EffectHelper类少量调整

**[历史更新记录](MarkdownFiles/Updates/Updates.md)**
5 changes: 4 additions & 1 deletion build_msvc.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@echo off

cmake -S . -B build
cmake --build build --config Release -- -m
cd build
del /S/Q *.cso
cmake --build . --config Release -- -m
cd ..

0 comments on commit 51d02db

Please sign in to comment.