| 1 |
// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Core 2.0 |
| 5 |
import Qt3D.Render 2.0 |
| 6 |
|
| 7 |
Effect { |
| 8 |
id : sceneMaterialEffect |
| 9 |
techniques : [ |
| 10 |
// OpenGL 3.1 |
| 11 |
Technique { |
| 12 |
graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.CoreProfile; minorVersion : 1; majorVersion : 3 } |
| 13 |
renderPasses : RenderPass { |
| 14 |
filterKeys : FilterKey { name : "pass"; value : "geometry" } |
| 15 |
shaderProgram : ShaderProgram { |
| 16 |
id : sceneShaderGL3 |
| 17 |
vertexShaderCode: |
| 18 |
"#version 140 |
| 19 |
|
| 20 |
in vec4 vertexPosition; |
| 21 |
in vec3 vertexNormal; |
| 22 |
|
| 23 |
out vec4 color0; |
| 24 |
out vec3 position0; |
| 25 |
out vec3 normal0; |
| 26 |
|
| 27 |
uniform mat4 mvp; |
| 28 |
uniform mat4 modelMatrix; |
| 29 |
uniform mat3 modelNormalMatrix; |
| 30 |
uniform vec4 meshColor; |
| 31 |
|
| 32 |
void main() |
| 33 |
{ |
| 34 |
color0 = meshColor; |
| 35 |
position0 = vec3(modelMatrix * vertexPosition); |
| 36 |
normal0 = normalize(modelNormalMatrix * vertexNormal); |
| 37 |
gl_Position = mvp * vertexPosition; |
| 38 |
} |
| 39 |
" |
| 40 |
fragmentShaderCode: |
| 41 |
"#version 140 |
| 42 |
|
| 43 |
in vec4 color0; |
| 44 |
in vec3 position0; |
| 45 |
in vec3 normal0; |
| 46 |
|
| 47 |
out vec4 color; |
| 48 |
out vec4 position; |
| 49 |
out vec4 normal; |
| 50 |
|
| 51 |
void main() |
| 52 |
{ |
| 53 |
color = color0; |
| 54 |
position = vec4(position0, 0.0); |
| 55 |
normal = vec4(normal0, 0.0); |
| 56 |
} |
| 57 |
" |
| 58 |
} |
| 59 |
} |
| 60 |
}, |
| 61 |
// OpenGL 2.0 |
| 62 |
Technique { |
| 63 |
graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.CoreProfile; minorVersion : 0; majorVersion : 2 } |
| 64 |
renderPasses : RenderPass { |
| 65 |
filterKeys : FilterKey { name : "pass"; value : "geometry" } |
| 66 |
shaderProgram : ShaderProgram { |
| 67 |
id : sceneShaderGL2 |
| 68 |
vertexShaderCode: |
| 69 |
"#version 110 |
| 70 |
|
| 71 |
attribute vec4 vertexPosition; |
| 72 |
attribute vec3 vertexNormal; |
| 73 |
|
| 74 |
varying vec4 color0; |
| 75 |
varying vec3 position0; |
| 76 |
varying vec3 normal0; |
| 77 |
|
| 78 |
uniform mat4 mvp; |
| 79 |
uniform mat4 modelMatrix; |
| 80 |
uniform mat3 modelNormalMatrix; |
| 81 |
uniform vec4 meshColor; |
| 82 |
|
| 83 |
void main() |
| 84 |
{ |
| 85 |
color0 = meshColor; |
| 86 |
position0 = vec3(modelMatrix * vertexPosition); |
| 87 |
normal0 = normalize(modelNormalMatrix * vertexNormal); |
| 88 |
gl_Position = mvp * vertexPosition; |
| 89 |
} |
| 90 |
" |
| 91 |
fragmentShaderCode: |
| 92 |
"#version 110 |
| 93 |
|
| 94 |
varying vec4 color0; |
| 95 |
varying vec3 position0; |
| 96 |
varying vec3 normal0; |
| 97 |
|
| 98 |
void main() |
| 99 |
{ |
| 100 |
gl_FragData[0] = color0; |
| 101 |
gl_FragData[1] = vec4(position0, 0); |
| 102 |
gl_FragData[2] = vec4(normal0, 0); |
| 103 |
} |
| 104 |
" |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
] |
| 109 |
} |