- Home /
What are normals?
Hello, all. I'm new to mesh modification through scripting, and I was trying to make a simple two tri four vertice square for a bullet hole. However, the shader for the bullet hole is the standard transparent diffuse. Whenever I hit a surface that will trigger a bullet mark, it says "Shader Wants normals, but mesh doesn't have them" As I said, I'm all new to this, so I was just wondering if someone could explain to me what normals are and how to set them to the code below:
var m : Mesh = new Mesh();
var i : float = bmSize/10;
m.vertices = [Vector3(-i, i, 0), Vector3(i, i, 0), Vector3(i, -i, 0), Vector3(-i, -i, 0) ];
m.uv = [Vector2 (0, 0), Vector2 (0, 1), Vector2(1, 0), Vector2 (1, 1)];
m.triangles = [0, 1, 2, 0, 2, 3];[0, 1, 2, 0, 2, 3];
Thanks In Advance! :)
Answer by Waz · Jul 01, 2011 at 11:46 AM
You want this function. Also, read this.
To extend this answer ( which is actually the solution ;) ):
A normal vector is a vector the is perpendicular to it's underlying surface.
In 3D rendering each vertex can have a surface normal to simulate a different shape than the original geometry has. The normal is used by a shader when it's calculating the lighting.
Everything is made up of triangles. Spheres would never look round and smooth if they are just made up of triangles but with surface normals the edges almost disapear.
Here's a good example of the difference between flat and smooth shading
I guess I should also mention that in Unity, there are only vertex normals (since that's what you need to render stuff). There is only one normal for each vertex or (as in your bug), none for any vertices, in a mesh.
Well, in computer graphics there are always just vertex normals since the whole rendering is build on top of vertex-stream-processing. It's possible to set shader globals to supply a normal for a single face but that's quite unusual ;)
Just to have it mentioned another (additionally) way to provide normals are normal-maps
Some get confused because some modeling programs have vertex/surface normals and something they call face-normals. The face normal isn't a real normal that is defined by a vector. It's just the winding order of the vertices that defines the direction of the face.
This is important for back-face-culling when the shader, like most, render only one side.
Do some modelling programs really have even vertex normals (except for rendering)? I can't imagine wanting to edit them other than to reverse the winding order of the face. I'm pretty sure Blender doesn't, even though some people want it (eg. to make smooth corners with 1/3 to 1/2 less vertices).
Well, i'm not an artist so i don't use modelling tools that often ;) Fact is that the graphics pipeline only processes vertex-data that made up the mesh. "Face normals" are just a visualisation of the winding order. Actually it seems blender just lacks of the possibillity to edit the vertex normals manually but it generates them automatically ins$$anonymous$$d.
I don't want to criticise blender in any way. I think it's one of the best free / opensource modelling tools out there ;) I just can't use it :D
http://jsgreenawalt.com/Blender-DTS-Exporter/documentation/dts-meshes/vertex-normals.html