Friday, April 22, 2011

Stencil Buffer

This tutorial will demonstrate the use of stencil buffer to mask pixels. Stencil buffer is widely used in games to implement mirrors and other things

This site is under construction. I will soon add samples and tutorials in the near future

Blending

This tutorial will demonstrate the use of blending for various purposes

This site is under construction. I will soon add samples and tutorials in the near future

Pipeline Statistics

This tutorial will demonstrate the use of pipeline statistics query to retrieve the information about graphics-pipeline activity. It can be done so by creating a query of type D3D11_QUERY_PIPELINE_STATISTICS

Code:


D3D11_QUERY_DESC oD3DQueryDesc;
::memset(&oD3DQueryDesc, 0, sizeof(D3D11_QUERY_DESC));


// Pipeline statistics query
oD3DQueryDesc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
CHECK_COM(m_pD3DDevice->CreateQuery(&oD3DQueryDesc, &m_pD3DPipelineStatsQuery));

D3D11_QUERY_DATA_PIPELINE_STATISTICS oD3DQueryDataPipelineStats;
m_pD3DImmDevContext->GetData(m_pD3DPipelineStatsQuery, reinterpret_cast<void *>(&oD3DQueryDataPipelineStats), sizeof(D3D11_QUERY_DATA_PIPELINE_STATISTICS), 0);

Now, 'oD3DQueryDataPipelineStats' should be populated with the pipeline statistics

Loading Mesh | Asset

This tutorial will demonstrate how to load mesh in Direct3D 11. It uses Assimp library to do so. It's an open source project and can be used to load various asset formats export from DCC tools

This site is under construction. I will soon add samples and tutorials in the near future

Thursday, April 14, 2011

Direct2D

This tutorial is dedicated to Direct2D for drawing hardware accelerated 2D images and texts

This site is under construction. I will soon add samples and tutorials in the near future

DirectWrite

This tutorial is dedicated to DirectWrite for using hardware accelerated 2D and 3D text

This site is under construction. I will soon add samples and tutorials in the near future

Geometry Shader

This tutorial will demonstrate the use of geometry shader.

Interfaces used:
ID3D11GeometryShader

Here's a simple geometry shader procedure which simply reads the input triangle data and appends the output data to existing stream. Inputs and outputs are vertex position, normal, texture coordinate and material color


[maxvertexcount(3)]
void GSProc(triangle SVS_Output oInput[3], inout TriangleStream<SVS_Output> triOutputStream)
{
SVS_Output oVSOutput = (SVS_Output) 0;

// Loop to read the input triangle data
for(uint uiCount = 0; uiCount < 3; uiCount++)
{
// Pass the input data as is
oVSOutput.m_vecPosition = oInput[uiCount].m_vecPosition; // Position
oVSOutput.m_fNormal = oInput[uiCount].m_fNormal; // Normal
oVSOutput.m_fTexture = oInput[uiCount].m_fTexture; // Texture
oVSOutput.m_fMaterialColor = oInput[uiCount].m_fMaterialColor; // Material color

triOutputStream.Append(oVSOutput); // Append output data to an existing stream
}

triOutputStream.RestartStrip(); // End the current primitive strip
}

Camera

This tutorial will demonstrate the use of camera

To create a camera, we need three vectors: up, right and look-at. Generally up vector is always set to (0.0f, 1.0f, 0.0f) and right and look-at vectors are set as follows (1.0f, 0.0f, 0.0f) and (0.0f, 1.0f, 0.0f). We will use these three vectors to create a view transformation matrix.

Before doing so we need to create a perspective projection matrix. We can create a left-handed perspective projection matrix using XMMatrixPerspectiveFovLH as follows:

float fAspectRatio = window_width / window_height; // Set window_width and window_height
XMMATRIX oProjectionMatrix = XMMatrixPerspectiveFovLH (XM_PI * 0.5f, // FOV

fAspectRatio, // Aspect ratio
0.01f, // Distance to near clipping plane
10000.0f); // Distance to far clipping plane

Now, it's time to create a left-handed view transformation matrix

XMMATRIX oViewMatrix = XMMatrixLookAtLH(XMVECTOR(0.0f, 0.0f, 0.0f, 0.0f), XMVECTOR(0.0f, 1.0f, 0.0f, 0.0f), XMVECTOR(0.0f, 1.0f, 0.0f, 0.0f));

Bind the above view transformation matrix to look at the objects in your game

Wednesday, April 13, 2011

Tessellation

This tutorial will demonstrate the use of tessellation to render highly detailed surfaces. It uses hull shader, tessellation and domain shader stages to accomplish this.

Interfaces used:
ID3D11DomainShader
ID3D11HullShader

This site is under construction. I will soon add samples and tutorials in the near future

Deferred Context | Multi-threaded Rendering

This tutorial will demonstrate the use of deferred context (ID3D11DeviceContext) for multi-threaded rendering

After creating your D3D 11 device you create a deferred context which will be used for rendering in a separate thread. These are the steps that should be taken:

1: Use ID3D11Device::CreateDeferredContext method to create a deferred context

Example:
ID3D11DeviceContext *pD3DDefDevContext;
m_pD3DImmDevContext->CreateDeferredContext(0, &pD3DDefDevContext);

2: Now pD3DDefDevContext can be used in a separate thread to do rendering stuff.

Constant Buffer

This tutorial will demonstrate the use of constant buffers to update multiple variables in a shader in a single call.

We group constant buffers based on the frequency of their usage. For example, world transformation matrix changes every frame for each and every object (assumption), so does it's inverse transpose. So we group it as a constant buffer. Similarly, assuming projection matrix remains static, we group it as a static constant buffer.


