| 1 |
// Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Core 2.9 |
| 5 |
import Qt3D.Render 2.9 |
| 6 |
import Qt3D.Extras 2.0 |
| 7 |
|
| 8 |
Entity { |
| 9 |
id: root |
| 10 |
|
| 11 |
property Texture colorTexture |
| 12 |
readonly property int samples : colorTexture ? colorTexture.samples : 1 |
| 13 |
|
| 14 |
Effect { |
| 15 |
id: materialEffect |
| 16 |
techniques : [ |
| 17 |
// OpenGL 3.2 |
| 18 |
Technique { |
| 19 |
graphicsApiFilter { |
| 20 |
api : GraphicsApiFilter.OpenGL |
| 21 |
profile : GraphicsApiFilter.CoreProfile |
| 22 |
minorVersion : 3 |
| 23 |
majorVersion : 2 |
| 24 |
} |
| 25 |
|
| 26 |
renderPasses : RenderPass { |
| 27 |
filterKeys : FilterKey { name : "pass"; value : "final" } |
| 28 |
|
| 29 |
shaderProgram : ShaderProgram { |
| 30 |
vertexShaderCode: |
| 31 |
"#version 150 core |
| 32 |
|
| 33 |
in vec3 vertexPosition; |
| 34 |
out vec2 texCoords; |
| 35 |
|
| 36 |
void main() { |
| 37 |
texCoords = vec2(0.5) + vec2(0.5) * vertexPosition.xz; |
| 38 |
gl_Position = vec4(vertexPosition.x, vertexPosition.z, 0.0, 1.0); |
| 39 |
}" |
| 40 |
fragmentShaderCode: |
| 41 |
"#version 150 core |
| 42 |
|
| 43 |
uniform sampler2DMS source; |
| 44 |
|
| 45 |
in vec2 texCoords; |
| 46 |
out vec4 fragColor; |
| 47 |
|
| 48 |
void main() { |
| 49 |
vec4 c = vec4(0.0); |
| 50 |
c += texelFetch(source, ivec2(gl_FragCoord), 0); |
| 51 |
fragColor = vec4(c.rgb / max(c.a, 0.01), c.a); |
| 52 |
}" |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
] |
| 57 |
} |
| 58 |
|
| 59 |
Material { |
| 60 |
id: materialWithoutTexture |
| 61 |
|
| 62 |
parameters: [ |
| 63 |
Parameter { name: "source"; value: colorTexture }, |
| 64 |
Parameter { name: "samples"; value: root.samples } |
| 65 |
] |
| 66 |
|
| 67 |
effect: materialEffect |
| 68 |
} |
| 69 |
|
| 70 |
PlaneMesh { |
| 71 |
id: planeMesh |
| 72 |
width: 2.0 |
| 73 |
height: 2.0 |
| 74 |
meshResolution: Qt.size(2, 2) |
| 75 |
} |
| 76 |
|
| 77 |
components : [ |
| 78 |
planeMesh, |
| 79 |
materialWithoutTexture |
| 80 |
] |
| 81 |
} |