Home:ALL Converter>Normal Mapping and Per Vertex Normal

Normal Mapping and Per Vertex Normal

Ask Time:2011-05-12T18:01:30         Author:Ricardo Sanchez

Json Formatter

I am fairly new to opengl programming, and I have always struggle getting the vertex normal calculations for my 3d shapes, it always depends on how I draw and calculate the triangles, so I wonder if I can avoid the normal calculations by using normal mapping?

Any help and/or reference material will be much appreciated

Author:Ricardo Sanchez,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/5976349/normal-mapping-and-per-vertex-normal
datenwolf :

No you cannot avoid the normal calculations if using normal mapping. Actually you've to calculate two additional vectors for each vertex, tangent and binormal, to make normal mapping work.\n\nHowever I don't see your problem. Calculating a normal is about the easiest thing to do. Pseudocode for per face and per vertex normal calculation:\n\nforeach face in model.faces:\n face.normal = crossproduct(\n model.vertices[face.vertindex[1]].pos - model.vertices[face.vertindex[0]].pos, \n model.vertices[face.vertindex[2]].pos - model.vertices[face.vertindex[0]].pos )\n foreach v in face.vertindex:\n model.vertices[v].in_faces.append(face)\n\nforeach vertex in model.vertices:\n vertex.normal = (0,0,0)\n for face in vertex.in_faces:\n vertex.normal += face.normal\n vertex.normal = vertex.normal / length(vertex.normal)\n\ncrossproduct(v0, v1):\n return (\n v0.y * v1.z - v0.z * v1.y,\n v0.z * v1.x - v0.x * v1.z,\n v0.x * v1.y - v0.y * v1.x,\n )\n",
2011-05-12T11:51:04
alxx :

Normal mapping allows to specify per-pixel normals to use in pixel shader. But these per-pixel normals usually only perturbing interpolated normals, so you need to calculate them anyway. You can get rid of vertex normals only if they would be backed up into textures.",
2011-05-12T10:09:01
yy