[英]Transparency of ModelVisual3D with DiffuseMaterial
I come across a problem which seems a bug for me. 我遇到了一个对我来说似乎是个问题的问题。 I'm making an app that visualizes atoms in a crystal.
我正在制作一个可视化水晶原子的应用程序。 That problem is that it draws a transparent object and hides the object behind.
问题是它绘制了一个透明对象并隐藏了后面的对象。
Here is the code: 这是代码:
foreach (var atom in filteredAtoms)
{
var color = new Color();
color.ScR = (float)atom.AluminiumProbability;
//color.G = 50;
color.ScB = (float)atom.MagnesiumProbability;
//setting alpha channel but Opacity doens't work as well
color.ScA = (float)(1.0 - atom.VacancyProbability); //(float)1.0;//
DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(color));
//material.Brush.Opacity = 1.0 - atom.VacancyProbability;
// make visuals and add them to
atomBuldier.Add(new Point3D(atom.X * Atom.ToAngstrom, atom.Y * Atom.ToAngstrom, atom.Z * Atom.ToAngstrom), material);
}
When I change the material to eg EmissiveMaterial there are no "cut" atoms. 当我将材料更改为例如EmissiveMaterial时,没有“切割”原子。 I googled this post , but the advices given don't apply to this case.
我用Google搜索了这篇文章 ,但给出的建议并不适用于这种情况。
Is this a bug with 2D brush applied to 3D? 这是2D刷子应用于3D的错误吗?
The full source code can be found here http://alloysvisualisation.codeplex.com the dll and a test file http://alloysvisualisation.codeplex.com/releases beta link. 完整的源代码可以在这里找到http://alloysvisualisation.codeplex.com dll和测试文件http://alloysvisualisation.codeplex.com/releases beta链接。
Steps to reproduce: 重现步骤:
For the transparent atoms, you must disable z-buffer-writing. 对于透明原子,必须禁用z缓冲区写入。 I'm unfamiliar with WPF, but you can probably set this in an Appearance or Material object or so.
我不熟悉WPF,但你可以在Appearance或Material对象中设置它。
The problem occurs because of the following: 出现此问题的原因如下:
When a transparent atom is rendered, it writes its depth to the z-buffer. 渲染透明原子时,它会将其深度写入z缓冲区。 Subsequent non-transparent atoms that are rendered and should appear, do not get written to the frame buffer, because their z-values fail the z-test, because of the z-values already in the z-buffer of the transparent atom.
渲染并且应该出现的后续非透明原子不会被写入帧缓冲区,因为它们的z值未通过z测试,因为z值已经存在于透明原子的z缓冲区中。
In short, the graphics card treats the transparent atom as opaque and hides anything behind it. 简而言之,显卡将透明原子视为不透明并隐藏在其后面的任何东西。
Edit : Upon looking into WPF it seems pretty high-level, without direct control of z-buffer behavior. 编辑 :在查看WPF时,它似乎非常高级,没有直接控制z缓冲区行为。
According to this link , the emissive and specular materials do not write to the z-buffer, so using those is your solution when working with transparent objects. 根据此链接 ,自发光和镜面反射材质不会写入z缓冲区,因此在使用透明对象时使用这些材料是您的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.