In this chapter, we'll try something different from the last one. Unfortunately, you'll need a source build engine for this. If you don't know how to get one, please check these instructions.

Our goal is to draw our cube (and all other mesh batches) directly onto the final render target in a red color!

Compile it and have a good sleep!

Now, think about what we need to do:

Add a new mesh pass enum

Add a new item in EMeshPass , inside MeshPassProcessor.h

Code

/** Mesh pass types supported. */
namespace EMeshPass
{
	enum Type : uint8
	{
		DepthPass,
		//...
		MeshDecal,
#if WITH_EDITOR
		HitProxy,
		//...
#endif
		RedCubePass, //<-- Here
		Num,
		NumBits = 6,
	};
}

If you directly compile, you will get an error:

Engine\\Source\\Runtime\\Renderer\\Public\\MeshPassProcessor.h(120): error C2338: Need to update switch(MeshPass) after changing EMeshPass

That is because you need also update GetMeshPassName function, just like the error message says.

And increase the static_assert number.

inline const TCHAR* GetMeshPassName(EMeshPass::Type MeshPass)
{
	switch (MeshPass)
	{
	case EMeshPass::DepthPass: return TEXT("DepthPass");
	//...
#if WITH_EDITOR
	case EMeshPass::HitProxy: return TEXT("HitProxy");
	//...
#endif
	case EMeshPass::RedCubePass: return TEXT("RedCubePass"); //<-- Here
	}

// Change the number from 29 to 30. If you use new version, just calculate by yourself.
#if WITH_EDITOR
	static_assert(EMeshPass::Num == 30 + 4, "Need to update switch(MeshPass) after changing EMeshPass"); // GUID to prevent incorrect auto-resolves, please change when changing the expression: {A6E82589-44B3-4DAD-AC57-8AF6BD50DF43}
#else
	static_assert(EMeshPass::Num == 30, "Need to update switch(MeshPass) after changing EMeshPass"); // GUID to prevent incorrect auto-resolves, please change when changing the expression: {A6E82589-44B3-4DAD-AC57-8AF6BD50DF43}
#endif

	checkf(0, TEXT("Missing case for EMeshPass %u"), (uint32)MeshPass);
	return nullptr;
}

We will get a new error:

Untitled

Let’s follow what it say, increase the MaxPSOCollectorCount in FPSOColectorCreateManager, inside PSOPrecache.h

class ENGINE_API FPSOCollectorCreateManager
{
public:

	constexpr static uint32 MaxPSOCollectorCount = 34; //from 33 to 34

Add a new mesh processor