-
Notifications
You must be signed in to change notification settings - Fork 2
/
NewVShader.vertexshader
70 lines (48 loc) · 2.02 KB
/
NewVShader.vertexshader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;
layout(location = 3) in vec3 vertexTangent_modelspace;
layout(location = 4) in vec3 vertexBiTangent_modelspace;
uniform mat4 VP;
uniform mat4 M;
uniform mat4 V;
uniform vec4 LightLocation_world_space;
out vec2 UV;
out vec3 Eye_Direction;
out vec3 LightDirection_eyespace;
out vec3 Eye_Direction_tangentspace;
out vec3 LightDirection_tangentspace;
out vec3 Normal_eyespace;
out vec3 Tangent_eyespace;
out vec3 Tangent_modelspace;
//out vec3 interpolatedColor;
out vec4 world_position;
void main()
{
Tangent_modelspace = vertexTangent_modelspace;
//BiTangent_modelspace = normalize(vertexTangent_modelspace);
mat4 MVP = VP*M;
vec3 tan = normalize(vertexTangent_modelspace - vertexNormal_modelspace * dot(vertexNormal_modelspace, vertexTangent_modelspace));
if (dot(cross(vertexNormal_modelspace, tan),vertexBiTangent_modelspace) < 0.0f){
tan.z = tan.z * -1.0f;
}
vec4 v = vec4(vertexPosition_modelspace,1);
world_position = M*v;
vec3 vertexPosition_cameraspace = ( V * M * v).xyz;
Eye_Direction = vec3(0,0,0) - vertexPosition_cameraspace;
vec3 LightPosition_eyespace = ( V * LightLocation_world_space).xyz;
LightDirection_eyespace = LightPosition_eyespace + Eye_Direction;
Normal_eyespace = normalize(( V * M * vec4(vertexNormal_modelspace,0)).xyz);
Tangent_eyespace =normalize(( V * M * vec4(tan,0)).xyz);
vec3 BiTangent_eyespace =normalize(( V * M * vec4(vertexBiTangent_modelspace,0)).xyz);
mat3 TBN = transpose(mat3(Tangent_eyespace,BiTangent_eyespace,Normal_eyespace));
LightDirection_tangentspace = TBN * LightDirection_eyespace;
Eye_Direction_tangentspace = TBN * Eye_Direction;
gl_Position = MVP * v;
UV = vertexUV;
/*
interpolatedColor.r = 0.8;
interpolatedColor.g = 0.8;
interpolatedColor.b = 0.8;*/
}