Update: I’ll keep this version up for now, as the intro has some information worth reading. I’m rewriting ch2 to actually make sense and finishing 3 and 4 when i get the time, sorry.
As i’m slightly active in various gamedev communities, I’ve noticed over time that a (seemingly) large portion of people have little to no experience when it comes to the “how, why and where” in the 3D graphical department of their engine of choice. There are loads of sites that explain these things in great detail from A to Z, but few that explain it in a short, concise and specific setting relating to game engines. Probably because the codemonkey guy on the team usually isn’t the one to do the 3D modeling and vice versa, but i digress.
In this relatively short 101 I’ll be using Unity as an example, but all of the theory applies to Godot, UE and practically any modern game engine under the sun. If you’ve directly touched on OpenGL or Direct3D in your life then – wait, why are you even here then?
However, if youve never touched a 3D modeling application in your life, you’ve only worked with the assets available through your chosen game engine and you want to learn the “whys and hows” of the models on your screen – read on.
Overview
- Introduction to 3D models
- General information and terminology
- Working with models in-engine
- Mesh
- Collider
- Modifying the model
- Code along!
- Shaders
- Types of shaders
1. Introduction to 3D models
Considering you’re even remotely interested in learning about this, I’ll assume youve gotten your hands slightly dirty and looked and wondered at things such as: wireframe, materials, renderer, shaders etc etc. These things and more will be covered (eventually) in this document.
For all intents and purposes, the model displayed on your screen consists of nothing but points (vertices) in 3D space with lines (edges) drawn between them. Considering your model could have thousands of these points, there has to be some rhyme or reason to where these lines are drawn, right? Well, there is, but luckily you don’t have to care about that for now at least.
As the picture shows, a simple 3-dimensional box consists of 8 vertices, one in each corner, that are connected by edges. 3 vertices made up of 3 edges create a face, as seen on the 3rd box. All of the triangles on the 3rd example are faces, but i decided to highlight only two to show how they are connected. As you can see in this case, a single vertex is directly connected to 5 other vertices via edges and if we were to raise the polygon count we would get:
the same cube but with more edges, verts and faces. As you can imagine and probably already know, the more of these polygons you have, the more resource-heavy it’ll be to render and display.
The layout of these vertices and edges is referred to as topology. The topology itself is what describes how the mesh of the model itself is structured. The entirety of this as well as textures/materials is the model itself. Now you know the basic terminology and pretty much what you need to start messing with it all.
2. Working with models in-engine
Now that we ended the last chapter talking about models and meshes we’ll continue with some code and hands-on approach on the mesh itself. Depending on the mesh itself.
Both the mesh itself and the mesh collider behave by the same rules in terms of how they are structured, even though they do vastly different things in practice. They both consist of a mesh and everything that entails.
A more direct approach on how you can modify a flat plane via directly altering the position of the vertices on the model:
Vector3[] vertsPlane = new Vector3[flatPlane.Length]; for (int i=0;i<vertsPlane.Length;i++) { Vector3 vertices = planeHeight[i]; //copy contents in order to assign them later vertices.x //modify each coordinate and see what happens vertices.y vertices.z }