Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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
28 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
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
3 votes
Accepted

Vertex Shader Sphere Projection and CPU Distance Calculation

I ended up finding an answer. To obtain the center of a projected plane that is projected on the GPU, you need to take the position of the unprojected plane and project it. ...
Miguel Myers's user avatar
3 votes

Get closest point on box to line

I wasn't happy with any of the answers here, as I wanted an answer for the 3D case, so I went ahead and wrote a shadertoy which demonstrates how to query the closest point between a line and a box. ...
Nate Morrical's user avatar
2 votes

In Unity shaders, how is IN.worldRefl calculated?

The reflection vector is calculated as below: float3 refl = 2.0 * o.Normal * dot(o.Normal, IN.viewDir) - IN.viewDir; //float3 refl = IN.worldRefl; That equation is ...
이희민's user avatar
2 votes

How do I target a tank turret with an offset barrel?

Here I am over 10 years later providing another answer, hopefully this will help someone. If we look at the tank image below, we know we can calculate the angle A° pretty easily with atan2. Rotating ...
CustomCalc's user avatar
2 votes
Accepted

How to check if player actually went through a trigger area and didn't just touch it?

Here's one way you can do this, using dot products to check how far the vehicle is from the center of the trigger's transform along the trigger's z axis (blue arrow in the local transform gizmo). To ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Finding the closest point on a circle to end of a ray in 3D

First, if we only care about the endpoint of the ray, then we can forget it came from a ray at all (or really, a line segment, since it has a definite, finite extent). Just think of it as an ordinary ...
DMGregory's user avatar
  • 135k
1 vote

Representing a concave polygon as a hull "minus" convex cavities

Your triangulated mesh already represents a convex hull with a cavity, there's no need to perform additional collision checks only to invalidate previous tests. This potentially means additional ...
liggiorgio's user avatar
  • 4,821
1 vote
Accepted

How can I calculate vertex positions for a rectangle outline using a unit square, vertex normals, model matrix and outline thickness?

I have updated my Unity project which I think does what you want: https://github.com/paulsinnett/RectangleOutlineShader As long as you stick to integer coordinates, scales, and widths, I think it ...
Paul's user avatar
  • 131
1 vote
Accepted

How can I correctly pass 2 vertices instead of all 4 for a quad to a vertex shader?

I'm going to ignore your commentary about the possible ordering of four supplied quad vertices, as I don't think it's relevant to the question. The question(s) as I understand them, are: (a) can you ...
1 vote

Finding the closest point on a circle to end of a ray in 3D

I believe DMGregory approach is correct: Wouldn't this just be the endpoint minus the circle center, projected onto the circle plane, and normalized to the circle radius? We will break it down to ...
Theraot's user avatar
  • 27k
1 vote

How to check if player actually went through a trigger area and didn't just touch it?

If you want to know if the car is within a race track segment, then don't use OnTriggerEnter. Create a trigger area that covers the whole track segment, and use ...
Philipp's user avatar
  • 120k
1 vote
Accepted

Rotating around 3D cube Camera Controller for Unity

I just needed the approach that https://gamedev.stackexchange.com/users/21890/philipp said A rig inside the cube and a focus point inside the rig. and the following code solve this: ...
DamagedCyborg's user avatar
1 vote

How to get area of 2D shape bounded by vertical and horizontal line segments?

As long as your polygon has no holes, and you have a list of the corners of the shape in order as you walk clockwise around the perimeter, you can calculate the area directly using the shoelace ...
DMGregory's user avatar
  • 135k

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