Hi, all.
I'm working on terrain editor, and the idea so far, is to have a set of textures I could place on each square with UV coords 1x1. I wrote a simple shader, which samples from 2 different textures, depending on UV coords, but for some reason, even though the textures should connect seamlessly, I'm having a strange artifact pixels on the seams. Now the really funny part, is that it works perfectly on a crappy Intel on-board video card, and doesn't work on my GTX500 with drivers up to date (!!!)
For instance, on an arbitrary hexagonal surface I sample everything, except for one square from grass texture, and one square from desert texture.
Magnified (Where are those pixels sampled from exactly? o.O)
Vertex shader code:
precision highp float;
precision highp int;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
attribute vec3 position;
attribute vec2 uv;
varying vec2 vUv
void main()
{
vUv = uv;
vec4 mvPosition;
mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
}
Fragment shader code:
precision highp float;
precision highp int;
uniform vec3 diffuse
uniform float opacity;
varying vec2 vUv;
uniform sampler2D map;
uniform sampler2D map1;
void main()
{
gl_FragColor = vec4( diffuse, opacity );
vec4 texelColor;
if(vUv.x >= 0.0 && vUv.x < 1.0 && vUv.y >=0.0 && vUv.y < 1.0) // <- Sample from a different texture for that square
texelColor = texture2D( map1, vUv );
else
texelColor = texture2D( map, vUv );
gl_FragColor = gl_FragColor * texelColor;
}
JSFiddle link (sorry for a big chunk of code, embedded textures take some space). The code is first 100 lines, everything below is THREE.js code to render the scene (Scroll wheel: dolly in/out, left click: rotate, right click: pan) -> https://jsfiddle.net/denisve/aucxz90s/
What am I doing wrong? The code is pretty straight forward, just sample from a different texture depending on UV.
Thanks in advance,
Denis.