Debian Codegraph @

tests/manual/planets-qml/shaders/es2/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 attribute vec3 vertexPosition;
6 attribute vec3 vertexNormal;
7 attribute vec2 vertexTexCoord;
8 attribute vec4 vertexTangent;
9
10 varying vec4 positionInLightSpace;
11 varying vec3 lightDir;
12 varying vec3 viewDir;
13 varying vec2 texCoord;
14
15 uniform mat4 viewMatrix;
16 uniform mat4 lightViewProjection;
17 uniform mat4 modelMatrix;
18 uniform mat4 modelView;
19 uniform mat3 modelViewNormal;
20 uniform mat4 mvp;
21
22 uniform float texCoordScale;
23
24 uniform vec3 lightPosition;
25
26 void main()
27 {
28 const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
29 0.0, 0.5, 0.0, 0.0,
30 0.0, 0.0, 0.5, 0.0,
31 0.5, 0.5, 0.5, 1.0);
32
33 positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
34
35 // Pass through texture coordinates
36 texCoord = vertexTexCoord * texCoordScale;
37
38 // Transform position, normal, and tangent to eye coords
39 vec3 normal = normalize(modelViewNormal * vertexNormal);
40 vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz);
41 vec3 position = vec3(modelView * vec4(vertexPosition, 1.0));
42
43 // Calculate binormal vector
44 vec3 binormal = normalize(cross(normal, tangent));
45
46 // Construct matrix to transform from eye coords to tangent space
47 mat3 tangentMatrix = mat3 (
48 tangent.x, binormal.x, normal.x,
49 tangent.y, binormal.y, normal.y,
50 tangent.z, binormal.z, normal.z);
51
52 // Transform light direction and view direction to tangent space
53 vec3 s = lightPosition - position;
54 lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0)));
55
56 vec3 v = -position;
57 viewDir = normalize(tangentMatrix * v);
58
59 // Calculate vertex position in clip coordinates
60 gl_Position = mvp * vec4(vertexPosition, 1.0);
61 }