MultiSampleAntiAliasing QML Type

Enable multisample antialiasing. 更多...

import 语句: import Qt3D.Render 2.5
实例化: QMultiSampleAntiAliasing
继承: RenderState

详细描述

A MultiSampleAntiAliasing type enables multisample antialiasing.

It can be added to a RenderPass :

RenderPass {
    shaderProgram: ShaderProgram {
        // ...
    }
    renderStates: [
        MultiSampleAntiAliasing {}
    ]
}
					

Or a RenderStateSet :

RenderStateSet {
    renderStates: [
        MultiSampleAntiAliasing {}
    ]
}
					

For multisampling to take effect, the render target must have been allocated with multisampling enabled:

RenderTarget {
    attachments: [
        RenderTargetOutput {
            attachmentPoint: RenderTargetOutput.Color0
            texture: Texture2DMultisample {
                width: 1024
                height: 1024
                format: Texture.RGBA8_UNorm
            }
        },
        RenderTargetOutput {
            attachmentPoint: RenderTargetOutput.DepthStencil
            texture: Texture2DMultisample{
                width: 1024
                height: 1024
                format: Texture.D24S8
            }
        }
    ]
}
					

Further, the shader code must use multisampling sampler types and texelFetch() instead of texture().

Further, the shader code must use multisampling sampler types and texelFetch() instead of 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;
}
					

注意: When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if MultiSampleAntiAliasing has been added to the render states.