Add a border to a procedural mesh

I’m creating a procedural mesh using C++ and I wondering how can I add it a border.

I don’t really want to create a mesh, I want to create a polygon. I have a set or vertices and someone here told me that I have to use procedural mesh to do it. But know I have a black triangle without a border and I need only the border.

How can I do it?

fresnel and opacity in your mesh material.
or a post-process sobel edge that relies on custom depth

Thanks for your answer. I didn’t know anything about what are you saying. Now I’m learning what is fresnel. But I don’t know how to use fresnel and opacity together or what is a post-process sobel edge that relies on custom depth.

I’m new in Unreal Development.

I have modified the class that create the ProceduralMesh:


AMyActor::AMyActor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));
	RootComponent = SphereComponent;

	UProceduralMeshComponent* mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"));
	/**
	*	Create/replace a section for this procedural mesh component.
	* @param	SectionIndex		Index of the section to create or replace.
	* @param	Vertices			Vertex buffer of all vertex positions to use for this mesh section.
	* @param	Triangles			Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
	* @param	Normals				Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
	* @param	UV0					Optional array of texture co-ordinates for each vertex. If supplied, must be same length as Vertices array.
	* @param	VertexColors		Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
	* @param	Tangents			Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
	* @param	bCreateCollision	Indicates whether collision should be created for this section. This adds significant cost.
	*/
	//UFUNCTION(BlueprintCallable, Category = "Components|ProceduralMesh", meta = (AutoCreateRefTerm = "Normals,UV0,VertexColors,Tangents"))
	//	void CreateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
	// const TArray<FVector2D>& UV0, const TArray<FColor>& VertexColors, const TArray<FProcMeshTangent>& Tangents, bool bCreateCollision);

	TArray<FVector> vertices;

	vertices.Add(FVector(0, 0, 0));
	vertices.Add(FVector(0, 100, 0));
	vertices.Add(FVector(0, 0, 100));

	TArray<int32> Triangles;
	Triangles.Add(0);
	Triangles.Add(1);
	Triangles.Add(2);

	TArray<FVector> normals;
	normals.Add(FVector(1, 0, 0));
	normals.Add(FVector(1, 0, 0));
	normals.Add(FVector(1, 0, 0));

	TArray<FVector2D> UV0;
	UV0.Add(FVector2D(0, 0));
	UV0.Add(FVector2D(0, 10));
	UV0.Add(FVector2D(10, 10));

	TArray<FColor> vertexColors;
	vertexColors.Add(FColor(100, 100, 100, 100));
	vertexColors.Add(FColor(100, 100, 100, 100));
	vertexColors.Add(FColor(100, 100, 100, 100));


	TArray<FProcMeshTangent> tangents;
	tangents.Add(FProcMeshTangent(1, 1, 1));
	tangents.Add(FProcMeshTangent(1, 1, 1));
	tangents.Add(FProcMeshTangent(1, 1, 1));


	mesh->CreateMeshSection(1, vertices, Triangles, normals, UV0, vertexColors, tangents, false);

	// With default options
	//mesh->CreateMeshSection(1, vertices, Triangles, TArray<FVector>(), TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>(), false);

	UMaterial* StarMaterial;

	static ConstructorHelpers::FObjectFinder<UMaterial> MatFinder(TEXT("Material'/Game/Materials/FresnelMaterial.FresnelMaterial'"));
	if (MatFinder.Succeeded())
	{
		StarMaterial = MatFinder.Object;

		UMaterialInstanceDynamic* StarMaterialInstanceDynamic = UMaterialInstanceDynamic::Create(StarMaterial, NULL);
		mesh->SetMaterial(0, StarMaterialInstanceDynamic);
	}

	mesh->AttachTo(RootComponent);
}

I have added this:


UMaterial* StarMaterial;

	static ConstructorHelpers::FObjectFinder<UMaterial> MatFinder(TEXT("Material'/Game/Materials/FresnelMaterial.FresnelMaterial'"));
	if (MatFinder.Succeeded())
	{
		StarMaterial = MatFinder.Object;

		UMaterialInstanceDynamic* StarMaterialInstanceDynamic = UMaterialInstanceDynamic::Create(StarMaterial, NULL);
		mesh->SetMaterial(0, StarMaterialInstanceDynamic);
	}

I don’t see any different with the previous one.

Any advice about how to add a material to a Procedural Mesh?

I’m sorry, but I don’t know how to do it. Could you help me with this, please?

after some messing around, dont use fresnel for borders… doesnt work as well as youd think.
For sobel edges, go here: Looking for a basic Sobel Edge Post Process Material? - Asset Creation - Epic Developer Community Forums and download and follow those instructions. you’re going to want to open the material up and invert the effect that ‘doesnt draw if custom depth = 1’ or what ever its called. you only want edges if this is true. in your procedural mesh, set ‘custom depth = true’ and that will give you an outline.

I did it and I get these errors (I’m using Unreal Engine 4.11.2):

Error [SM5] Missing Material Function
Error [SM5] (Node If) If input B must be of type float.
Error [SM5] (Node SceneTexture) SceneColor lookups are only available when MaterialDomain = Surface. PostProcessMaterials should use the SceneTexture PostProcessInput0.

And when I open the project I get this error also:

Error /Game/Materials/MI_SobelEdge : Can’t find file for asset. /Game/Materials/SobelEdge/M_SobelEdge
Info Failed to load /Game/Materials/SobelEdge/M_SobelEdge.M_SobelEdge Referenced by MI_SobelEdge

I have solved all these errors changing SceneTexture:SceneColor with SceneTexture:PostProcessInput0. But, without any error, I still don’t see the sobel edge. Any idea? This is very frustrating.

UPDATE:

I’m continue searching how to do it and I have found this tutorial: Multi-color Outline Post Process - Tom Looman. I have had to create a new material instance but it seems to work and I can see the effect.

I don’t understand why I can’t see the sobel edge.