DirectX 11 Book chapter 6

I did some Exercises from Directx 11 book chapter 6 Drawing in DirectX.

Some more interesting screenshots and some code snippets from exercises.

ex.4

Capturech6ex4

 // The Pyramid
 Vertex verticesP[] =
	{
		{ XMFLOAT3(-1.0f, -1.0f, -1.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(-1.0f, -1.0f, 1.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(+1.0f, -1.0f, 1.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(+1.0f, -1.0f, -1.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(0.0f, 1.5f, 0.0f), (const float*)&Colors::Red }
	};

	// Create the index buffer
	UINT indicesP[] = {
		// bottom
		2, 1, 0,
		3, 2, 0,

		// sides
		0, 1, 4,
		1, 2, 4,
		2, 3, 4,
		3, 0, 4
	};

ex.6
Simple cube animation on vertex shader.
Added code to C++


// member variable for time
ID3DX11EffectScalarVariable* mfxTime;

// in BuildFX()
mfxTime = mFX->GetVariableByName("gTime")->AsScalar();

//...

// in Draw()
mfxTime->SetFloat(mTimer.TotalTime());

shader code:

cbuffer cbPerFrame
{
	float gTime;
};

VertexOut VS(VertexIn vin)
{
	VertexOut vout;

	// ch.6 ex.6
	vin.PosL.xy += 0.5f*sin(vin.PosL.x)*sin(3.0f*gTime);
	vin.PosL.z *= 0.6f + 0.4f*sin(2.0f*gTime);

	// Transform to homogeneous clip space.
	vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);

	// Just pass vertex color into the pixel shader.
    vout.Color = vin.Color;

    return vout;
}

ex. 13
Setting and using scissor test.

Capturech6ex13

  D3D11_RASTERIZER_DESC wireframeDesc;
	ZeroMemory(&wireframeDesc, sizeof(D3D11_RASTERIZER_DESC));
	wireframeDesc.FillMode = D3D11_FILL_WIREFRAME;
	wireframeDesc.CullMode = D3D11_CULL_BACK;
	wireframeDesc.FrontCounterClockwise = false;
	wireframeDesc.DepthClipEnable = true;
	wireframeDesc.ScissorEnable = true;

	HR(md3dDevice->CreateRasterizerState(&wireframeDesc, &mWireframeRS));

	D3D11_RECT rects = { 100, 100, 400, 400 };
	md3dImmediateContext->RSSetScissorRects(1, &rects);

ex. 14
GeoSphere with different subdivision levels. Subdivision levels: 0, 1 and 3.

Capturegs0

Capturegs1

Capturegs3

 

Leave a Reply

Your email address will not be published. Required fields are marked *