Firemonkey半透明Image3D有时是不透明的

Dav*_*ois 7 delphi firemonkey

我创建了一个带有3个半透明tImage3D的FireMonkey应用程序.这是代码和屏幕.一切似乎都很好.

procedure TForm1.Form3DCreate(Sender: TObject);

// create a new semi-transparent timage3d
// object with color and Z position.
procedure NewImage ( const nColor : tColor;
                     const nZ     : integer );
begin
  // create the image
  with tImage3D . Create ( self ) do
    begin
      // put it on the screen
      Parent := self;
      // set the size
      Width := 10;
      Height := 10;
      // set the image to a single pixel.
      Bitmap . Width := 1;
      Bitmap . Height := 1;
      // set the Alpha to $80 to make it
      // semi-transparent
      Bitmap . Pixels [ 0, 0 ] := $80000000 + nColor;
      // set the z position
      Position . Z := nZ;
    end;
end;

begin
  NewImage ( claRed,   +10 );
  NewImage ( claGreen,   0 );
  NewImage ( claBlue,  -10 );
end;
Run Code Online (Sandbox Code Playgroud)

一切都很好

现在颠倒顺序.现在它们是不透明的.

begin
  NewImage ( claRed,   -10 );
  NewImage ( claGreen,   0 );
  NewImage ( claBlue,  +10 );
end;
Run Code Online (Sandbox Code Playgroud)

现在它们是不透明的

我错过了什么?

Eri*_*nge 4

FireMonkey(截至目前)\xe2\x80\x99t 不支持在 3D 中渲染半透明对象。

\n\n

FireMonkey 仅支持半透明对象的混合(通过不透明度属性或由于其纹理,例如半透明 PNG 图像),但单独混合不足以使用Z 缓冲区(其FMX 和大多数 3D 应用程序都在使用)。

\n\n

有关技术说明,您可以阅读透明度排序,该文章是关于 OpenGL 的,但也适用于 DirectX。

\n\n

因此,为了获得正确的渲染,您需要从相机的角度将半透明对象从后到前排序

\n\n

您可以在这篇文章中获取更多详细信息和一些代码来解决该问题:

\n\n

在FireMonkey中渲染半透明对象

\n\n

但请记住这只是一个解决方法

\n\n

理想情况下,这应该由 FireMonkey 场景图处理,因为它依赖于渲染,否则,您最终必须更改场景图结构,这可能会产生各种其他副作用,如果您有多个摄像机观看同一场景。

\n\n

此外,排序方法仅适用于不相交的凸对象,并且不具有三重重叠,如下所示:

\n\n

三重重叠示例

\n\n

不存在正确的排序(没有一个元素位于其他元素的前面)。

\n