I have a subroutine that creates an animated displacement map and a normal map. I have used these maps to create a couple of MeshPhysicalMaterials - one that includes both maps (along with a texture map) and one that includes only the normal map (and no texture map, only a color). I have created two different types of plane geometries to hold these materials: one that will hold the first material and another that is 4X larger that will hold the second material. To make things consistent, I need to repeat the second material 4X on the second geometry.
What is the best way to repeat materials on the second geometry? Here is what things look like right now:
You can see the clear line of demarcation where the materials get larger again.
I have seen a lot about repeating textures, but very little about repeating materials. Here, if I make the textures repeat, then they will repeat for both geometries (and that may also mess up the computation of those textures).
I have tried the following material shader extension that will change the UVs for a diffuseColor:
onBeforeCompile: shader => {
shader.fragmentShader = `
${shader.fragmentShader}
`
.replace(
`#include <color_fragment>`,
`#include <color_fragment>
vec2 uv2 = fract(vUv * 2.0);
diffuseColor.a = 1.0 - (uv2.x * uv2.y);
`
);
}
But it appears to have no effect on the normalColor.
I could define the geometry of the second plane to include 4 segments, but is there a way to insert a material in each segment?
I have tried something like this:
let geometry2 = new THREE.PlaneGeometry(size,size,2,2);
let materials2 = [material2,material2,material2,material2];
let mesh2 = new THREE.Mesh(geometry2,materials2);
But that does not seem to work.
I have also tried:
let geometry2 = new THREE.PlaneGeometry(size,size,2,2);
let materials2 = [material2,material2,material2,material2];
geometry2.groups=[];
var triangles=2;
var vertices=triangles*3;
for(let n=0;n<4;n++){
geometry2.groups.push({start:n*vertices,count:vertices,materialIndex:n});
}
let mesh2 = new THREE.Mesh(geometry2,materials2);
Again, no joy.
Also, since I am merely repeating the same material 4X, I would like to minimize the number of draw calls for each plane, if that is possible.
EDIT
My initial assumption may have been wrong. The problem seems to disappear when I use repeat.set(2,2) on the normal texture before it is used to construct material2.
However, the problem then reappears at higher altitudes - perhaps mipmaps are playing a role here?