์ ๋ด์ฉ์ ๋ง์ถฐ ๋ฒํ ์ค๋ฅผ ๋ง๋ค์ด๋ณด์. ์ธ๋ฑ์ค๋ ์๋ตํจ.
float stackheight = height / stackCount;
// ํ ์ธต ์์ ๋๋ฏธ๋ก ์ฌ๋ผ ๊ฐ ๋์ ๋ฐ์ง๋ฅผ ๋ณํ๋
float radiusStep = (topRadius - bottomRadius) / stackCount;
uint32 ringCount = stackCount + 1;
for( uint32 i = 0; i < ringCount; ++i )
{
float y = - 0.5f + i * stackHeight;
float r = bottomRadius + i * radiusStep;
float dTheta = 2.0f * XM_PI/sliceCount;
for(uint32 j = 0; j <=sliceCount; ++j)
{
Vertex vertex;
float c = cosf(j*dTheta);
float s = sinf(j*dTheta);
vertex.Position = XMFLOAT3(r*c, y, r*s);
vertex.TangentU = XMFLOAT3(-s, 0.0f, c);
float dr = bottomRadius - topRadius;
XMFLOAT3 bitangent(dr*c, -height, dr*s);
XMVECTOR T = XMLoadFloat3(&vertex.TangentU);
XMVECTOR B = XMLoadFloat3(&bitangent);
XMVECTOR N = XMVertor3Normalize(XMVector3Cross(T,B));
}
}
์์ ๊ฐ์ด ์ ์ ์ ๊ตฌํ๊ณ ์ธ๋ฑ์ค๋ฅผ ์ฐ์๋ค๋ฉด ๋ฐฐ์ด์ ๋ด์ ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ฌ๋ผ๊ณ GPU์๊ฒ ์์ฒญํด์ผํ๋ค. DirectX12์์ GPU์๊ฒ ์์ฒญํ๋ ๊ณผ์ ์ ์์๋ณด์.
์ด์ ์ [Prev]CommandList๋ฅผ CommandQueue(GPU๊ฐ ์คํํ๋๋ก)์ ์ ์ถํ๊ณ ์๋กญ๊ฒ ๊ทธ๋ฆด ๋ช ๋ น๋ค์ [New]CommandList์ ๋ด์ CommnadQueue์ ์ ์ถํ๋ ๊ณผ์ ์ ์ ๋ฆฌํ๊ณ ์ดํดํด๋ณด์. ์๋๋ Draw์ ๊ณผ์ ์ ๋จ์ํ๊ฒ ๊ทธ๋ฆผ์ผ๋ก ๋ํ๋ด๋ณด์๋ค.
1.ExecuteCommandList๋ฅผ ํตํด ์ปค๋งจ๋ ํ์ ์ ์ถํ ๋ค์์ ์ปค๋งจ๋ ๋ฆฌ์คํธ๋ฅผ ๋ฆฌ์ ํ ์ ์๋ค.
2. ๋ค์ GPU์ ์ ์ถํ commandList๋ฅผ ์์ฑํ๊ธฐ ์ ์ ๋ฆฌ์คํธ๋ฆฌ ID3D12GraphicsCommandList::Reset() ํด์ค๋ค.
3. commandList์ ๋ ๋๋ง์ ์ํ ๊ณผ์ ํจ์๋ฅผ ์คํํ์ฌ ๋ฆฌ์คํธ์ ๋ฃ๋๋ค.
[ Command List ๋ํ ํจ์ /* ์์ ์ค์ */ ]
A : ID3D12GraphicsCommandList::RSSetViewports( 1, &D3D12_VIEWPORT )
B : ID3D12GraphicsCommandList::RSSetScissorRects( 1, & D3D12_RECT )
C : ID3D12GraphicsCommandList::ResourceBarrier (1, &CD3DX12_RESOURCE_BARRIER::Transition(CurrentBackBuffer(),
D3D12_RESOURCE_STATE_PRESENT,
D3D12_RESOURCE_STATE_RENDER_TARGET));
๋ฆฌ์์ค์ ์ํ๋ฅผ ๋ ๋๋ง์ ํ ์ ์๋๋ก ๋ณ๊ฒฝํจ. (๋ฆฌ์์ค ์ํ๋ฅผ ์ฅ๋ฒฝ์ ์ฌ์ฉํ์ฌ ๋๊ธฐํ ํจ.)
* CD3DX12_RESOURCE_BARRIER::Transition
์ ํ ์ฅ๋ฒฝ: ์๋ก ๋ค๋ฅธ ์ฌ์ฉ๊ฐ์ ์ ํํจ์ ๋ํ๋.
์ ์์ ๋ ๋ฐฑ ๋ฒํผ๊ฐ ๋ ๋๋ง ๋์์ผ๋ก ์ฌ์ฉ๋จ์ ๋ํ๋.
D : ID3D12GraphicsCommandList::ClearRenderTargetView( )
E : ID3D12GraphicsCommandList::ClearDepthStencilView( )
๋ฐฑ ๋ฒํผ์ ๋์ค ๋ฒํผ๋ฅผ ํด๋ฆฌ์ด ํจ.
F : ID3D12GraphicsCommandList::OMSetRenderTargets( )
์ด๋์ ๋ ๋๋ง์ ํ ์ง ์ค์ ํจ.
G : ID3D12GraphicsCommandList::SetDescriptorHeaps( )
H : ID3D12GraphicsCommandList::SetGraphicsRootSignature( )
I : ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable( )
********* Draw **********
ID3D12GraphicsCommandList::IASetVertexBuffers ( )
ID3D12GraphicsCommandList::IASetIndexBuffer ( )
ID3D12GraphicsCommandList::IASetPrimitiveTopology ( )
์ ์ ์๋ฃ๋ฅผ ์ด์ฉํ์ฌ ๊ธฐํํ์ ๊ธฐ๋ณธ ๋ํ์ ํ์ฑํ๋ ๋ฐฉ๋ฒ์ ์ค์ ํด์ค๋ค.
ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable ( )
ID3D12GraphicsCommandList::DrawIndexedInstanced ( )
***************************
G:ID3D12GraphicsCommandList::ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(CurrentBackBuffer(),
D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATE_PRESENT));
๋ฆฌ์์ค์ ์ํ๋ฅผ ์ถ๋ ฅํ ์ ์๋๋ก ๋ณ๊ฒฝํจ.
4. commandList์ ๊ธฐ๋ก์ ์ข
๋ฃํจ.
ID3D12GraphicsCommandList::Close()
5. ์ปค๋งจ๋ ๋ฆฌ์คํธ์ ์คํ์ ์ํด ํ์ ์ ์ถํจ.
6. ๋ฐฑ ๋ฒํผ์ ํ๋ก ํธ ๋ฒํผ๋ฅผ ๊ต์ฒดํจ. [์ค์์ฒด์ธ swapchain]
7. ์ด ํ์ค ์ง์ ๊น์ง ์ปค๋งจ๋๋ค์ ํ์ํ๊ธฐ ์ํด ํ์ค ๊ฐ์ ์ฆ๊ฐํจ.
8. ์ ํ์ค ์ง์ ์ ์ค์ ํ๋ ์ธ์คํธ๋ญ์ ์ ์ปค๋งจ๋ ํ์ ์ถ๊ฐํจ. GPU๊ฐ ๋ชจ๋ ์ปค๋งจ๋๋ค์ ์ฒ๋ฆฌ๊ฐ ์๋ฃ๋๊ธฐ ์ ๊น์ง Signal()์ ์ฒ๋ฆฌํ์ง ์์.
auto cmdListAlloc = mCurrFrameResource->CmdListAlloc;
ThrowIfFailed(cmdListAlloc->Reset());
if (mIsWireframe)
{
ThrowIfFailed(mCommandList->Reset(cmdListAlloc.Get(), mPSOs["opaque_wireframe"].Get()));
}
else
{
ThrowIfFailed(mCommandList->Reset(cmdListAlloc.Get(), mPSOs["opaque"].Get()));
}
mCommandList->RSSetViewports(1, &mScreenViewport);
mCommandList->RSSetScissorRects(1, &mScissorRect);
mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(CurrentBackBuffer(),
D3D12_RESOURCE_STATE_PRESENT,
D3D12_RESOURCE_STATE_RENDER_TARGET));
mCommandList->ClearRenderTargetView(CurrentBackBufferView(), Colors::LightSteelBlue, 0, nullptr);
mCommandList->ClearDepthStencilView(DepthStencilView(), D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr);
mCommandList->OMSetRenderTargets(1, &CurrentBackBufferView(), true, &DepthStencilView());
ID3D12DescriptorHeap* descriptorHeaps[] = {mCbvHeap.Get()};
mCommandList->SetDescriptorHeaps(_countof(descriptorHeaps), descriptorHeaps);
mCommandList->SetGraphicsRootSignature(mRootSignature.Get());
int passCbvIndex = mPassCbvOffset + mCurrFrameResourceIndex;
auto passCbvHandle = CD3DX12_GPU_DESCRIPTOR_HANDLE(mCbvHeap->GetGPUDescriptorHandleForHeapStart());
passCbvHandle.Offset(passCbvIndex, mCbvSrvUavDescriptorSize);
mCommandList->SetGraphicsRootDescriptorTable(1, passCbvHandle);
DrawRenderItems(mCommandList.Get(), mOpaqueRitems);
mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(CurrentBackBuffer(),
D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATE_PRESENT));
ThrowIfFailed(mCommandList->Close());
ID3D12CommandList* cmdLists[] = {mCommandList.Get()};
mCommandQueue->ExecuteCommandLists(1, cmdLists);
ThrowIfFailed(mSwapChain->Present(0, 0));
mCurrBackBuffer = (mCurrBackBuffer + 1) % SwapChainBufferCount;
mCurrFrameResource->Fence = ++mCurrentFence;
mCommandQueue->Signal(mFence.Get(), mCurrentFence);
'๐ฏ game engine > โฝ directX12' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DirectX12] ํ๋ธ๋งต ๋ง๋ค๊ธฐ / StructuredBuffer (0) | 2024.11.26 |
---|---|
[DirectX12] ์คํ ์ค(stencil) ๊ฑฐ์ธ ๋ง๋ค๊ธฐ (0) | 2024.11.07 |
[DirectX12] ์กฐ๋ช ์ ์ข ๋ฅ (0) | 2023.12.19 |
[DirectX12] ์กฐ๋ช ์ฐ์ฐ์ ์ํ ๋ฒ์ ๋ฒกํฐ, ๋ฒ์ ๋ฒกํฐ์ ๋ณํ (0) | 2023.12.14 |
[DirectX12] Direct3D ์ด๊ธฐํ ๊ณผ์ , ๊ทธ๋ํฝ ํ๋ก๊ทธ๋๋ฐ์ CPU์ GPU์ ์ํธ์์ฉ (1) | 2023.12.06 |
์ ํ๋ ๊ฒ ๋ณด๋ค ๋ซ๊ฒ ์ง
ํฌ์คํ ์ด ์ข์๋ค๋ฉด "์ข์์โค๏ธ" ๋๋ "๊ตฌ๋ ๐๐ป" ํด์ฃผ์ธ์!