|
|
|
 |
Reply From: |
Zylann |
Textures need texture coordinates, a.k.a UVs. These are regular Vector2
attributes you can add when building your geometry, for each vertex.
For example, a quad made of 4 vertices might have the following UVs: (0,0), (1, 0), (1, 1), (0, 1)
.
More complex models require to think about “unwrapping”, like a paper origami, to properly layout the UVs. It can be based on typical primitives like cylinders, quads or spheres, which have several known working UV layouts.
A quick alternative for really complex models is to use triplanar mapping. This technique generates UVs based on vertex coordinates, at the cost of a few more computations in the shader, so that your mesh doesn’t need to have UVs. You can toggle this option in SpatialMaterial
.
Note: the same applies to colors. You can color a model by changing albedo
in the material, but you can also specify colors per vertex (if the material has use_vertex_color_as_albedo
checked).
So at what point do I create this UV, will I have to dynamically create it each frame after I have used my calls to create the immediate geometry?
Also how is it possible to unwrap intimidate geometry as its mesh is not known at build time?
NewDevTrying | 2019-07-17 19:02
You have to do it for every vertex that you add to ImmediateGeometry
. This is per vertex, so that the renderer knows which coordinate of the texture to use on every specific point of the mesh:
immediate_geometry.set_uv(uv1) # Used for the next vertex
immediate_geometry.add_vertex(position1)
immediate_geometry.set_uv(uv2) # Used for the next vertex
immediate_geometry.add_vertex(position2)
immediate_geometry.set_uv(uv3) # Used for the next vertex
immediate_geometry.add_vertex(position3)
# etc
You might not know the mesh beforehands, but maybe you know at least what kind of mesh it is. Is it a ribbon? A tube? A heightmap? A completely arbitrary shape? If it’s the latter, triplanar shading might be easier.
Zylann | 2019-07-17 19:44
Ok, so I guess if you use set_uv, add_vertex pairs Then after I just apply a texture as normal once to the overall mesh?
NewDevTrying | 2019-07-17 19:49
Yes once you have UVs you can apply textures from a SpatialMaterial
.
Zylann | 2019-07-17 19:50
thanks very much
NewDevTrying | 2019-07-17 20:43