We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › smooth triangles edges
Pages: 1 2 
smooth triangles edges (Read 4202 times)
smooth triangles edges
Dec 10th, 2009, 2:54pm
 
guys, how do i smooth these edges?

...

i want it to look round, not the way it looks.

thanks
Re: smooth triangles edges
Reply #1 - Dec 11th, 2009, 12:10am
 
have you tried smooth()?

(are you talking about the way the blue meets the green or the way that you can see the individual green triangles? they are different problems. the first needs antialiasing, the second surface normals and gouraud shading but i'm not sure i know how to fix either in processing.)
Re: smooth triangles edges
Reply #2 - Dec 11th, 2009, 6:20am
 
smooth() does nothing Sad i tried already.

yes, i'm talking about the second issue, the edges of the triangles.   it's suposed to look round like a lake or something, but those edges keep apearing anyway.

no i'm not talking about the blue intercepting the green.

i hate those edges, it's makes me remember those old school poor rendered game graphics.

i could make my triangles half the size, but then for the same terrain area, i would have 4 times more triangles to render..... i need to be carefull with that, because i have lot's off stuff to go into the sceane.
Re: smooth triangles edges
Reply #3 - Dec 11th, 2009, 6:27am
 
Maybe you should post the code that's generating the triangles and also let people know what renderer you're using (P3D/OPENGL?)...
Re: smooth triangles edges
Reply #4 - Dec 11th, 2009, 6:35am
 
here goes mate, the rendering part of the code (main).


Code:

 MyCamera cam;

 int raio = 20;
 int square = (raio*2) + 1;
 int meshindex=0;
 
 void setup()
 {
   size(800, 600, P3D);
   setgrid();
   cam = new MyCamera(60,-100,-100,60,0,0,0,0,1);
 }

void draw() {
 background(255);
 //smooth();
 //noStroke();
 //hint(ENABLE_OPENGL_4X_SMOOTH);
 ambientLight(50,50,50);

 keyboard();
 cam.Display();
 drawMap();
}

void drawMap()
{
 int q = 5;
 for(int x=0;x<(raio*2);x++)
 {
   for(int y=0;y<(raio*2);y++)
   {
     noStroke(););
     fill(0, 255,0);

     beginShape(TRIANGLES);  
     vertex((x*q),(y*q), -grid[x][y][0]*q);
     vertex((x*q),q + (y*q), -grid[x][y+1][0]*q);
     vertex(  q + (x*q), (y*q), -grid[x+1][y][0]*q);
                         
     vertex(  q + (x*q),  (y*q), -grid[x+1][y][0]*q);
     vertex( (x*q),   q + (y*q), -grid[x][y+1][0]*q);
     vertex(  q + (x*q),   q + (y*q), -grid[x+1][y+1][0]*q);                                      
     endShape();
     
     // gets the trees                                        
     objecto(grid[x][y][1],x*q,y*q,grid[x][y][0]*5);
                                             
     fill(255, 0, 0);
   }
 }
     // the blue thing
     fill(0, 0,255,150);
     beginShape(QUADS);
     vertex(0,0,0);
     vertex(0,200,0);
     vertex(200,200,0);
     vertex(200,0,0);
     endShape();
}
Re: smooth triangles edges
Reply #5 - Dec 11th, 2009, 6:39am
 
if i smooth() the triangles, it goes worst, i'll be able to see the blue stuff between triangles.

bad,bad,bad....

also, if i draw  sphere it's uses triangles too but itś very well smothed, so... there must be a way.
Re: smooth triangles edges
Reply #6 - Dec 11th, 2009, 7:06am
 
Well beginShape(QUADS) might be problematic for a start - unless you're sure the quads are flat in one plane, which I'd assume they're not on the blue section.  Only use triangles on curved 3D surfaces... and just use more triangles to make them smoother.  IIRC smooth()  in P3D can be problematic...
Re: smooth triangles edges
Reply #7 - Dec 11th, 2009, 7:09am
 
i read about triangle strip, i'll test that, i suspect they'll work better talking about surfaces. (meshes)
Re: smooth triangles edges
Reply #8 - Dec 11th, 2009, 7:42am
 
One word of warning: the whole triangle strip has to be the same colour (or I guess you could apply an image texture) so you may be better off working with triangles from the outset depending on your needs...
Re: smooth triangles edges
Reply #9 - Dec 11th, 2009, 8:25am
 
i think blindfish is mistaken about the quads - that defines the surface of the water and, well, that IS flat. the green is triangles and is fine. forget TRIANGLE_STRIP for now.

the way it's drawing the triangles it's using the same normal for each vertex. so the light calculations assign the same colour for each corner and the whole triangle looks flat (it's called Flat Shading because of this)(and i happen to like it!)

with the sphere that you mention it's also made of triangles but the normals at each vertex are different, match that of a ray drawn from the centre to the point. so the lighting for each corner will be different and the colouring of the triangle will blend smoothly. which is enough to make it look round.

there are also probably a lot more, smaller triangles in a sphere, which helps.

so, either define the correct normals for the points of your triangles or make the triangles smaller.

http://en.wikipedia.org/wiki/Gouraud_shading
http://electronics.howstuffworks.com/question484.htm
http://freespace.virgin.net/hugo.elias/graphics/x_polygo.htm
Re: smooth triangles edges
Reply #10 - Dec 11th, 2009, 8:36am
 
http://processing.org/discourse/yabb2/num_1147477505.html

this says that processing does smooth shading IF you define the normals yourself. you'll need another array holding the (3d) normal at each point. don't know how you're generating your points so i can't suggest how you calculate the normals but they need to be perpendicular to the plane that's tangential to the curve at the given point. (iirc)

and don't forget to normalise them or it'll screw up your lighting.

(am not sure we even covered this at university. i did both the graphics modules but it stopped at vector graphics, bezier curves and the like. there were some bitmapped screens attached to a couple of Suns but we never used them)
Re: smooth triangles edges
Reply #11 - Dec 11th, 2009, 8:43am
 
koogy wrote on Dec 11th, 2009, 8:25am:
i think blindfish is mistaken about the quads - that defines the surface of the water and, well, that IS flat.


Oops - I had based my assumption on the screengrab, but as you say in the code it is flat...  Embarrassed

And agreed - I like the flat-shaded retro look.  I loved Zarch on the archimedes Wink
Re: smooth triangles edges
Reply #12 - Dec 11th, 2009, 10:32am
 
thanks very much.
so, if i'm not mistaken i need this:

normal(nx, ny, nz)

right?
Re: smooth triangles edges
Reply #13 - Dec 11th, 2009, 10:41am
 
yes.

the real trick is knowing how to calculate nx, ny and nz for each point (they are variables)
Re: smooth triangles edges
Reply #14 - Dec 11th, 2009, 11:19am
 
i found this:

     normal_x = (y2 - y1)*(z3 - z1) - (z2 - z1)(y3 - y1);
     normal_y = (z2 - z1)*(x3 - x1) - (y2 - y1)(z3 - z1);
     normal_z = (x2 - x1)*(y3 - y1) - (x2 - x1)(x3 - x1);

but... it's no going very well .... i'm trying.
Pages: 1 2