Skip to main content
44 votes
Accepted

What is a "normal" in game development

Direct Answer I see that other answer going into technical details, but I don't know if that hits the spot for answering "What are even normals" - so here's a plain English answer for ...
Raphael Schmitz's user avatar
33 votes

What is a "normal" in game development

In the context of geometry, a normal is a vector that is oriented perpendicular to a given object. It is commonly used for lighting calculations, but it can also be used to for calculating visibility, ...
Pikalek's user avatar
  • 12.4k
29 votes
Accepted

How do game engines avoid recalculating normals upon mesh rotation?

They don't. When you rotate a mesh, the normals in memory are not changed in any way. All that changes is the object's transformation matrix is updated. The raw mesh vertex and normal data remains ...
DMGregory's user avatar
  • 135k
28 votes
Accepted

How can I get the normal vector for a plane from a set of vertices?

You could easily find the normal by calculating two vectors, V1 = P2-P1, and V2 = P3-P1, and then find the cross product N = V1 x V2. Then you normalize N. Depending on the ordering of the vertices (...
Hermetix's user avatar
  • 507
16 votes

What are some good examples of the practical usages of cross product in game development?

Generating Normals As Maximus Minimus notes in the comments, when we have a mesh without normal vectors (say just raw vertex positions from a procedural generator or 3D scanned point cloud), we can ...
DMGregory's user avatar
  • 135k
16 votes

How do game engines avoid recalculating normals upon mesh rotation?

DMGregory's answer explains how this is actually handled, but I'd like to point out a couple of misconceptions: Assume that a face of a mesh is defined by vertices ...
Kevin Reid's user avatar
  • 5,498
8 votes

Confused About My Code Suggesting The Normal Matrix Is Equivalent To The ModelView Matrix

When a matrix is orthogonal, inverse and transpose are equivalent making an inverse transpose equal to the original matrix. So if your model view matrix is orthogonal, the normal matrix will be equal ...
GettingShwifty's user avatar
5 votes
Accepted

How does one calculate the surface normal, in 2D collisions?

I think the following may help. You have the sphere center, box center and hopefully the details of the rectangle. Since the rectangle may be rotated we need the rectangle extents, and the ...
Biggy Smith's user avatar
4 votes
Accepted

Consistent normals at any angle in bezier curve

I'm not sure why you say the suggestion in the comments "gets worse" - I implemented it and it performs as expected: In each of these examples we have the same cubic spline being wrapped in a tube ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

Normal Matrix in plain English

You need to use a different matrix to transform your normal vectors when your model's transformation might include non-uniform scale. When we stretch a shape along, say, just the y axis, the y ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

How to calculate verticle normals of triangular mesh

It looks like some normals are pointing the wrong way. This means that those triangles aren't wound correctly. As a quick fix you can do: ...
ratchet freak's user avatar
3 votes

Algorithms for calculating vertex normals in 2D polygon

First, obtain the normals for each edge of the polygon. The normal for an edge is given by the normalized cross product of the edge vector (p2 - p1) with the 2D ...
EvilTak's user avatar
  • 932
3 votes
Accepted

How to know if two surface are in the same direction?

Imagine applying a force along those normals to the faces. If the normals both face in the same direction (e.g. outward), then it would have a book closing effect, the faces would get closer. If they ...
Bálint's user avatar
  • 14.9k
3 votes

What are some good examples of the practical usages of cross product in game development?

Many.. many things: calculating normals for light/physics calculation using for calc distances (point/plane) checking orientation of (2D)-Polys (are they left or right wound?) calculating 2D-area of ...
Peter Parker's user avatar
3 votes
Accepted

Why is this back-facing texture showing through?

When you set a material to be transparent, by default this also disables it from writing to the depth buffer. This is important for avoiding ugly cut-out effects, where a transparent or faintly ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

Convert a dot product scalar for a triangle's slope, into a translation ratio?

I don't understand your setup. However, 0.707106 looks familiar to me. It is approximately this: $$\frac{1}{\sqrt{2}}$$ And you say that is a 45º slope, right? So, ...
Theraot's user avatar
  • 27.2k
2 votes
Accepted

How do I make my indices anti-clockwise, so I can cull triangles in OpenGL? (immediate mode)

Solved by reversing the indices for the problematic bottom face. Indices are now: ...
Alex V-P's user avatar
2 votes
Accepted

How to achieve good looking surface net normals?

A common way of generating vertex normals for a mesh is to sum the normals of the faces that touch each vertex, then normalize those sums. You're part-way there with taking cross-products from the ...
Victor T.'s user avatar
  • 1,381
2 votes
Accepted

How do I calculate normals correctly for dynamic terrain (DX11, C++)?

I see several bugs, if I understand the structure of your mesh correctly. I think it's a grid of triangles, arranged so pairs of triangles form squares. First, when calculating ...
Victor T.'s user avatar
  • 1,381
2 votes

Using indices in obj files and handling normals

First convert the obj mesh to a non-indexed mesh with vertex+normal+other attributes. Then convert back to indexed by merging identical vertex entries. The 2nd step can be made generic to be re-used ...
Stephane Hockenhull's user avatar
2 votes

Getting scene normals in Unity

you can use Replacement Shader to Displaying Mesh Normals First attach this script to camera: ...
Seyed Morteza Kamali's user avatar
2 votes
Accepted

Why does Unity ignore normals when calculating backfaces?

This is not a decision by Unity, but a standard part of the GPU rendering pipeline. (See eg. OpenGL) The primitive assembly step can be configured to discard faces based on their winding order on the ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Algorithms for calculating vertex normals in 2D polygon

If I understand the question correctly we have the following: Given a list of numbers (I'm going to presume we're working with doubles or decimals) we need to transform this into a sequence of 2D ...
theheadofabroom's user avatar
2 votes
Accepted

Calculating surface normal numerically

You should use the Sobel opererator, which is a type of convolution filter. A 3x3 pixel convolution would work fine, but you need to do it twice: once for horizontal edges, then once for vertical ...
Bram's user avatar
  • 3,719
2 votes
Accepted

Unity - Blender models/animations showing gaps

You shouldn't put two faces with inverted normals instead, you have to use a Double Sided Shader in unity to show the backfaces too. if it's a custom shader, you can write ...
Mohammad Zamanian's user avatar
2 votes
Accepted

How to check if two normals/directions "look at" each other?

Given points P0 and P1 with normals N1 and N2... ...
Bram's user avatar
  • 3,719
2 votes
Accepted

Explain how Inigo Quilez calculates SDF box normals

We are looking at the function boxIntersection. I'll reiterate the information from the comment: // axis aligned box centered at the origin, with size boxSize We ...
Theraot's user avatar
  • 27.2k
2 votes
Accepted

How To Convert World Space Normal To Tangent Space?

Your coordinate conversions are incorrect. The tangent and normal attributes that three.js provide to you are in object space. ...
DMGregory's user avatar
  • 135k
1 vote
Accepted

Converting between world coordinate systems

Every time you interchange two axes, or negate an axis, you mirror space. So to go from xzy to zy-x we perform: Interchange <...
DMGregory's user avatar
  • 135k
1 vote

Converting between world coordinate systems

Your mesh should not be in world space. It should be in "object space". It can then be scaled/translated/rotated into world space by homogeneous transform matrices on the GPU. This includes changes ...
Ian Young's user avatar
  • 2,649

Only top scored, non community-wiki answers of a minimum length are eligible