Q3D表面:半透明QSurface3DSeries

Q3DSurface: Semi-transparent QSurface3DSeries

本文关键字:QSurface3DSeries 半透明 表面 Q3D      更新时间:2023-10-16

我试图使用alpha通道渲染我的曲面,但当我设置alpha值时,它使用随机颜色渲染,而不是半透明

// Init memory
Q3DSurface *poSurface = new Q3DSurface();
QSurface3DSeries *poSeries = new QSurface3DSeries();
QSurfaceDataArray *poDataArray = new QSurfaceDataArray();
// Generating test surface series
for ( int i = 0, k = 0; i < 10; ++i)
{
QSurfaceDataRow *poRow = new QSurfaceDataRow();
for ( int j = 0; j < 10; ++j )
{
float x = j;
float y = i;
float z = k;
poRow->append( QSurfaceDataItem( QVector3D( x, y, z ) ) );
}
poDataArray->append( poRow );
if ( i % 2 == 0 )
{
++k;
}
}
//
poSeries->dataProxy()->resetArray( poDataArray );
poSurface->addSeries( poSeries );
// Setting color with alpha value
poSeries->setBaseColor( QColor( 100, 100, 100, 100 ));
// Show surface widget
QWidget *poWidget = QWidget::createWindowContainer( poSurface );
poWidget->setWindowTitle( "test ");
poWidget->show();

我做错了什么?

我不确定你所说的"随机颜色"是什么意思,但猜测一下,你是否考虑了默认的照明?3d照明的效果可以使颜色看起来与明确设置的颜色不同。关于你的透明度设置,我认为这个代码看起来不错。您将RGBA值设置为R=100、G=100、B=100、A=100,这将产生灰色。在默认灯光下,由于您绘制的函数以及灯光从边缘"反弹"的方式,这可能看起来像亮/暗补丁。试着稍微更改一下你的代码,看看这是否真的发生了:

poSeries->dataProxy()->resetArray( poDataArray );
poSurface->addSeries( poSeries );
//PICK A DARK THEME THAT WILL HELP TO ILLUSTRATE THE EFFECT
poSurface->activeTheme()->setType(Q3DTheme::ThemeEbony);
//TURN THE AMBIENT LIGHTING UP TO FULL
poSurface->activeTheme()->setAmbientLightStrength(1.0f);
// Setting color with alpha value
//SET IT TO RED WITH A FULL ALPHA CHANNEL
poSeries->setBaseColor( QColor( 100, 0, 0, 255 ));

// Show surface widget
QWidget *poWidget = QWidget::createWindowContainer( poSurface );
poWidget->setWindowTitle( "test ");
poWidget->show();

这应该会在深色背景下生成一个暗红色的图形图像(只是为了让事情更清楚)。现在把阿尔法值放回你最初想要的值,你会看到这对颜色有什么影响:

// Setting color with alpha value: "washed out" red colour
poSeries->setBaseColor( QColor( 100, 0, 0, 100 ));

您可能会看到,在通过"setBaseColor"设置的透明度设置中渲染的是颜色(而不是网格)。

不幸的是,我无法告诉您如何透明地渲染Q3DSurface本身,但我希望这会有所帮助。

相关文章:
  • 没有找到相关文章