# Vertex normal and 3 points gradient

This topic is 4632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, my first post here.. I'm trying to build a software graphic engine in Java (Yeah I know Java might not be that great for graphics, and there are already a bunch of good,good enough, free graphic engine for Java. I know, I know... It's just for fun! It'll be ugly and run at 10 fps, but w/e!). -VERTEX NORMAL Anyway, I want to do lighting based on vertex normal instead of surface normal and I'm wondering how to store the vertex normal? Normally it'll be easy, one vertex as one normal, but say in a cube, each vertex will have 3 normals, because each faces surrounding that vertex belongs to a different smoothing group. I want to be able to have smooth _AND_ sharp edges. So how should I do that? 1. have 2 arrays, 1 for the smoothing group of that vertex, and the other for storing the vertex normal. So I'd do a search in the first array for the smoothing group of the face I'm currently drawing, then use the index it returns to get the right normal. 2. duplicate every vertex that belong to a different smoothing group. So a cube would have 24 vertices instead of 8. 3. an other way... -3 POINTS GRADIENT How can I create a 3 point gradient in java _without_ J3D, JOGL,... maybe an other package, but I dont want to use a 3D engine package, I'm making my own! Thanks

##### Share on other sites
Quote:
 Original post by IarusAnyway, I want to do lighting based on vertex normal instead of surface normal and I'm wondering how to store the vertex normal? Normally it'll be easy, one vertex as one normal, but say in a cube, each vertex will have 3 normals, because each faces surrounding that vertex belongs to a different smoothing group. I want to be able to have smooth _AND_ sharp edges.

so for the cube you'd have to store 3 verticies [each with their own normal]

Quote:
 Original post by Iarus-3 POINTS GRADIENTHow can I create a 3 point gradient in java _without_ J3D, JOGL,... maybe an other package, but I dont want to use a 3D engine package, I'm making my own!

one pixel at a time... the math isn't really that complicated.

##### Share on other sites
Since nobody else posted, I guess you all hate me! or everybody duplicate vertex when using multiple smoothgroups. I dont really like this method because I'll have to work with a lot more vertices, but I guess it'll be easier than my other way of complicating everything.

For the 3 points gradient thing, you say it's simple maths, so I guess I'll figure it out, else I'll google it again.

##### Share on other sites
Yes, you guessed it, everyone hate you ^^

For the vertex normal question. In hardware rendering (eg. OpenGL or DirectX) there is only 1 normal for 1 vertex. So, if you want a sharp edge, you have to split the vertices (create a new one to introduce a new normal) on the edge. This way, you only have to duplicate vertices on sharp edges. That's the way OpenGL and DirectX do.

For the interpolation, if you want to get the color of the point X (which is inside a triangle) you simply have to compute the distance to the 3 points of the triangle. Based on that, compute a value between [0.0 1.0] for each point like :

value1 = dist1 / (dist1 + dist2 + dist3);
value2 = dist2 / (dist1 + dist2 + dist3);
value3 = dist3 / (dist1 + dist2 + dist3);

and then, you have colorX = value1 * color1 + value2 * color2 + value3 * color3
Their may be better ways to interpolate value between 2 points (this way probably gives strange results outside the triangle ^^) but I think it works ^^

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002275
×