Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mesh loader and normal discontinuity  (Read 1432 times)
0 Members and 1 Guest are viewing this topic.
Offline pixel

Junior Newbie




And the thing


« Posted 2003-05-26 22:35:34 »

Hi,

I have written a mesh loader for MS DirectX .x files (just the mesh components for now, no textures, animation) and can display the loaded mesh using lwjgl drawing triangles and setting normals etc.

The problem is that when I specify a gl.normal3f() for each triangle (at a right angle to the triangle), the faces are predictably heavily faceted under lighting (like a crystal).

Does anyone have any recommendations for how I can display a poly model consisting of triangles so that the surface is smooth rather than heavily faceted (like a crystal)

I am happy to share the mesh loader on this forum when it is finished

Pixel  Wink

Edit:

Having a look around, it seems that I will need to specify per vertex normals which are averaged between normals for each face.

Additionally, the gl.enable(gl.NORMALIZE) call seems to be important in rendering with Gouraud shading.

Does anyone have any working examples or links to an applicable tutorial (C or C++ is fine) for per vertex normal calculation and OpenGL rendering of triangle meshes with Gouraud shading?

Pixel
Offline Mojomonkey

Senior Devvie




ooh ooh eee eeee


« Reply #1 - Posted 2003-05-27 01:03:32 »

You need to do what's called normal averaging. Basically smoothly interpolating between the normals of a face. Instead of calculating the normal for just the face, calculate the normal for each vertex. Where the normal for a single vertex is the average of the normals of each face it touches. Hope that helps.

Don't send a man to do a monkey's work.
Offline pixel

Junior Newbie




And the thing


« Reply #2 - Posted 2003-05-27 02:30:50 »

Thanks Mojomonkey,

Does anyone have sample code to calculate per vertex normals?

Once I have them, do I just call gl.normal3f() just before gl.vertex3f()?

My Mesh object contains (amongst other things)

1) a Vertex [] of vertices
2) a Vertex [] of normals for each triangle
3) a Triangle [] where each triangle lists the index of each point and an index for the normal for the triangle

Pixel
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pixel

Junior Newbie




And the thing


« Reply #3 - Posted 2003-05-27 02:38:39 »

I suppose I could:

1) walk the triangle array indexing each vertex according to the triangles that contain that point.

2) Accumulate the indexes to the normals for each attached triangle for every vertex.

3) Acquire an average normal by adding each x,y,z component from the adjacent triangle normals and dividing each component total by the number of normals.

avNormal.x = (adjNormal1.x + adjNormal2.x + adjNormal3.x) / 3.0f;

avNormal.y = (adjNormal1.y + adjNormal2.y + adjNormal3.y) / 3.0f;

avNormal.z = (adjNormal1.z + adjNormal2.z + adjNormal3.z) / 3.0f;

Is it that easy?  Or is there some funky vector math that I should use to average a set of normals?

Pixel  :-/
Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #4 - Posted 2003-05-27 07:45:26 »

That's basically it, but for smoother results you can take the size of each face into account, instead of giving each the same weighting in the average.

I believe that this is done in idx3d, which can be found here. It's a software renderer that does phong shading, environment mapping and other stuff, all in java 1.1.  Digging around the source may turn up some tips.
Offline pixel

Junior Newbie




And the thing


« Reply #5 - Posted 2003-05-27 09:30:50 »

Thanks Bleb,

I tried what I was suggesting and the results are very promising.  The loader just calculates the per vertex normal as it is loading the mesh.

The result is certainly smooth enough for the engine I am writing.

Now for some texturing....
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (28 views)
2014-11-22 12:13:56

xFryIx (70 views)
2014-11-13 12:34:49

digdugdiggy (49 views)
2014-11-12 21:11:50

digdugdiggy (43 views)
2014-11-12 21:10:15

digdugdiggy (37 views)
2014-11-12 21:09:33

kovacsa (61 views)
2014-11-07 19:57:14

TehJavaDev (65 views)
2014-11-03 22:04:50

BurntPizza (63 views)
2014-11-03 18:54:52

moogie (79 views)
2014-11-03 06:22:04

CopyableCougar4 (78 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!