如何在Unity中像Minecraft一样的立方地形块的不同面应用不同的法线贴图纹理?

问题描述:

我正在Unity中制作一个程序生成的类似于Minecraft的体素地形。网格生成和反照率通道纹理完美无瑕;但是,我需要针对不同的立方体面应用不同的法线贴图纹理,以了解它们是否与另一个立方体相邻。材质仅接受单个法线贴图文件,而不能为法线贴图提供sprite-sheet-editor类功能。因此,我不知道如何使用法线贴图文件中的选定切片,就像它们是反照率纹理一样。我找不到有关此问题的任何相关资源。任何帮助将不胜感激。谢谢...

I'm making a procedurally generated minecraft-like voxel terrain in Unity. Mesh generation and albedo channel texturing is flawless; however I need to apply different normal map textures for different cube faces regarding whether they're neighboring to another cube or not. Materials accepts only single normal map file and doesn't provide a sprite-sheet-editor kind of functionality for normal maps. So I have no idea about how to use selected slices out of normal map file as if they were albedo textures. I couldn't find any related resources about the problem. Any help will be appreciated. Thanks...

首先,我不是该领域的专家,尽管我将尝试

First of all, I'm not an expert in this area, though I am going to try to help you based on my limited and incomplete understanding of parts of Unity.

如果存在有限数量的正常人脸图,则可以帮助您。对于可能存在的图像,我建议您使用类似的指示( sprite sheet),并创建包含所有这些法线贴图的单个纹理(有时也称为纹理图集)。

If there are a finite number of "normal face maps" that can exist, I suggest something like you indicated ("sprite sheet") and create a single texture (also sometimes called a texture atlas) that contains all these normal maps.

下一个步骤(我不确定标准材质明暗器是否适合您的情况)是为法线贴图生成UV /纹理坐标,然后将其与顶点xyz位置一起传递给明暗器。 UV坐标必须针对每个面的每个顶点。它们被指定为法线贴图集的2-D(U,V)偏移量,并且是[0.0,1.0]范围内的浮点值,它们映射到实际法线贴图的完整X和Y坐标。例如,如果您有一个带有4行4列纹理网格的图集,则应使用左上角纹理的面的UV坐标为[(0,0),(0.25,0),(0.25 ,0.25),(0,0.25)]。

The next step, which I'm not sure whether the Standard material shader will be to handle for your situation is to generate UV/texture coordinates for the normal map and pass those along with your vertex xyz positions to the shader. The UV coordinates need to be for each vertex of each face; they are specified as a 2-D (U, V) offset into your atlas of normal maps and are floating point values with a range of [0.0, 1.0], that map to the full X and Y coordinates of the actual normal texture. For instance, if you had an atlas with a grid of textures in 4 rows and 4 columns, a face that should use the top-left texture would have UV coords of [(0,0), (0.25,0), (0.25,0.25), (0, 0.25)].

这里的困难可能取决于您是否要使用UV坐标进行其他纹理贴图(例如在反照率或其他地方)。如果是这种情况,我认为Unity Standard Shader允许使用两组纹理坐标,如果需要更多纹理坐标,则可能必须滚动自己的着色器或在其他地方找到允许更多UV集的Shader资产。这是我对抖动的理解的地方,因为我不能完全确定着色器如何使用这两个UV坐标集,以及是否存在一些有关如何使用这些UV坐标的约定,因为标准着色器支持辅助/详细贴图,这可能意味着您必须与所有非详细地图共享UV0集,例如反照率,法线,高度,遮挡等。

The difficulty here may depend if you are you using UV coordinates for doing other texture mapping (e.g. in the Albedo or wherever else). If this is the case, I think the Unity Standard Shader permits two sets of texture coordinates, and if you need more, you might have to roll your own shader or find a Shader asset elsewhere that allows for more UV sets. This is where my understanding of gets shaky, as I'm not exactly sure how the shader uses these two UV coordinate sets, and whether there is some existing convention for how these UV coordinate are used, as the standard shader supports secondary/detail maps, which may mean you have to share the UV0 set with all non-detail maps, so albedo, normal, height, occlusion, etc.