| 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 150 core |
| 6 |
|
| 7 |
in vec3 vertexPosition; |
| 8 |
in vec3 vertexNormal; |
| 9 |
in vec2 vertexTexCoord; |
| 10 |
in vec4 vertexTangent; |
| 11 |
|
| 12 |
out vec3 lightDir; |
| 13 |
out vec3 viewDir; |
| 14 |
out vec2 texCoord; |
| 15 |
|
| 16 |
uniform mat4 viewMatrix; |
| 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 |
// Pass through texture coordinates |
| 29 |
texCoord = vertexTexCoord * texCoordScale; |
| 30 |
|
| 31 |
// Transform position, normal, and tangent to eye coords |
| 32 |
vec3 normal = normalize(modelViewNormal * vertexNormal); |
| 33 |
vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz); |
| 34 |
vec3 position = vec3(modelView * vec4(vertexPosition, 1.0)); |
| 35 |
|
| 36 |
// Calculate binormal vector |
| 37 |
vec3 binormal = normalize(cross(normal, tangent)); |
| 38 |
|
| 39 |
// Construct matrix to transform from eye coords to tangent space |
| 40 |
mat3 tangentMatrix = mat3 ( |
| 41 |
tangent.x, binormal.x, normal.x, |
| 42 |
tangent.y, binormal.y, normal.y, |
| 43 |
tangent.z, binormal.z, normal.z); |
| 44 |
|
| 45 |
// Transform light direction and view direction to tangent space |
| 46 |
vec3 s = lightPosition - position; |
| 47 |
lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0))); |
| 48 |
|
| 49 |
vec3 v = -position; |
| 50 |
viewDir = normalize(tangentMatrix * v); |
| 51 |
|
| 52 |
// Calculate vertex position in clip coordinates |
| 53 |
gl_Position = mvp * vec4(vertexPosition, 1.0); |
| 54 |
} |