我在地形的片段着色器中使用纹理混合来从一个纹理混合到下一个纹理。就在仅使用我的草纹理和混合泥土/草或雪/草纹理之间的接缝处,mipmap 似乎造成了丑陋的接缝(见下图)。禁用 mipmapping 可以解决问题,但会使我的地形在远处变得非常粗糙/难看。有没有办法在不禁用 mipmapping 的情况下消除这种接缝?
地形-vs.glsl:
precision mediump float;
attribute vec3 Position;
attribute vec2 TextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 texCoord;
varying float y;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(Position, 1.0);
texCoord = TextureCoord;
y = Position.y;
}
地形-fs.glsl:
precision mediump float;
uniform sampler2D dirt_texture;
uniform sampler2D grass_texture;
uniform sampler2D snow_texture;
varying vec2 texCoord;
varying float y;
void main(void) {
if (y < -5.0) {
gl_FragColor = texture2D(dirt_texture, texCoord);
} else if (y < 0.0) {
gl_FragColor = mix(
texture2D(dirt_texture, texCoord),
texture2D(grass_texture, texCoord),
(y + 5.0) / 5.0
);
} else if (y < 3.0) {
gl_FragColor = texture2D(grass_texture, texCoord);
} else if (y < 5.0) {
gl_FragColor = mix(
texture2D(grass_texture, texCoord),
texture2D(snow_texture, texCoord),
(y - 3.0) / 2.0
);
} else {
gl_FragColor = texture2D(snow_texture, texCoord);
}
}
纹理管理器::初始化
gl.bindTexture(gl.TEXTURE_2D, texture.texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
配置:
- 视窗 7 专业版 SP1
- 谷歌浏览器 24.0.1312.57 m
- 英伟达 GTX 680
正常视图
放大