【发布时间】:2019-05-16 02:03:50
【问题描述】:
我有这个几何:Picture
我想添加山与雪纹理等相同的效果:
Texture splatting with Three.js
我从 Three.js 向着色器提供什么信息的小背景:
//importing grass and snow textures:
var grassTexture = new THREE.ImageUtils.loadTexture( 'images/grass-512.jpg' );
grassTexture.wrapS = grassTexture.wrapT = THREE.RepeatWrapping;
var snowTexture = new THREE.ImageUtils.loadTexture( 'images/snow-512.jpg' );
snowTExture.wrapS = snowTExture.wrapT = THREE.RepeatWrapping;
this.customUniforms = {
grassTexture: { value: grassTexture },
snowTexture: { value: snowTexture },
};
var customMaterial = new THREE.ShaderMaterial({
uniforms: customUniforms,
side: THREE.DoubleSide,
vertexShader: document.getElementById( 'vertexShader' ).textContent,
fragmentShader: document.getElementById( 'fragmentShader' ).textContent,
});
//creating mesh, geometry is the model in picture.
mesh = new THREE.Mesh(geometry, customMaterial);
顶点和片段着色器:
//vertexShader:
varying vec2 vUV;
void main(){
vUV = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
我用这个得到全红色模型:
//fragmentShader:
void main(){
gl_FragColor = vec4(1, 0.0, 0.0, 1.0) ;
}
我想要使用 snowTexture 较高且使用 GrassTexture 较低的纹理。
uniform sampler2D grassTexture;
uniform sampler2D snowTexture;
varying vec2 vUV;
//Something like this?:
vec4 grass = texture2D( grassTexture, vUV);
vec4 snow = texture2D( snowTexture, vUV);
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) + grass + snow;
【问题讨论】:
-
bumpTexture的内容是什么?它是否包含法线向量和/或位移高度?如果它是平面几何,那么你可以做到。newPosition = position + normalize(bumpnormal) * bumpheight);。如果几何由一个镶嵌平面组成,并且模型空间中平面的法向量为 (0, 0, 1),这将起作用。更准确地说,如果地图中的法线向量在模型空间中。 -
基本上我希望顶点着色器遍历所有已经创建的顶点,而不是将它们移动到任何地方,现在当我应用它时,它会创建一组全新的顶点。 BumpTexture 包含我使用加载器函数加载的 three.js 中的纹理
-
很难理解您在 OP 中的含义以及“遍历所有顶点”的含义,我建议您编辑您的帖子并尝试使其更清晰。您提供的链接使用纹理作为置换贴图来控制顶点的高度。如果这不是您想要的,那么也许这不是一个好的起点。
-
好吧,我改了,也许现在你能理解得更好了。