•DirectX-Graphics-Samples-master\Samples\Desktop\D3D12HelloWorld\src\HelloTexture
•Paints
2d texture (checkerboard image) to triangle.
Difference from D3D12HelloTriangle
Took diff with WinMerge to
find difference.
•D3D12HelloTexture.h
–
static const
UINT TextureWidth = 256;
– static const UINT TextureHeight = 256;
– static const UINT TexturePixelSize = 4;
–
struct Vertex
– {
– XMFLOAT3 position;
– XMFLOAT2 uv; //< texture UV instead of vertex
color.
– };
–ComPtr<ID3D12DescriptorHeap> m_srvHeap;
–ComPtr<ID3D12Resource> m_texture;
Texture UV corrdinate
Direct X traditionally uses right=X+, down=Y+ coordinates for UV.
Objects and their relations
Changes from HelloTriangle example is highlighted in orange.
•m_texture
–width=256px,
height=256px, pixelformat=RGBA8888
–mipmap
level=1
–initialized
as COPY_DEST state (ready to update texture image)
–UpdateSubResources() to
upload texture image of CPU memory to texture GPU memory
–change
resource state to PIXEL_SHADER_RESOURCE for pixel shader to read
•sampler
–defines
texture sampler behavior such as texture clamp and mip map
parameters.
–m_rootSignature has
this sampler info.
•m_srvHeap
(Shader Resource View heap)
–Pixel
shader sees m_texture via m_srvHeap.
–m_commandList
connects m_srvHeap via
those calls:
ID3D12DescriptorHeap* ppHeaps[] = { m_srvHeap.Get() };
m_commandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
m_commandList->SetGraphicsRootDescriptorTable(
0, m_srvHeap->GetGPUDescriptorHandleForHeapStart());
PipelineStateDesc.InputLayout is changed to input texture UV instead of vertex color.
Shader code
DirectX-Graphics-Samples-master\Samples\Desktop\D3D12HelloWorld\src\HelloTexture\shaders.hlsl
Vertex shader pass through input position and UV value.
Pixel shader samples texture to get pixel color.
No comments:
Post a Comment