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.
Page Index Toggle Pages: 1
Normals or not (Read 1208 times)
Normals or not
Dec 5th, 2009, 9:14am
 
I am currently creating a 3D shape library and when a shape is created the user can specify whether or not they want the surface normals to be calculated and used.

The idea was to reduce the amount of calculation on OpenGL if shading wasn't required.

In the various shape classes I am using the P5 normal() function to set the normals (if reqd) but when I (eventually) looked at the documentation for this it stated

Quote:
Processing attempts to automatically assign normals to shapes, but since that's imperfect, this is a better option when you want more control. This function is identical to glNormal3f() in OpenGL.

The experiments I have carried out seem to indicate little difference in execution speed whether the shape was created with or without normals.

If there is no difference I can calculate the normals by default and simplify the shape drawing method,  but before I do that I thought it might be a good idea to see if anyone knows a good reason for leaving this option in. Smiley


The library is not ready for download yet you can preview some examples here.
http://www.lagers.org.uk/s3d4p/applets/s3d4p_earthandmoon/index.html
Re: Normals or not
Reply #1 - Dec 6th, 2009, 7:05pm
 
I've been working on quite the same thing, already being able to draw a myriad of shapes with different controlable parameters, i found nice to be able to switch normals on and of for in case i wanted to use, for example, my sphere function to draw an octahedron, or my cylinder function to draw a cube (by setting different parameters for u and v subdivisions), maybe you'd like to leave it Tongue.
Re: Normals or not
Reply #2 - Dec 7th, 2009, 2:39am
 
Hi Quark, I will say yes, give the option, and set a default value for it

Thanks for the efforts
rS
Re: Normals or not
Reply #3 - Dec 8th, 2009, 6:25am
 
Hi Guys

Thanks for your comments. I am still undecided but I am leaning towards calculating and using the normals by default because

(1) It is more efficient to calculate the normals at the same time as the XYZ coordinates, this is important if the shape has several hundred triangles.

(2) The amount of memory used is not that important beacause it will be dwarfed by the memory needed for the OpenGL textures and to maintain a decent frame rate the number of shapes to be drawn is unlikely to be large.

(3) Since P5 is going to try and create normals I might as well create accurate ones based on the shape.

(4) I want to keep the number of if statements in the draw method to an absolute minimum, testing whether a normal is to be used for each vertex might be less effiecient than just using one.

[fdevant]
Quote:
my cylinder function to draw a cube (by setting different parameters for u and v subdivisions)

Although not obvious from the examples you can do the same with this library by defining the number of subdivisions in the class constructor. Do you have any examples online I would be interested in seeing them.

Thanks again.  Cheesy


Page Index Toggle Pages: 1