Saturday, March 14, 2026

Pixelating vertex colour mixing to align with texture texels


I’m fairly new to shader programming and I’m making an attempt to make vertex colour mixing seem pixelated and aligned to the texel grid of my texture.

For context: I am utilizing the vertex colour to mix between two pixel artwork textures, so clean transitions breaks the look. I want this to work at runtime, so baking the vertex colours to a texture isn’t actually an possibility in my case.

I am in search of one thing nearer to nearest neighbor sampling, the place the vertex colours are quantized so that every texel will get a single worth.

I discovered an method in one other dialogue and tried to implement it for my use case. (Hyperlink to the thread right here)

That is what I am at the moment utilizing:

//UV to texel house and nearest texel heart
float2 texelPos = UVMap*TextureRes;
float2 texelCenter = flooring(texelPos) + 0.5f;
float2 delta = (texelCenter - texelPos) * (1.0f/TextureRes);

//display screen house vertex colour gradient 
float2 gradient = float2(ddx(VertexCol), ddy(VertexCol));

//UV to display screen
float2x2 uvToScreen;
uvToScreen[0]=ddx(UVMap);
uvToScreen[1]=ddy(UVMap);

//display screen to UV
float determinant = uvToScreen[0][0] * uvToScreen[1][1] - uvToScreen[0][1] *uvToScreen[1][0];

float2x2 end result = {uvToScreen[1][1], -uvToScreen[0][1], -uvToScreen[1][0],uvToScreen[0][0]};

float2x2 ScreenToUV;
ScreenToUV = end result * 1.0f/determinant;

//gradient from display screen to UV
gradient = mul(ScreenToUV, gradient);

return VertexCol+dot(gradient,delta);

My understanding of the code is that it approximates what the vertex colour would have been at every texel heart to make the fragments throughout the texel use the identical worth.

This works effectively when the UV’s of the mannequin are completely aligned per texel (no overlap), however creates small diagonal artifacts when a UV seam by way of a texel.

Any strategies for fixing the diagonal artifacts or different approaches to realize texel aligned vertex colour mixing could be vastly appreciated.

Pixel good vertex transitions (all UV seams on texel boarders)

Pixelating vertex colour mixing to align with texture texels

Diagonals showing when UV seams overlap with texels (floor proven was remeshed with a voronoi sample)
Vertex blending with diagonal artifacts

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles