Im getting a very subtle checkerboard artifact along the triangle edges shown by light to normal shading on white.
Im wondering if anyone has seen this before and maybe knows a quick fix?
Im thinking maybe there is some setting im not aware of.
I can’t seem to get rid of it i tried all the sampler states i could think of nothing.
So im thinking its some sort of antialiasing on the edges of the triangles.
Multisample does nothing either.
Nothing in my shader does anything like that, its very simple.
It appears that the triangles edges are drawn either lighter or darker like a sort of soft aliasing.
Hopefully you can see it. Its not visible with textures drawn only when i shade white against the light and surface normals of the mesh, i mean open gl appears to be doing it…
Its not a bag deal with a texture but if that textures really smooth or reflective i can imagine it might become one.
Humm the normals are all passed in from the vertice data normalize.
By the time it gets to the pixel shader its just interpolated shading colors or white in this instance.
Maybe that’s not a straightforward thing though ?
Humm maybe the normals are messed up somehow but still how would they give off that effect.
Looks like vertexlighting in the screenshots. You are doing NdotL in vertexshader instead of pixel if you wanted pixel lighting it should be in the ps. i also did not see the dot product.
Or i did not understand what you want to achieve which is highly possible
When i pick it up again ill try to move it to the pixel shader see what happens.
All its doing is changing the color intensity at each vertices from white towards black if the dot is less then 1 then the color should get lerped as its passed to the shader right ?
i mean it clearly is just not on certain edges. which is really weird.
In the case not used here the lightcolor is just multiplied against the texture as a intensity its super hard to see the lines with a texture drawn.
It really does look like a normal is off on just one vertice of every other quad i must of messed something up somewhere…
The white line in the image i circled that’s the weird thing.
In the basic effect one its even more pronounced.
The line goes from white to black but stays white nearly the entire way.
That’s riding on the edge of a triangle, from a white vertice to a black one.
I’ve finally found your dot product, easier to look at the code when not on my mobile ^^
If you try the “shaded” mode on any model in FBX review app from autodesk, sometimes it gives about the same result. It may come from the normals/tangents missing or binormals bi tangents. (the GenerateTangentFrames checkbox in MG pipeline tool is related to this too)
I think if you do the dot product in the vertex shader it is done per vertex whereas in the pixelshader it is per pixel (if you have a normal to sample from, if not i don’t know as I’ve never tried).
Do you use a normal texture to sample from ?
I generate them after creating the mesh vertices with the below.
Maybe i messed it up, It calculates the normal from all connected triangles to the vertice by averaging them…
I tried uping the precision just to make sure some weird precision loss thing wasn’t going on and even normalized them in the function again.
But i can’t tell if they are correct by eye. ill have to make some separate test to see if they are coming out wrong. Don’t have time for it today.
/// This method creates smooth normals from a quad structured vertice mesh array
private PositionNormalColorUv CreateSmoothNormals(PositionNormalColorUv vertices, int indexs)
// Under quads there are two triangles per quad
// such that the triangle associated with normals in a proper indexed vertice list
// will describe per triangle all shared normals for each vertice.
// hence each vertice will be shared by 6 triangles ranging from 0 to 5
// so that for each vertice we must must calculate the surrounding triangle normals to average them.
// well just brute force this as its only done once on creation.
int tvertmultiplier = 3;
int triangles = (int)(indexs.Length / tvertmultiplier);
// Loop the vertices
for (int currentTestedVerticeIndex = 0; currentTestedVerticeIndex < vertices.Length; currentTestedVerticeIndex++)
// Reset are sum and total counts
float total = 0;
Vector3 sum = Vector3.Zero;
// loop thru each triangle
for (int t = 0; t < triangles; t++)
int tvstart = t * tvertmultiplier;
int tindex0 = tvstart + 0;
int tindex1 = tvstart + 1;
int tindex2 = tvstart + 2;
var vindex0 = indices[tindex0];
var vindex1 = indices[tindex1];
var vindex2 = indices[tindex2];
// Test each triangle for the currentTestedVertice presence
if (vindex0 == currentTestedVerticeIndex || vindex1 == currentTestedVerticeIndex || vindex2 == currentTestedVerticeIndex)
// Obtain a orthagonal direction from the surface of this triangle.
// This is basically a non unit length normal.
// Multiply by some amount 10 here to increase precision and avoid nans.
var n0 = (vertices[vindex1].Position - vertices[vindex0].Position) * 100f;
var n1 = (vertices[vindex2].Position - vertices[vindex1].Position) * 100f;
// Sum the cross product and increment the total
var cnorm = Vector3.Cross(n0, n1);
sum += cnorm * 100f;
total += 1;
// Find the average
if (total > 0)
var averagednormal = sum / total;
// Normalize the result
// Assign the normal to the vertice
vertices[currentTestedVerticeIndex].Normal = averagednormal;
Console.WriteLine(" SmoothedNormals: vertices[" + currentTestedVerticeIndex + "].Position: " + vertices[currentTestedVerticeIndex].Position);
Console.WriteLine(" SmoothedNormals: vertices[" + currentTestedVerticeIndex + "].Normal: " + averagednormal);