How to color single texture on large texture atlas?

Hello everyone!

I just started learning UE and have made some progress, but I’m having trouble working out a texture issue with a Procedural Mesh.

I created a material from a large texture atlas and specified UV coords to place a single mapped texture from the atlas to each side of the cube. I did this manually in C++ using vertices, triangles, normals and tangent arrays - then built a Procedural Mesh for my single cube. My manually created cube now has a different texture on each side rendered from the same material. So far so good.

Now I want to change the color of just one of the individual textures and I have no idea how to get that done. So far I’ve done everything in C++ and would like to find a way to do this in C++ if possible, but maybe there is a way to do this in Blueprint that makes it even easier?

When working with the UProceduralMeshComponent, I did try to set the VertexColor array value for this one quad, but that seemed to have no affect.

Any help is greatly appreciated.

Does anyone have a solution for this? Here’s a bit of code that might stimulate some ideas:

I’m creating 6 quads to form a cube. Here is how I create one quad:




 // Arrays declared in header
    TArray<FVector> vertices;
    TArray<int32> triangles;
    TArray<FVector> normals;
    TArray<FVector2D> UVs;
    TArray<FProcMeshTangent> tangents;
    TArray<FLinearColor> vertexColors;

 // Creating the quad by ordering vertices in the array
        parent->vertices.Add(points[1] + position);
        parent->vertices.Add(points[5] + position);
        parent->vertices.Add(points[6] + position);
        parent->vertices.Add(points[2] + position);
// normals
        parent->normals.Add(FVector(0.0f, 0.0f, -1.0f));
        parent->normals.Add(FVector(0.0f, 0.0f, -1.0f));
        parent->normals.Add(FVector(0.0f, 0.0f, -1.0f));
        parent->normals.Add(FVector(0.0f, 0.0f, -1.0f));
// triangles
        parent->triangles.Add(parent->vertices.Num() - 4);
        parent->triangles.Add(parent->vertices.Num() - 3);
        parent->triangles.Add(parent->vertices.Num() - 2);
        parent->triangles.Add(parent->vertices.Num() - 2);
        parent->triangles.Add(parent->vertices.Num() - 1);
        parent->triangles.Add(parent->vertices.Num() - 4);

// I then create the mesh, set the material and enable collisions
// mesh is a UProceduralMeshComponent
    mesh->SetMaterial(0, material);
    mesh->CreateMeshSection_LinearColor(0, vertices, triangles, normals, UVs, vertexColors, tangents, true);
    mesh->ContainsPhysicsTriMeshData(true);



The above code generates my cube and applies my UV targeted texture to each face. I just can’t get the color of one face to change.
I have experimented with different values within the vertexColors array, but nothing I have tried makes any difference. In the above example I am passing in empty arrays.

Any ideas?

Humm To me this describes the function of an instanced material.

Sounds like you probably need to make your material support the function of change the color of one face. Just as above, an instanced material with some parameters to handle the color of specific face.

I’m not understanding how the Material Instance allows me to change the color of just one UV location. For example, I have the following texture atlas. I want to change the color of the very first item in the texture (0.0, 0.0, 0.0833, 0.0833). How do I do this while leaving the rest of the texture alone?

Is Blueprint the only way to do what I want to do? If so, what needs to happen to the following:

No you don’t need to use a BP but you do need a material, unless you figure out how to do a or want to make use of procedural material.

Why you would want to use an instance material is because a function or a value, or mask, can be added that can be exposed in the instance and code can be used to change the value. Instance material are awesome as you only make the master once, as in if you add anything to the master it translates to the instances, so the behavior of the instances as to texture looks ups and parameter changes is equal to the single master no mater how many you make. You could have hundreds of instances but only have to look up the 4-8K TA once.

In context to change the color at (0.0, 0.0, 0.0833, 0.0833), top left?, I would create a mask texture input that defines that area and expose it. In the instance I would then add the mask and use other exposed values to change the color. Boot load of tutorials on how to do color changes.

In most cases such demo’s use BP’s but to keep in mind that anything that can be done using a BP can be done in code as a BP is nothing more than C++ exposed. (You can even copy a nod and paste it in note pad to see where the hooks are)

as in

In a material you can even change the area of the texture/material would be effected by changing the properties of the UV map output of an instanced material or even include in code if making a plugin for example.

Over all though it would be easier to work out as a BP first and then convert to code as that is just one of the purpose of having blueprints in the first place.