// Constant buffer that's static
cbuffer CBStatic
{
row_major matrix m_matProjection; // Projection matrix
};



// Constant buffer that changes every frame
cbuffer CBEveryFrame
{
matrix m_matWorld; // World matrix
matrix m_matInverseTransposeWorld; // Inverse transpose of world matrix
};


Their corresponding structure in our C++ code:


// Constant buffer that remains unchanged
struct SStaticConstantBuffer
{
XMMATRIX m_oProjectionMatrix; // Projection matrix
};


// Constant buffer that changes every frame
struct SChangesEveryFrameConstantBuffer
{
XMMATRIX m_oWorldMatrix; // World matrix
XMMATRIX  m_oInverseTransposeWorldMatrix; // Inverse transpose of world matrix
};



// Constant buffer description


D3D11_BUFFER_DESC oD3DBufferDesc = {0};
oD3DBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; // Bind constant buffer


// Create constant buffer that's static
oD3DBufferDesc.Usage = D3D11_USAGE_DEFAULT; // GPU read/write
oD3DBufferDesc.ByteWidth = sizeof(SStaticConstantBuffer);
CHECK_COM(pD3DDevice->CreateBuffer(&oD3DBufferDesc, nullptr, &m_pD3DStaticConstBuffer));


oD3DBufferDesc.Usage = D3D11_USAGE_DYNAMIC; // GPU read only; CPU write only permissions
oD3DBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // CPU can change it's contents



// Create constant buffer that changes every frame
oD3DBufferDesc.ByteWidth = sizeof(SChangesEveryFrameConstantBuffer);
CHECK_COM(pD3DDevice->CreateBuffer(&oD3DBufferDesc, nullptr, &m_pD3DChangesEveryFrameConstBuffer));

It's time to update the constant buffer that changes every frame:

D3D11_MAPPED_SUBRESOURCE oD3DMappedSubresource;


// Get a pointer to the data that contains HLSL constant buffers
CHECK_COM(pD3DDeviceContext->Map(m_pD3DChangesEveryFrameConstBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &oD3DMappedSubresource));

// Update the constant buffer data that changes every frame
::memcpy(oD3DMappedSubresource.pData, g_pChangesEveryFrameConstBuffer, sizeof(SChangesEveryFrameConstantBuffer)); // g_pChangesEveryFrameConstBuffer is a pointer to SChangesEveryFrameConstantBuffer

pD3DDeviceContext->Unmap(m_pD3DChangesEveryFrameConstBuffer, 0); // Unmap the pointer to the data

pD3DDeviceContext->VSSetConstantBuffers(0, 1, &m_pD3DChangesEveryFrameConstBuffer); // Set constant buffer that changes every frame

So in this way we update multiple variables in a constant buffer in a single call






Index Buffer

This tutorial will demonstrate the use of index buffer

This site is under construction. I will soon add samples and tutorials in the near future

Vertex Buffer

This tutorial will demonstrate the use of vertex buffer

This site is under construction. I will soon add samples and tutorials in the near future

Sharing Surface Between Direct3D and Direct2D

This tutorial will demonstrate how to share surface between Direct3D and Direct2D

This site is under construction. I will soon add samples and tutorials in the near future

Effect Interface

This tutorial will demonstrate the user of Direct3D Effects 11 framework

This site is under construction. I will soon add samples and tutorials in the near future

Stream Output

This tutorial will demonstrate the use of stream output

This site is under construction. I will soon add samples and tutorials in the near future

Occlusion Predicate

This tutorial will demonstrate occlusion predicate query

Interfaces used:
ID3D11Predicate

This site is under construction. I will soon add samples and tutorials in the near future

Occlusion Query

This tutorial will demonstrate occlusion query to find the number of pixels that passed the sample test

Interfaces used:
ID3D11Query

This site is under construction. I will soon add samples and tutorials in the near future

Normal Mapping

This tutorial will demonstrate normal mapping using Direct3D 11

This site is under construction. I will soon add samples and tutorials in the near future

Saturday, April 2, 2011

Draw Text Using Direct2D And DirectWrite

This tutorial will demonstrate how to draw text using Direct2D and DirectWrite and Direct3D 11

This site is under construction. I will soon add samples and tutorials in the near future

Adaptive Tessellation

This tutorial will demonstrate how to implement adaptive tessellation using Direct3D 11 and shader model 5

This site is under construction. I will soon add samples and tutorials in the near future

Shadow Mapping

This tutorial will demonstrate how to implement shadow mapping using shader model 5

This site is under construction. I will soon add samples and tutorials in the near future

Texturing

This tutorial will demonstrate how to load texture in Direct3D 11

Interfaces used:
ID3D11ShaderResourceView

std::wstring oTexturePathString = L"c:\\textures\\hello.dds"; // Replace this file path with the texture that you want to load


ID3D11ShaderResourceView *pD3DShaderResourceView;

CHECK_COM(::D3DX11CreateShaderResourceViewFromFile(g_pD3DDevice, oTexturePathString.data(), nullptr, nullptr, &pD3DShaderResourceView, nullptr));

Now bind the created SRV to the shader to see the bound texture

Displacement Mapping

This Direct3D 11 tutorial will show you how to implement displacement mapping in hardware

This site is under construction. I will soon add samples and tutorials in the near future

Dynamic Shader Linkage

This Direct3D 11 tutorial will demonstrate how to implement dynamic shader linkage

Interfaces used:
ID3D11ClassLinkage

This site is under construction. I will soon add samples and tutorials in the near future