- Home /
Is there any way to tile a texture within a single triangle of a procedural mesh?
Background:
I'm interested in creating a usable voxel engine myself because I love sandbox games, like making games, and don't enjoy using somebody else's pre-packaged solutions.
The engine is cube-based (no fancy smoothed-out terrain or anything.) I use a chunk system, of course. Each chunk's individual blocks are combined into a single mesh. Since I haven't started actual terrain generation, the chunks are just being generated as 8x8x8 cubes for now.
As far as optimization goes, I've already made it so that most unnecessary faces (those that aren't visible) aren't added to the combined mesh - meaning that the computer doesn't have to deal with those triangles.
I'm still worried about performance. With only eight of these chunks in view at the same time, the fps starts to get worryingly close to 60 (which is the fps I hope to achieve with a reasonable render distance when I get to an actual game.) Admittedly, my computer isn't a super-machine, but it can handle many more Minecraft chunks at a similar fps (and those are much larger than mine.)
There's nothing else going on in this scene besides chunk-rendering, so I need to make it run more efficiently.
I'm using Unity (free version) 4.[something].[something] on Windows 7.
Situation:
Now that I've already gotten rid of the vast majority of triangles just by not adding unnecessary faces, I'm looking to further reduce triangle count by combining groups of cube faces in the same chunk, on the same plane, and with the same uvs into larger rectangles (only two triangles, as opposed to however many there would be otherwise.)
However, I seem to have hit a road block. When I eventually texture these chunks, I don't want the textures to be weirdly stretched on the larger rectangles. Which brings me to my question: is there any way to make a texture tile itself within a triangle?
As far as I know, UV coordinates absolutely have to correspond to vertices, so adding more UV coordinates won't help performance.
Thank you in advance for any help you can give!
Answer by MrCrinkle · Nov 11, 2013 at 03:53 AM
You should be able to multiply the UV coordinates based on how many block you're combining into the combined face. So if you were combining a 3x3 grid of blocks into a single face, then the new coords for that face would be 3 times the regular coords for a block.
Would that work with a texture atlas, though? I suppose I should have mentioned that, but since a single mesh in Unity can only have one texture, I would have to use a texture atlas to achieve blocks of different appearences, so the UV coords wouldn't be (0,0) through (1, 1). $$anonymous$$ultiplying the coordinates then would include bits of other graphics, right? Unless there's a trick that lets you actually use multiple textures on a gameObject.
Thank you for the response - I wasn't aware of that technique.
Edit: I believe I've found a way to tile with an atlas. See link below.
http://answers.unity3d.com/questions/214837/is-possible-to-tile-within-a-texture-atlas.html
(Although it might not work with procedural meshes. The easiest solution I've found would be making a long, one-block-tall texture atlas, and then tiling necessary parts in one-directional strips.)
Actually, do you know how much of an advantage there is to having fewer meshes if the triangle count is the same? Because I could increase chunk size, have multiple chunks occupying the same space (one per block type), and base membership in the chunks exclusively on block type, meaning I could use a smaller texture and tile it much more easily. There would need to be more of a data structure in place to handle that, though.
With that method, I could make the average material's chunk such a size that the triangle count would be similar to the current chunks' (so there wouldn't be very many more meshes after all.) With the extra "thinking" that the game would have to do to process the extra/illogical data structures, would it be worth it?
Another downside is that when the chunks are loading, one material would display before another...I'd better stick all the ores in last if I do that :P