When I have an empty scene with a camera and directional light, I have 2 Tris and 4 Verts by default. I went to lighting and deleted the skybox and now have a blue background. Why do I have an empty scene with Tris and Verts already? [Image 1 attached below]
I generate a single mesh with the following code:
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class TestQuadScript : MonoBehaviour
{
void Start()
{
MeshFilter meshFilter = GetComponent<MeshFilter>();
meshFilter.mesh = BuildQuad(1f, 1f);
}
private Mesh BuildQuad (float width, float height)
{
Mesh mesh = new Mesh ();
// Setup vertices
Vector3[] newVertices = new Vector3[4];
float halfHeight = height * 0.5f;
float halfWidth = width * 0.5f;
newVertices [0] = new Vector3 (-halfWidth, 0,-halfHeight);
newVertices [1] = new Vector3 (-halfWidth, 0,halfHeight);
newVertices [2] = new Vector3 (halfWidth, 0,-halfHeight);
newVertices [3] = new Vector3 (halfWidth, 0,halfHeight);
// Setup UVs
Vector2[] newUVs = new Vector2[newVertices.Length];
newUVs [0] = new Vector2 (0, 0);
newUVs [1] = new Vector2 (0, 1);
newUVs [2] = new Vector2 (1, 0);
newUVs [3] = new Vector2 (1, 1);
// Setup triangles
int[] newTriangles = new int[6] { 0, 1, 2, 3, 2, 1 };
// Setup normals
Vector3[] newNormals = new Vector3[newVertices.Length];
for (int i = 0; i < newNormals.Length; i++) {
newNormals [i] = Vector3.forward;
}
// Create quad
mesh.vertices = newVertices;
mesh.uv = newUVs;
mesh.triangles = newTriangles;
mesh.normals = newNormals;
mesh.RecalculateNormals(); // ? Better to use?
return mesh;
}
}
I now have 6 Tris and 12 Verts? What am I doing wrong 2x the number expected? [Image 2 attached below]
Is RecalculateNormals faster than the code above?
When posting here with an image URL tag, whats the best image hosting service? I tried imgur but the link shows a picture with a red X when linking (like below). What’s the preferred means to upload files when posting here?
You can use Window > Analysis > Frame Debugger to find out what Unity renders. You can click on each draw call and in the Preview tab see how many verts it renders in that draw call.
In your 30x30 quads case I would expect the scene to contain a total of 30x30x2 = 1800 triangles and the 1.7k in your stats seems to be close to that. Do you expect less triangles due to not all of the quads being visible to the camera? If frustum culling worked as expected I would expect less than 1800 but my guess is that Unity has combined all the quads into one large mesh because they have the same material and you have static or dynamic batching enabled.
Remember though that without batching you would have 900 draw calls if all the quads were visible at once and that would be much worse for performance so in this case it’s better to render 1800 triangles in just a few draw calls
Note that the rendering stats window is not a triangle or vertex staticsts of your scene, but a rendering statistic. So the number of tris / verts listed there are how many verts / tris has been rendered per frame. A two pass shader would render the same triangles twice. Likewise fullscreen post processing effects usually add another fullscreen quad (2 triangles) to the statistics. See Rendering Statistics Window for more details.
Thanks for your reply, appreciated. I guess another way to approach that would be to break the grid into chunks, that way you get the benefits of batching and frustrum culling whilst adding a few draw calls if more than one chunk was visible at the same time in the camera view.