我在QML應用程序中看到主要的性能問題,我寫了一個Scene3d
以顯示點雲。 1000點/秒是沒問題的,但是在10000點時它基本上停止了我的整個計算機。目標是進入數百萬點(這是什麼舊的應用程序,一個Qt/VTK混合物可以做的放緩之前)Qt pointcloud在scene3d中的性能下降
我擔心我不會卸載處理到另一個線程,或者沒有正確渲染。 ...這是我的第一個Qt項目,對所有這些都是新的。
基本上我建立了一個循環緩衝點(每個點是32字節),我將它複製到一個QByteArray
上的定製QGeometry
,Entity
。該實體具有運行頂點和片段着色器的材質。
我能做些什麼來提高性能嗎?
材料:
import Qt3D.Core 2.0
import Qt3D.Render 2.0
Material {
effect: Effect {
techniques: Technique {
renderPasses: RenderPass {
shaderProgram: ShaderProgram {
vertexShaderCode: loadSource("qrc:/shaders/pointcloud.vert")
fragmentShaderCode: loadSource("qrc:/shaders/pointcloud.frag")
}
renderStates: [
PointSize { sizeMode: PointSize.Programmable } //supported since OpenGL 3.2
]
}
graphicsApiFilter {
api: GraphicsApiFilter.OpenGL
profile: GraphicsApiFilter.CoreProfile
majorVersion: 4
minorVersion: 3
}
}
}
// some parameters...
}
我的着色器是非常簡單的:
頂點:
#version 430
layout(location = 1) in vec3 vertexPosition;
out VertexBlock
{
flat vec3 col;
vec3 pos;
vec3 normal;
} v_out;
uniform mat4 modelView;
uniform mat3 modelViewNormal;
uniform mat4 mvp;
uniform mat4 projectionMatrix;
uniform mat4 viewportMatrix;
uniform float pointSize;
uniform float maxDistance;
void main()
{
vec3 vertexNormal = vec3(1.0, 1.0, 1.0);
v_out.normal = normalize(modelViewNormal * vertexNormal);
v_out.pos = vec3(modelView * vec4(vertexPosition, 1.0));
float c = (vertexPosition[0]*vertexPosition[0] + vertexPosition[1]*vertexPosition[1])*maxDistance;
v_out.col = vec3(c,c,0.5);
gl_Position = mvp * vec4(vertexPosition, 1.0);
gl_PointSize = viewportMatrix[1][1] * projectionMatrix[1][1] * pointSize/gl_Position.w;
}
片段:
#version 430
in VertexBlock
{
flat vec3 col;
vec3 pos;
vec3 normal;
} frag_in;
out vec4 colour;
void main()
{
colour = vec4(frag_in.col, 1.0);
}
渲染:
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import "Cameras"
RenderSettings {
id: root
property CameraSet cameraSet: CameraSet {
id: cameraSet
}
property real userViewWidth: 0.79
property real topOrthoViewHeight: 0.79
activeFrameGraph: Viewport {
id: viewport
normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
RenderSurfaceSelector {
ClearBuffers {
buffers : ClearBuffers.ColorDepthBuffer
clearColor: theme.cSceneClear
NoDraw {}
}
Viewport {
id: userViewport
normalizedRect: Qt.rect(0, 0, userViewWidth, 1.0)
CameraSelector {
id: userCameraSelectorViewport
camera: cameraSet.user.camera
}
}
// Two other viewports...
}
}
}
實體
Entity {
property PointBuffer buffer: PointBuffer {
id: pointBuffer
}
PointsMaterial {
id: pointsMaterial
dataBuffer: pointBuffer
}
Entity {
id: particleRenderEntity
property GeometryRenderer particlesRenderer: GeometryRenderer {
instanceCount: buffer.count
primitiveType: GeometryRenderer.Points
geometry: PointGeometry { buffer: pointBuffer }
}
components: [
particlesRenderer
, pointsMaterial
]
}
}