DirectX11 book exercises chapter 11

I Did some more exercises from Directx 11 book. Chapter 11 The Geometry Shader had couple interesting exercises.

First one was exercise 3 that asked to implement a simple explosion effect in geometry shader to an icosahedron where each triangle are translated to the direction of their face normal as a function of time. The geometry shader counts the face normal then translates the three vertices of the triangle. I added this to previous modified crate demo that had nice fire texture and changed also the box in it to icosahedron.

// simple explosion geometry shader
[maxvertexcount(3)]
void GS(triangle VertexOut gin[3],
	uint primID: SV_PrimitiveID,
	inout TriangleStream<GeoOut> triStream)
{
	float3 u = gin[1].PosW - gin[0].PosW;
	float3 v = gin[2].PosW - gin[0].PosW;

	float3 n = cross(u, v);
	n = normalize(n);

	float3 speed = 0.02f * primID%5;

	float4 tri[3];
	tri[0] = float4(gin[0].PosW + speed*gTime*n, 1.0f);
	tri[1] = float4(gin[1].PosW + speed*gTime*n, 1.0f);
	tri[2] = float4(gin[2].PosW + speed*gTime*n, 1.0f);

	GeoOut gout;
	[unroll]
	for (int i = 0; i < 3; ++i)
	{
		gout.PosH = mul(tri[i], gWorldViewProj);
		gout.PosW = tri[i].xyz;
		gout.NormalW = gin[i].NormalW;
		gout.Tex = gin[i].Tex;

		triStream.Append(gout);
	}

}

Capturech11ex3

 

 

 

 

 

 

5 subdivisions and black background in 0.1 second starts to look nice:

Capture5sub

 

 

 

 

 

 

Other exercises where drawing cylinder from circle in gs and subdividing icosahedron and also experimenting with tree billboards demo with different draw calls together with size of the quads and primitive id.

 

Leave a Reply

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