#Fix UVs in Generated Mesh
6 messages · Page 1 of 1 (latest)
I do something similar in my project (procedurally generated voxel mesh), but I'm using a vertices for a standard cube and a 2D array texture passed to the shader. I haven't had any issues like you are describing, though.
I don't fully understand what is causing your issue. Can you describe it in more detail? Any code snippets would also help.
Hmm, yea I'm not sure if the texture array does anything special other than just stacking multiple images into one file. I'm also building one mesh per chunk made up of many voxels, where each voxel returns its UVs / normals / vertices and then I append that to the mesh data. Here's what the sampling looks like in my shader:
var pbr_input: pbr_functions::PbrInput = pbr_functions::pbr_input_new();
pbr_input.material.perceptual_roughness = 0.98;
pbr_input.material.reflectance = 0.1;
pbr_input.material.emissive = vec4<f32>(0.001, 0.001, 0.001, 1.0);
pbr_input.material.base_color = textureSample(land_array_texture, land_texture_sampler, in.uv, i32(in.texture_idx));
My texture index is just a custom field on the Vertex that I pass for each voxel based on the biome.
The vertex data is just the 4 sides of a cube (e.g. for the top face):
// Top
([sp.max_x, sp.max_y, sp.min_z], [0., 1.0, 0.], [1.0, 0.]),
([sp.min_x, sp.max_y, sp.min_z], [0., 1.0, 0.], [0., 0.]),
([sp.min_x, sp.max_y, sp.max_z], [0., 1.0, 0.], [0., 1.0]),
([sp.max_x, sp.max_y, sp.max_z], [0., 1.0, 0.], [1.0, 1.0]),
I do remember having bleeding issues at one point a long time ago, so I wonder what exactly fixed that issue. Maybe it is the texture array 🤔.
I think the biggest difference is your code is using one texture for the entire mesh where as mine is taking a tiling texture and sampling that with UVs between 0 and 1 per voxel.
If you don't mind me asking, how did you manage to create such a nice slope effect? Is that just adjusted UVs, or are you doing actual vertex displacement / additional geometry?