-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfragShader.glsl
87 lines (75 loc) · 2.05 KB
/
fragShader.glsl
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Mao Zunjie Wang Haocheng 18098531-i011-0019 18098537-i011-0112
#version 430
in vec3 varyingLightDir;
in vec3 varyingVertPos;
in vec3 varyingNormal;
in vec3 varyingTangent;
in vec2 tc;
out vec4 fragColor;
layout (binding=0) uniform sampler2D t;
layout (binding=1) uniform sampler2D n;
layout (binding=2) uniform sampler2D h;
struct PositionalLight
{ vec4 ambient;
vec4 diffuse;
vec4 specular;
vec3 position;
};
struct Material
{ vec4 ambient;
vec4 diffuse;
vec4 specular;
float shininess;
};
uniform vec4 globalAmbient;
uniform PositionalLight light;
uniform Material material;
uniform mat4 mv_matrix;
uniform mat4 proj_matrix;
uniform mat4 norm_matrix;
uniform int sun;
vec3 CalcBumpedNormal()
{
vec3 Normal = normalize(varyingNormal);
return Normal;
vec3 Tangent = normalize(varyingTangent);
Tangent = normalize(Tangent - dot(Tangent, Normal) * Normal);
vec3 Bitangent = cross(Tangent, Normal);
vec3 BumpMapNormal = texture(n,tc).xyz;
BumpMapNormal = BumpMapNormal * 2.0 - 1.0;
mat3 TBN = mat3(Tangent, Bitangent, Normal);
vec3 NewNormal = TBN * BumpMapNormal;
NewNormal = normalize(NewNormal);
return NewNormal;
}
void main(void)
{
if(sun==1)
{
vec4 tcc = texture(t,tc);
fragColor = tcc*1.3;
return;
}
// normalize the light, normal, and view vectors:
vec3 L = normalize(varyingLightDir-varyingVertPos);
vec3 V = normalize(-varyingVertPos);
//vec3 N = CalcBumpedNormal();
vec3 N = CalcBumpedNormal();
// get the angle between the light and surface normal:
float cosTheta = dot(L,N);
// compute light reflection vector, with respect N:
vec3 R = normalize(reflect(-L, N));
// angle between the view vector and reflected light:
float cosPhi = dot(V,R);
//fragColor = vec4(N,1);
//return;
// compute ADS contributions (per pixel):
vec4 tcc = texture(t,tc);
fragColor =
0.25*tcc +
2*tcc*(fragColor = globalAmbient * material.ambient
+ light.ambient * material.ambient
+ light.diffuse * material.diffuse * max(cosTheta,0.0)
+ light.specular * material.specular
* pow(max(cosPhi,0.0), material.shininess));
}