• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Halsafar

Calculate Terrain Normals

5 posts in this topic

So I'm not quite sure how to calculate the normals for my terrain. I've never had to calculate normals for anything yet so this is foreign. What should be my first step? I have the vertices and the indices used to formulate the triangles.
0

Share this post


Link to post
Share on other sites
Firstly you need to create the face normals (normals for each triangle). This is quite easy to do. Just get two edges of the triangle and then crossproduct them tog et the normal, for example


v0-----v1
|
|
|
|
v2



edge1 = v1-v0
edge2 = v2-v0
normal = cross(edge1,edge2)
normalize(normal)

or something similar (I might have the order of the edges in the crossproduct the wrong way around, Im fairly drunk/tired right now).

Then once you have done this for every triangle you can find the vertex normals.

You see, if you just use the faec normals your terrain lighting will seem somewhat odd (plus you will have to render with triangle lists not strips). To get the vertex normals, just take the average of all the normals of the rtiangles surrounding the vertex, for example:


v0----v1----v2
|\ |\ |
| \T1 | \T3 |
|T0\ |T2\ |
| \ | \ |
v3---v4----v5
|\ |\ |
| \T5 | \T7 |
|T4\ |T6\ |
| \ | \ |
v6---v7----v8


v4 would average the face normals from T1,T2,T7,T6 and T5 to find the vertex normal. Ive also heard that you should weight the normals, so T2 and T5 would have greater impact since they have a larger angle at v4, though Ive never tied it myself.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Drazgal
Im fairly drunk/tired right now

Damn good job for drunk and tired! Rating++

There are also faster approximations by just crossing the diagonal points and using those. It avoids the need to calculate normals for faces first. So in Drazgal's example, you could cross (v8-v0) with (v6-v2) to get the normal for v4. It's not the same calculation, and can cause problems. It works great for my system, though. The real explanation of this can be found in my old post, here. Credit to oliii of course.
0

Share this post


Link to post
Share on other sites
I have used many kinds of calculations for terrain normals, but the best is just to calculate first face normals and then per vertex normals, even if it's optimized it will take time (more complex terrain structures, more time it takes). So basically:


a = v1-v0
b = v2-v0
r = a cross product b
r.Normalize();


After doing that for each face you'll have to find faces for each vertex :


for (int v=0; v<num_vertices; v++)
{
int num_adjents=0;
int *storage = new int [num_faces];

for (int f=0; f<num_faces; f++)
{
if (faces[f].a == v)
storage[num_adjents++] = f;
else if (faces[f].b == v)
storage[num_adjents++] = f;
else if (faces[f].c == v)
storage[num_adjents++] = f;
}


for (int a=0; a<num_adjents; a++)
{
vertices[v].n.x += faces[storage[a]].nx;
vertices[v].n.y += faces[storage[a]].ny;
vertices[v].n.z += faces[storage[a]].nz;
}

vertices[v].n.x /= num_adjents;
vertices[v].n.y /= num_adjents;
vertices[v].n.z /= num_adjents;

vertices[v].n.Normalize();

delete [] storage;
}




But that isn't the fastest way to do that, you could have list of faces in every vertex and then add the faces in some loop where you go trough faces. :)
0

Share this post


Link to post
Share on other sites
This should help you.

But try using search next time.. this is anwserd even on the same page you posted...
-1

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
But try using search next time.. this is anwserd even on the same page you posted...

You may have not noticed, but search is disabled. You could always train everyone to search gamedev with google. By the way, how can you be sure this post was not posted before the other post on this page?

Why is everyone so damn grumpy?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0