Vertex normal generation

This is a discussion on Vertex normal generation within the Game Programming forums, part of the General Programming Boards category; I am currently working on a fractal based game engine. This engine generates a fractal world (yes it's actually roundish) ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    37

    Vertex normal generation

    I am currently working on a fractal based game engine. This engine generates a fractal world (yes it's actually roundish) from a set of functions and refines it and unrefines it in real time as you run across the surface. Currently I have the world generation, collision detection, and camera working so I can move around the surface. However I haven't started shading it yet. I have face normals and I more or less know how to generate vertex normal's from them. I intend to use procedural shading.

    However there is a problem. Sometimes the fractal algorithm generates sharp peaks and stuff like that. I want to be able to set a threshold so that sharp peaks (i.e. drastic changes in normals from one face to the next) are not smooth shaded so they look realistic. I know how to handle this in DirectX but I need a good algorithm to figure out how many normals are needed per vertex and to which triangles they apply. Does anyone know of a good algorithm that will smooth shade up to a point but allows for non smooth shading for sharp corners? I have a couple possible ideas I but I wanted to find out if there was some standard way to handle this.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by SyntaxError View Post
    I am currently working on a fractal based game engine. This engine generates a fractal world (yes it's actually roundish) from a set of functions and refines it and unrefines it in real time as you run across the surface.
    Yer a nut!

    Anyway, if this provides any perspective, in openGL "smooth" vs. "sharp" or curved vs. faceted surfaces are dealt with by using additional normals for each vertex of a polygon/quadratic surface, vs. using only one normal for each flat segment.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    37
    Quote Originally Posted by MK27 View Post
    Yer a nut!
    I won't argue with that However, now that I have all the bugs out of the collision detector (which took me an eon) it actually works quite well and it gives me some big advantages over a normal game engine. a) I can make my game world as large as I wan't. b) I don't have to store terrain data anywhere. c) I can generate a whole new world to play on in a matter of seconds.

    Several other people are working on the same thing so there must be a few other nuts out there. When someone finally builds a viable engine my feeling is it's going to take over MMORPGs. Think of being able to put all players on a single shard (ala EVE online) however with full terrain and everything.

    Quote Originally Posted by MK27 View Post
    Anyway, if this provides any perspective, in openGL "smooth" vs. "sharp" or curved vs. faceted surfaces are dealt with by using additional normals for each vertex of a polygon/quadratic surface, vs. using only one normal for each flat segment.
    Actually that part I know. It's just I'm not sure who to determine what faces get the version of a vertex with a particular normal. For instance if you have a vertex surrounded by 6 triangles you could have 1 normal, or 6 different normals or 2 different normals or various other combinations depending on the triangles.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by SyntaxError View Post
    I won't argue with that However, now that I have all the bugs out of the collision detector (which took me an eon) it actually works quite well and it gives me some big advantages over a normal game engine. a) I can make my game world as large as I wan't. b) I don't have to store terrain data anywhere. c) I can generate a whole new world to play on in a matter of seconds.
    I meant nut in a good way. Hooray! Vis, the thing with OGL and "normals for quadratics", I just got myself introduced to it yesterday (which is why it was stuck in my brain), so I can't comment any further. But I think there are a couple people who could who might be around here sooner or later...ITMT I would try 2 different normals before I would try 6 :x
    Last edited by MK27; 06-06-2009 at 07:12 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    37
    Well I think I figured something out on my own. You can just walk the faces surrounding the vertex in a loop, sum up the normals and divide by the number of faces. The caveat is wherever the angle of normals between two consecutive faces are greater than your threshold, you assign your current normal average to the vertex in question of the faces you have already traversed, then clear your sum and count and keep going. Hopefully this will let you shade ridgelines correctly while keeping smooth shading where you want it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple (?) problem rendering a vertex buffer
    By Dark_Phoenix in forum Game Programming
    Replies: 4
    Last Post: 08-11-2007, 08:32 PM
  2. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 08:55 PM
  3. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 04:33 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  5. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 02:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21