Debian Codegraph @

tests/manual/planets-qml/shaders/rhi/planetDB.vert

raw
1 // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2 // Copyright (C) 2017 The Qt Company Ltd.
3 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5 #version 450 core
6
7 layout(location=0) in vec3 vertexPosition;
8 layout(location=1) in vec3 vertexNormal;
9 layout(location=2) in vec2 vertexTexCoord;
10 layout(location=3) in vec4 vertexTangent;
11
12 layout(location=0) out vec3 lightDir;
13 layout(location=1) out vec3 viewDir;
14 layout(location=2) out vec2 texCoord;
15
16
17 layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
18 mat4 viewMatrix;
19 mat4 projectionMatrix;
20 mat4 uncorrectedProjectionMatrix;
21 mat4 clipCorrectionMatrix;
22 mat4 viewProjectionMatrix;
23 mat4 inverseViewMatrix;
24 mat4 inverseProjectionMatrix;
25 mat4 inverseViewProjectionMatrix;
26 mat4 viewportMatrix;
27 mat4 inverseViewportMatrix;
28 vec4 textureTransformMatrix;
29 vec3 eyePosition;
30 float aspectRatio;
31 float gamma;
32 float exposure;
33 float time;
34 };
35
36 layout(std140, binding = 1) uniform qt3d_command_uniforms {
37 mat4 modelMatrix;
38 mat4 inverseModelMatrix;
39 mat4 modelViewMatrix;
40 mat3 modelNormalMatrix;
41 mat4 inverseModelViewMatrix;
42 mat4 modelViewProjection;
43 mat4 inverseModelViewProjectionMatrix;
44 };
45
46 layout(std140, binding = 2) uniform extras_uniforms {
47 float texCoordScale;
48 vec3 ka; // Ambient reflectivity
49 vec3 ks; // Specular reflectivity
50 float shininess; // Specular shininess factor
51 float opacity; // Alpha channel
52 vec3 lightPosition;
53 vec3 lightIntensity;
54 };
55
56 void main()
57 {
58 // Pass through texture coordinates
59 texCoord = vertexTexCoord * texCoordScale;
60
61 // Transform position, normal, and tangent to eye coords
62 vec3 normal = normalize(modelNormalMatrix * vertexNormal);
63 vec3 tangent = normalize(modelNormalMatrix * vertexTangent.xyz);
64 vec3 position = vec3(modelViewMatrix * vec4(vertexPosition, 1.0));
65
66 // Calculate binormal vector
67 vec3 binormal = normalize(cross(normal, tangent));
68
69 // Construct matrix to transform from eye coords to tangent space
70 mat3 tangentMatrix = mat3 (
71 tangent.x, binormal.x, normal.x,
72 tangent.y, binormal.y, normal.y,
73 tangent.z, binormal.z, normal.z);
74
75 // Transform light direction and view direction to tangent space
76 vec3 s = lightPosition - position;
77 lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0)));
78
79 vec3 v = -position;
80 viewDir = normalize(tangentMatrix * v);
81
82 // Calculate vertex position in clip coordinates
83 gl_Position = modelViewProjection * vec4(vertexPosition, 1.0);
84 }