Skip to content

Commit 6de007b

Browse files
+ 添加箱子的alpha绘制
* 箱子的alpha绘制,需要修改ps shader,alpha值小于0.1的就不输出颜色了。 * 对于这种绘制需求,因为需要看到透过去的部分,添加一个不做背面剔除的PSO * GraphicsCore再调用update时的入参,在关闭了垂直同步的情况下,第二次的update会传入一个极大值。 对变量s_FrameStartTick添加初始化
1 parent 12ee999 commit 6de007b

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

Chapter 10 Blending/Core/Graphics/GraphicsCore.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ bool Graphics::Initialize(void)
525525
// GraphRenderer::Initialize();
526526
// ParticleEffects::Initialize(kMaxNativeWidth, kMaxNativeHeight);
527527

528+
s_FrameStartTick = SystemTime::GetCurrentTick();;
528529
return true;
529530
}
530531

Chapter 10 Blending/Core/Shaders/defaultPS.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ float4 main(VertexOut pin) : SV_Target0
5959
{
6060
float4 diffuseAlbedo = gDiffuseMap.Sample(gsamAnisotropicWrap, pin.TexC) * gDiffuseAlbedo;
6161

62+
// ͸Ã÷ÏñËØµãÌÞ³ý
63+
// Discard pixel if texture alpha < 0.1. We do this test as soon
64+
// as possible in the shader so that we can potentially exit the
65+
// shader early, thereby skipping the rest of the shader code.
66+
clip(diffuseAlbedo.a - 0.1f);
67+
6268
// Interpolating normal can unnormalize it, so renormalize it.
6369
pin.NormalW = normalize(pin.NormalW);
6470

Chapter 10 Blending/GameApp.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ void GameApp::Startup(void)
8181
wireFramPSO.SetRasterizerState(raster);
8282
wireFramPSO.Finalize();
8383
m_mapPSO[E_EPT_WIREFRAME] = wireFramPSO;
84+
85+
// alpha test PSO
86+
// 对于本例箱子一些面是透明的,要求显示到背面的东西
87+
GraphicsPSO alphaTestPSO = defaultPSO;
88+
raster = Graphics::RasterizerDefault;
89+
raster.CullMode = D3D12_CULL_MODE_NONE;
90+
alphaTestPSO.SetRasterizerState(raster);
91+
alphaTestPSO.Finalize();
92+
m_mapPSO[E_EPT_ALPHATEST] = alphaTestPSO;
8493
}
8594

8695
void GameApp::Cleanup(void)
@@ -418,7 +427,7 @@ void GameApp::buildLandAndWaves()
418427
const ManagedTexture* MatTextures[3] = {};
419428
MatTextures[0] = TextureManager::LoadFromFile(L"grass", true);
420429
MatTextures[1] = TextureManager::LoadFromFile(L"water1", true);
421-
MatTextures[2] = TextureManager::LoadFromFile(L"WoodCrate01", true);
430+
MatTextures[2] = TextureManager::LoadFromFile(L"WireFence", true);
422431

423432
GeometryGenerator geoGen;
424433
GeometryGenerator::MeshData grid = geoGen.CreateGrid(160.0f, 160.0f, 50, 50);
@@ -594,6 +603,8 @@ void GameApp::renderLandAndWaves(GraphicsContext& gfxContext)
594603

595604
setShaderParam(gfxContext, m_renderItemBox);
596605

606+
gfxContext.SetPipelineState(m_mapPSO[E_EPT_ALPHATEST]);
607+
597608
// 绘制
598609
gfxContext.DrawIndexedInstanced(m_IndexBufferBox.GetElementCount(), 1, 0, 0, 0);
599610
}

Chapter 10 Blending/GameApp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ class GameApp : public GameCore::IGameApp
6464
enum ePSOType
6565
{
6666
E_EPT_DEFAULT = 1,
67-
E_EPT_WIREFRAME = 2
67+
E_EPT_WIREFRAME = 2,
68+
E_EPT_ALPHATEST = 3,
6869
};
6970
std::unordered_map<int, GraphicsPSO> m_mapPSO;
7071

71-
bool m_bRenderShapes = true;
72+
bool m_bRenderShapes = false;
7273
bool m_bRenderFill = true;
7374

7475
// shapes
341 KB
Binary file not shown.

0 commit comments

Comments
 (0)