如何在 WPF 3D 中使用顶点处的值对网格着色?
我们有一个球体,我们想要以 3D 方式显示它,并给定一个依赖于球坐标的函数。
使用 (theta, phi) 中的规则网格对球体进行三角测量,但这会在两极附近产生许多小三角形。为了减少极点处的三角形数量,我们更改了网格生成以在表面上生成更均匀大小的三角形。
第一种三角测量方法的优点是我们可以轻松创建纹理并将其覆盖在表面上。似乎在 WPF 中不可能像在 OpenGL 或 Direct3D 中那样为顶点分配颜色。
使用第二种三角测量方法,如何生成纹理和设置纹理坐标并不明显,因为顶点不再与网格对齐。
也许可以创建一个包含每个顶点颜色的线性纹理,但这将如何影响着色呢?通过应用每个顶点着色,它仍然会像人们所期望的那样在三角形表面上平滑地渲染吗?
We've got a sphere which we want to display in 3D and color given a function that depends on spherical coordinates.
The sphere was triangulated using a regular grid in (theta, phi), but this produced a lot of small triangles near the poles. In an attempt to reduce the number triangles at the poles, we've changed out mesh generation to produce more evenly sized triangles over the surface.
The first triangulation method had the advantage that we could easily create a texture and drape it over the surface. It seems that in WPF it isn't possible to assign colors to vertices the way one would go about in OpenGL or Direct3D.
With the second triangulation method it isn't apparent how to go about generating the texture and setting the texture coordinates, since the vertices aren't aligned to a grid any more.
Maybe it would be possible to create a linear texture containing a color for each vertex, but then how will that effect the coloring? Will it still render smoothly over the triangle surfaces as one would expect by applying per vertex coloring?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经将算法转换为使用线性纹理,这实际上只是对颜色图的查找。这似乎很有效,并且是比前一个更好的解决方案。我现在只创建 256 x 1 的固定纹理,而不是创建大小为 ThetaSamples * PhiSamples 的纹理。
I've converted the algorithm to use a linear texture which is really just a lookup into the colormap. This seems to work great and is a much better solution than the previous one. Instead of creating a texture of size ThetaSamples * PhiSamples, I'm now only creating a fixed texture of 256 x 1.