PySide6.Qt3DRender.Qt3DRender.QMultiSampleAntiAliasing

class QMultiSampleAntiAliasing

启用多重采样抗锯齿。更多

PySide6.Qt3DRender.Qt3DRender.QMultiSampleAntiAliasing 的继承图

概要

方法

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

一个 QMultiSampleAntiAliasing 类启用了多重采样抗锯齿。

可以通过调用addRenderState()将其添加到QRenderPass中:

QRenderPass *renderPass = new QRenderPass();

QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing();
renderPass->addRenderState(msaa);

或者通过调用 addRenderState() 来创建一个 QRenderStateSet

QRenderStateSet *renderStateSet = new QRenderStateSet();

QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing();
renderStateSet->addRenderState(msaa);

要使多重采样生效,渲染目标必须在启用多重采样的情况下分配:

QTexture2DMultisample *colorTex = new QTexture2DMultisample;
colorTex->setFormat(QAbstractTexture::RGBA8_UNorm);
colorTex->setWidth(1024);
colorTex->setHeight(1024);

QRenderTargetOutput *color = new QRenderTargetOutput;
color->setAttachmentPoint(QRenderTargetOutput::Color0);
color->setTexture(colorTex);

QTexture2DMultisample *depthStencilTex = new QTexture2DMultisample;
depthStencilTex->setFormat(QAbstractTexture::RGBA8_UNorm);
depthStencilTex->setWidth(1024);
depthStencilTex->setHeight(1024);

QRenderTargetOutput *depthStencil = new QRenderTargetOutput;
depthStencil->setAttachmentPoint(QRenderTargetOutput::DepthStencil);
depthStencil->setTexture(depthStencilTex);

Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget;
renderTarget->addOutput(color);
renderTarget->addOutput(depthStencil);

此外,着色器代码必须使用多重采样采样器类型和texelFetch()而不是texture()。

例如,如果你有像这样的代码

#version 150

uniform sampler2D colorTexture;
in vec2 texCoord;
out vec4 fragColor;

void main()
{
    fragColor = texture(colorTexture, texCoord);
}

你可以将其重写为

#version 150

uniform sampler2DMS colorTexture;
in vec2 texCoord;
out vec4 fragColor;

void main()
{
    ivec2 tc = ivec2(floor(textureSize(colorTexture) * texCoord));
    vec4 c = texelFetch(colorTexture, tc, 0) +
                texelFetch(colorTexture, tc, 1) +
                texelFetch(colorTexture, tc, 2) +
                texelFetch(colorTexture, tc, 3);
    fragColor = c / 4.0;
}

注意

当使用OpenGL作为图形API时,如果QMultiSampleAntiAliasing已添加到渲染状态中,将调用glEnable(GL_MULTISAMPLE)。

__init__([parent=None])
Parameters:

parentQNode

构造函数使用指定的parent创建一个新的QMultiSampleAntiAliasing实例。