Smooth shadows (normal calculation)

Started by
4 comments, last by lauris71 12 years, 7 months ago
Ok, I am probably just not thinking strait and this is possibly a very easy problem to solve, but, I can't seam to contemplate a way to dynamically generate the normals of a mesh of triangles...
(see picture for what my mesh is)
I know that if it was quads I could simply add up the surrounding normals and get my vertex normal, but I believe that in this that that wouldn't work... would I maybe have to add up the 4 surrounding boxes, and the boxes where there are two triangle ends meeting half the normal value?

Thanks for the help :)
meshmap.png
Advertisement
That's it, a flat pane? Then all the normals just point "up"/away from the face.
/edit: also, if you make a mesh in say 3DSMAX or Blender, don't you get the normals exported too?

That's it, a flat pane? Then all the normals just point "up"/away from the face.
/edit: also, if you make a mesh in say 3DSMAX or Blender, don't you get the normals exported too?


Its not a flat plane, sorry, I didn't mention that this picture was a top view, the y-axis can be modified with a height map file (i,e a 250x250 raw file, the red channel determining the y axis, pixel position determining the x,z axis... And its not made in 3DS, its made with .raw

I am fairly sure, just weighting the normals which take up 1/4 if the area around the vertex with 2x the weighting is the correct way, I was just not wanting to make a big stuff up :P
Well now that it's clear what it is, I'm sure someone here knows how to deal with heightmaps smile.gif
Has much more to do with someone who knows about linear algebra. See: Cross product, which will give you what you want. Also at wolfram.

Calculate the cross product for a triangle, then normalize said cross product.
As I understood the question was, whether to assign less weight to triangles which have less angular area around vertex.
There probably is not single "correct" solution. In normal application, where the sampling rate of your heightmap is sufficient (there are no sharp angles between adjacent triangles), you probably do not need to bother with it.
If unsure, you can go with two approaches:
1) calculate and normalize the average normal of divided square, then average over squres
2) calculate your normal directly from heightmap, by sampling at constant angles around your vertex.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

This topic is closed to new replies.

Advertisement