Hot answers tagged

72 votes
Accepted

Why are normal maps predominantly blue?

There are two types of normal maps commonly used in game development. The way you are thinking they should work is the way one type works (model-space normal maps), but most games use another type (...
user avatar
  • 2,308
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 (...
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 ...
user avatar
  • 114k
10 votes
Accepted

What is the cause of this lighting artifact on my dynamic terrain mesh?

This isn't caused by your UVs or by your normals. The problem is triangle interpolation, and it's a very common problem for quad-based heightmaps. Here's a closeup of a small portion of your ...
user avatar
8 votes

Why are normal maps predominantly blue?

The normal map mostly points outward from a surface. Assuming you go with the usual mapping of the Z component of the XYZ normal vectors being the "depth" direction and an that mapping to the B ...
user avatar
7 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 ...
user avatar
7 votes
Accepted

Calculated normals for mesh not working

vec3 norm = vec3(uViewMatrix * uModelMatrix * aNormal); The normal cannot be transformed like a point, to transform a normal you use the inverse transpose matrix. If you want the fun details of why ...
user avatar
  • 601
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 ...
user avatar
4 votes
Accepted

Marching Cubes Vertex Normals

Essentially, the normal of the vertex would be the average of the adjacent faces' (triangles) normals. In pseudocode: ...
user avatar
  • 3,775
4 votes
Accepted

Normal matrix space has to be eye space?

It's common for people to compute lighting in eye space because of how the specular component of lighting in the Phong model is calculated. Doing the calculation in view space, allows you to avoid a ...
user avatar
4 votes
Accepted

SSAO issue - surfaces darken based on camera angle

To me it looks very much like your issue here is that you are mixing world and viewspace or something similiar. Now your GBuffer normals look like they might be in viewspace in that picture, but the ...
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 ...
user avatar
  • 114k
3 votes
Accepted

Make a plane to display material from both sides

You need to edit your shader source file in order to add "Cull Off" inside, more info here If you are not writing your own shaders (and so use default provided Unity shaders) then you can look at ...
user avatar
3 votes
Accepted

Malformed/Pixelated Vertex Normals

There is nothing inherently wrong with your original code when it comes to normalization. The only problem can be with meshes that do not properly share vertices, meaning your normalization code will ...
user avatar
3 votes
Accepted

How many normals are needed to have a smooth surface?

The way you are computing vertex normals only considers an individual quad and not its neighbours. Thus you get the discontinuities between the somewhat flat quads. If you want smooth normals, the ...
user avatar
  • 4,074
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: ...
user avatar
3 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 ...
user avatar
  • 114k
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 ...
user avatar
  • 14.5k
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 ...
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 ...
user avatar
  • 114k
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, ...
user avatar
  • 18.5k
2 votes

GLSL Normals not transforming propertly

Andon is making the correct assumption I believe. Specifically, the n vector in the vertex shader should be assigned as ...
user avatar
2 votes
Accepted

What is wrong with my specular phong shading

I have found the answer (and now I feel stupid) int DotOfNormalAndLight = Vec3Df::dotProduct(normal,relativeLightPos); should have been ...
user avatar
  • 965
2 votes

OpenGL: why do I have to set a normal with glNormal?

Minimal example that illustrates some details of how glNormal works with diffuse lightning. The comments of the display ...
user avatar
2 votes
Accepted

Calculating the winding and normal when programatically adding triangles to a mesh

I don't completely understand the problem you're having, but this is a sketch of an extrusion algorithm Supposing polygon is an array of 3D points in counter-...
user avatar
  • 13.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: ...
user avatar
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 ...
user avatar
  • 1,351
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 ...
user avatar
  • 1,351
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 ...
user avatar
2 votes

Getting scene normals in Unity

you can use Replacement Shader to Displaying Mesh Normals First attach this script to camera: ...
user avatar

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