Download

How to have streched face to tile texture uv.

I am looking for a node setup to account for world position/face size to tile face textures (uv positions?) from** texture atlas**.
I am pretty sure this is something standard, but can’t find it.

I am using procedural mesh to draw two overlaying faces.
It should display three unit size tiles instead of two stretched out faces.

b5a0231ca488da23f7a99fb1294df7a68d88f087.jpeg

The faces are defined as such. ( unit size and positions)


	
// pos is times 100 when drawing
FVector stone_Faces] = {
		FVector(1.0, 0.0, 1.0), // first face vertex
		FVector(1.0, 2.0, 1.0),
		FVector(0.0, 2.0, 1.0),
		FVector(0.0, 0.0, 1.0),

		FVector(2.0, 0.0, 1.0), // second face vertex
		FVector(2.0, 1.0, 1.0),
		FVector(0.0, 1.0, 1.0),
		FVector(0.0, 0.0, 1.0)
	};

	FVector2D stone_UVs] = {
		FVector2D(0.296875, 0.265625),
		FVector2D(0.546875, 0.265625),
		FVector2D(0.546875, 0.015625),
		FVector2D(0.296875, 0.015625),

		FVector2D(0.296875, 0.265625),
		FVector2D(0.546875, 0.265625),
		FVector2D(0.546875, 0.015625),
		FVector2D(0.296875, 0.015625)
	};


The texture is
bb6ac22afc6e1d915f7e19ecc39009fa54100b30.png

8b171fccf52332b916f43396023a9f4a1563ab75.jpeg

I have made progress…
It works in one orientation and only when vertex pos axis are postive.
I have the same corner uv on all 4 vertices, and in the material add the relative vertex position to the uv-cord.

43098e4642.jpg
adaa0581ae3f67a8a03d8b2a85c2d8534949bbfe.png



FVector dirt_Faces] = {
		FVector(1.0, 0.0, 1.0), // first face vertex
		FVector(1.0, 2.0, 1.0),
		FVector(0.0, 2.0, 1.0),
		FVector(0.0, 0.0, 1.0),

		FVector(2.0, 0.0, 1.0), // second face vertex
		FVector(2.0, 1.0, 1.0),
		FVector(0.0, 1.0, 1.0),
		FVector(0.0, 0.0, 1.0),

		 // third  face vertex
		
		FVector(0.0 + 1, 1.0, 2.0),
		FVector(0.0 + 1, 0.0, 2.0),
		FVector(1.0 + 1, 0.0, 2.0),
		FVector(1.0 + 1, 1.0, 2.0)
	};

	FVector2D dirt_UVs] = {
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),

		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),

		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625),
		FVector2D(0.296875, 0.015625)
		//
	};

I think I can manage the xz and yz axis with some trickery reading the normals,
but** I have no idea how to have rotation or tile size** passed to the material.

Should I hack it into some value i don’t use? like vertex color,weight or something else?
Or should I have all the tiles and rotations on separate tiles textures?

Got the orientation working…
9f2ab8cb1e95f166fb82e986290849ae51727d18.jpeg



float2 uv;
if (abs(Normal.x)>0.01){	 
	uv = float2(LocalPosition.y,-LocalPosition.z);
} else if (abs(Normal.y)>0.01){	 
	uv = float2(LocalPosition.x,-LocalPosition.z);
} else if (abs(Normal.z)>0.01){	 
	uv = float2(LocalPosition.x,LocalPosition.y);
} else {
	return float2(0.9,0.9);
}	

uv /= voxelSize;
uv -= floor(uv);
uv *= uvTileSize;

return uv;

Am I on the right track?
Any pointers would be appreciated, as I am quite new to ue4 and it’s procedural mesh generator.