使用 Three.js 绘制纹理
纹理泼溅可以与 Three.js 或其他 Javascript 3D 渲染框架一起使用吗?如果是的话,我想看看示例,甚至是大地形上的教程。如果它不起作用,还有其他方法绘制大地形图吗? 谢谢。
Does texture splatting works with Three.js or other Javascript 3D rendering framework? If yes I'd like to see example maybe even tutorial on large terrain. If it doesn't work is there any other way mapping large terrains?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已接受的挑战!
首先,您可以编写一个灰度图像并将其用作高度图的顶点着色器,并包含不同的浮点(称为
vamount
)以传递到片段着色器以确定纹理(s)在这一点上显示(混合)。接下来是片段着色器,它可以包括不同的高程所需的许多纹理,并且有一个很棒的内置功能,称为
smookestep
,使平滑过渡更易于计算。这样的片段着色器的代码示例:
然后,您可以使用
trex.shadermaterial
将其用于给定的网格。以上代码在
这可以帮助您入门。愉快的编码!
Challenge accepted!
First, you can write a vertex shader that takes a grayscale image and uses it as a heightmap, and includes a varying float (called
vAmount
below) to pass to the fragment shader to determine the texture(s) to display(blend) at that point.Next comes the fragment shader, which can include however many textures you need for different elevations, and there is a great built-in function called
smoothstep
that makes smooth transitions much easier to calculate.An example of code for such a fragment shader:
Then you can use a
THREE.ShaderMaterial
to use this for a given mesh. The above code is implemented at http://stemkoski.github.io/Three.js/Shader-Heightmap-Textures.html and produces a result like this:Hope this helps you get started. Happy coding!