We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I'm trying 3D with custom lights for the first time and I keep coming across this line that appears once in almost all my shapes. I think it has to do with the calculation of the normal for every plane and the ending of the row. Is there anything I can do to fix this? My code is really long so I won't send you it but this is the draw function for my tree:
void draw(){
fill(30,87,37);
for(int i=0; i< vertexes.size()-1; i++) {
ArrayList<PVector> first=vertexes.get(i);
ArrayList<PVector> last=vertexes.get(i+1);
if(first.get(0).x != first.get(first.size()/2).x) {
beginShape(TRIANGLE_STRIP);
for(int j=0; j< first.size(); j++){
PVector pt1=first.get(j);
PVector pt2=last.get(j);
vertex(pt1.x, pt1.y, pt1.z);
vertex(pt2.x, pt2.y, pt2.z);
}
endShape();
}
}
}
I am using an ArrayList<ArrayList< PVector > > to store vertexes from the fractal and then drawing them with this. I am actually using a PShape now but you get the idea.
I suspect the shading is caused by a vertex that's normal is undefined as it links two rows. I am currently at a loss as to how to fix this. Can anyone help?
Answers
You can supply per-vertex normals for better shading. Just call normal() before each vertex() call. See: https://www.processing.org/reference/normal_.html
Thanks! I everything looks so much better!