Skip to content

Commit 6ebd7e3

Browse files
committed
Starting on new texture generation
1 parent 6d2f908 commit 6ebd7e3

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

DirectCompositeSample.cpp

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void D3D12HelloTexture::LoadAssets()
303303

304304
D3D12_SUBRESOURCE_DATA textureData = {};
305305
textureData.pData = &texture[0];
306-
textureData.RowPitch = TextureWidth * TexturePixelSize;
306+
textureData.RowPitch = TextureWidth * sizeof(UINT);
307307
textureData.SlicePitch = textureData.RowPitch * TextureHeight;
308308

309309
UpdateSubresources(m_commandList.Get(), m_texture.Get(), textureUploadHeap.Get(), 0, 0, 1, &textureData);
@@ -345,35 +345,54 @@ void D3D12HelloTexture::LoadAssets()
345345
// Generate a simple black and white checkerboard texture.
346346
std::vector<UINT8> D3D12HelloTexture::GenerateTextureData()
347347
{
348-
const UINT rowPitch = TextureWidth * TexturePixelSize;
348+
const UINT rowPitch = TextureWidth * sizeof(UINT);
349349
const UINT cellPitch = rowPitch >> 3; // The width of a cell in the checkboard texture.
350350
const UINT cellHeight = TextureWidth >> 3; // The height of a cell in the checkerboard texture.
351351
const UINT textureSize = rowPitch * TextureHeight;
352352

353-
std::vector<UINT8> data(textureSize);
354-
UINT8* pData = &data[0];
355-
356-
for (UINT n = 0; n < textureSize; n += TexturePixelSize)
357-
{
358-
UINT x = n % rowPitch;
359-
UINT y = n / rowPitch;
360-
UINT i = x / cellPitch;
361-
UINT j = y / cellHeight;
353+
DirectX::XMFLOAT4 colors[NumTextureColors] =
354+
{
355+
DirectX::XMFLOAT4(0, 0, 0, 1), // Black
356+
DirectX::XMFLOAT4(0, 0, 0, 1), // White
357+
DirectX::XMFLOAT4(1, 0, 0, 1), // Red
358+
DirectX::XMFLOAT4(1, 1, 0, 1), // Yellow
359+
DirectX::XMFLOAT4(0, 1, 0, 1), // Green
360+
DirectX::XMFLOAT4(0, 1, 1, 1), // Cyan
361+
DirectX::XMFLOAT4(0, 0, 1, 1), // Blue
362+
DirectX::XMFLOAT4(1, 0, 1, 1) // Purple
363+
};
362364

363-
if (i % 2 == j % 2)
364-
{
365-
pData[n] = 0x00; // R
366-
pData[n + 1] = 0x00; // G
367-
pData[n + 2] = 0x00; // B
368-
pData[n + 3] = 0xff; // A
369-
}
370-
else
371-
{
372-
pData[n] = 0xff; // R
373-
pData[n + 1] = 0xff; // G
374-
pData[n + 2] = 0xff; // B
375-
pData[n + 3] = 0xff; // A
376-
}
365+
std::vector<UINT8> data(textureSize);
366+
UINT8* pData = &data[0];
367+
368+
for (UINT a = 0; a < NumAlphaShades; ++a)
369+
{
370+
float alpha = a / (float)(NumAlphaShades - 1);
371+
372+
for (UINT c = 0; c < NumTextureColors; ++c)
373+
{
374+
const DirectX::XMFLOAT4& color = colors[c];
375+
DirectX::XMFLOAT4 pmaColor =
376+
{
377+
color.x * alpha,
378+
color.y * alpha,
379+
color.z * alpha,
380+
alpha
381+
};
382+
383+
UINT y = TexturePixelSizeY * c;
384+
for (UINT j = 0; j < TexturePixelSizeY; ++j, ++y)
385+
{
386+
for (UINT x = 0; x < TexturePixelSizeX; ++x)
387+
{
388+
UINT offset = (y * TextureWidth + x) * sizeof(UINT);
389+
pData[offset + 0] = 0xFF; //(uint8_t)(pmaColor.x * 255.0f);
390+
pData[offset + 1] = 0xFF; //(uint8_t)(pmaColor.y * 255.0f);
391+
pData[offset + 2] = 0xFF; //(uint8_t)(pmaColor.z * 255.0f);
392+
pData[offset + 3] = 0xFF; //(uint8_t)(pmaColor.w * 255.0f);
393+
}
394+
}
395+
}
377396
}
378397

379398
return data;

DirectCompositeSample.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ class D3D12HelloTexture : public DXSample
3333
virtual void OnDestroy();
3434

3535
private:
36+
static const UINT NumTextureColors = 8;
37+
static const UINT NumAlphaShades = 8;
3638
static const UINT FrameCount = 2;
3739
static const UINT TextureWidth = 256;
3840
static const UINT TextureHeight = 256;
39-
static const UINT TexturePixelSize = 4; // The number of bytes used to represent a pixel in the texture.
41+
static const UINT TexturePixelSizeX = TextureWidth / NumAlphaShades; // The number of bytes used to represent a pixel in the texture.
42+
static const UINT TexturePixelSizeY = TextureHeight / NumTextureColors; // The number of bytes used to represent a pixel in the texture.
4043

4144
struct Vertex
4245
{

0 commit comments

Comments
 (0)