# White dots artifacts when applying borders to hex tiled geometry

I have a hexagon tiled geometry I created in Blender

Which I then load in WebGL, using THREE.js library. Below is the loading code, I've cut the code of creating scene, lights, etc. I create rendered with antialiasing flag.

grassTexture = new THREE.ImageUtils.loadTexture( 'textures/GrassTileModo.png');
grassTexture.wrapS = grassTexture.wrapT = THREE.RepeatWrapping;

{
var attr = []
for(var i = 0; i < geometry.faces.length; i++)
{
if(i % 4 == 0)
att = [new THREE.Vector3(1.0, 0.0, 0.0), new THREE.Vector3(0.0, 1.0, 0.0), new THREE.Vector3(0.0, 0.0, 1.0)];
if(i % 4 == 1 || i % 4 == 2)
att = [new THREE.Vector3(1.0, 0.0, 0.0), new THREE.Vector3(0.0, 0.0, 1.0), new THREE.Vector3(0.0, 1.0, 0.0)];
if(i % 4 == 3)
att = [new THREE.Vector3(1.0, 1.0, 1.0), new THREE.Vector3(1.0, 1.0, 1.0), new THREE.Vector3(1.0, 1.0, 1.0)];

attr.push(att);
}

var material = new THREE.ShaderMaterial( {
uniforms:
{
diffuse: {type: 'c', value: new THREE.Color(1, 1, 1)},
opacity: {type: 'f', value: 1.0},
map: {type: 't', value: grassTexture},
},
attributes:
{
aBorderMap: {type: 'v3', value: attr, boundTo: 'faceVertices'}
},
} );

plane = new THREE.Mesh(geometry, material);

});


Basically, the idea is I assign each vertex barycentric coords, and use them to know which edge I need to outline. Since my hexagons are getting tesselated by blender to 4 faces each, I assign different attributes to different faces, the way edges I don't need to outline are not outlined. In my case on the edges I don't want to outline, z barycentric coordinate will be zero.

This is how blender tesselates:

precision highp float;
precision highp int;

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
attribute vec3 position;
attribute vec2 uv;
varying vec2 vUv;
attribute vec3 aBorderMap;
varying vec3 vBorderMap;

void main()
{
vUv = uv;
vBorderMap = aBorderMap;
vec4 mvPosition;
mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
}


precision highp float;
precision highp int;

uniform vec3 diffuse;
uniform float opacity;
varying vec2 vUv;
uniform sampler2D map;
varying vec3 vBorderMap;

void main()
{
gl_FragColor = vec4( diffuse, opacity );

vec4 texelColor;
if(vBorderMap.x <= 0.05 || vBorderMap.y <= 0.05)
texelColor = texture2D( map, vUv ) * 0.5  + vec4(0.0, 0.0, 0.0, 1.0) * 0.5;
else
texelColor = texture2D( map, vUv );
gl_FragColor = gl_FragColor * texelColor;
}


When I zoom out those artifacts can be clearly seen:

Although zoomed in it looks much better:

At first I thought lack of antialaising was a problem, but when I added it, it didn't help.

EDIT:

full screen ---> https://jsfiddle.net/denisve/ad74pf77/5/embedded/result/

WARNING: Huge embedded image there, so will take some time to load, sorry about that, didn't find a way to use external images on jsfiddle.

• EDIT: Also tried to use mipmapping and anisotropy filter, didn't help. – user1617735 Sep 22 '15 at 20:09
• ANOTHER EDIT: Texture is power of 2, of course. – user1617735 Sep 22 '15 at 20:11
• AA and AA filters are still filters, there are "frequencies" which'll go through them, also do you actually have geometry meeting there? If so neither kind of filtering will help that. Try creating TINY gaps in the blender mesh. – Alec Teal Sep 22 '15 at 20:16
• The geometry meets properly. Without the code that creates outlines there is no artifacts. Also if I just put hardcoded color instead of sampling the texture, it also looks fine, and there's no artifacts. – user1617735 Sep 22 '15 at 20:24
• Add the texture please – Alec Teal Sep 22 '15 at 20:24

You need to use texture linear filtering or nearest filtering.

texture.minFilter = THREE.LinearFilter;

• Actually I solved this by removing ifs from fragment shader code. Apparently shaders don't like sampling under branching. So the solution was to sample both textures and then take the appropriate pixel for fragment color calculations. – user1617735 Nov 16 '15 at 16:58
• @user1617735 it would be good to add this as its own answer and mark it accepted, so users with similar problems can easily find your solution. – DMGregory Jan 15 '16 at 17:42