-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextured-Fragment.glsl
117 lines (99 loc) · 3.08 KB
/
textured-Fragment.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#version 150 core
in vec3 Color;
in vec3 vertNormal;
in vec3 pos;
in vec3 lightDir;
in vec2 texcoord;
out vec4 outColor;
out vec4 outBloom;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
uniform sampler2D tex4;
uniform sampler2D tex5;
uniform sampler2D tex6;
uniform sampler2D tex7;
uniform sampler2D tex8;
uniform sampler2D tex9;
uniform sampler2D tex10;
uniform sampler2D tex11;
uniform sampler2D tex12;
uniform int texID;
uniform vec3 lightColor;
uniform bool toon;
uniform bool bloom;
const float ambient = .3;
void main() {
vec3 color;
if (texID == -1)
color = Color;
else if (texID == 0)
color = texture(tex0, texcoord).rgb;
else if (texID == 1)
color = texture(tex1, texcoord).rgb;
else if (texID == 2)
color = texture(tex2, texcoord).rgb;
else if (texID == 3)
color = texture(tex3, texcoord).rgb;
else if (texID == 4)
color = texture(tex4, texcoord).rgb;
else if (texID == 5)
color = texture(tex5, texcoord).rgb;
else if (texID == 6)
color = texture(tex6, texcoord).rgb;
else if (texID == 7)
color = texture(tex7, texcoord).rgb;
else if (texID == 8)
color = texture(tex8, texcoord).rgb;
else if (texID == 9)
color = texture(tex9, texcoord).rgb;
else if (texID == 10)
color = texture(tex10, texcoord).rgb;
else if (texID == 11)
color = texture(tex11, texcoord).rgb;
else if (texID == 12)
color = texture(tex12, texcoord).rgb;
else{
outColor = vec4(1,0,0,1);
return; //This was an error, stop lighting!
}
if (!toon)
{
vec3 normal = normalize(vertNormal);
vec3 diffuseC = color*max(dot(-lightDir,normal),0.0);
vec3 ambC = color*ambient;
vec3 viewDir = normalize(-pos); //We know the eye is at (0,0)! (Do you know why?)
vec3 reflectDir = reflect(viewDir,normal);
float spec = max(dot(reflectDir,lightDir),0.0);
if (dot(-lightDir,normal) <= 0.0) spec = 0; //No highlight if we are not facing the light
vec3 specC = .8*vec3(1.0,1.0,1.0)*pow(spec,4);
vec3 oColor = (ambC+diffuseC+specC)*lightColor;
outColor = vec4(oColor,1);
} else {
vec3 normal = normalize(vertNormal);
vec3 viewDir = normalize(-pos);
// diffuse
vec3 diffuseC = vec3(max(dot(-lightDir,normal),0.0));
float d_intensity = smoothstep(0, 0.01, diffuseC.x);
// specular
float gloss = 5.0;
vec3 reflectDir = reflect(viewDir,normal);
float spec = max(dot(reflectDir,lightDir),0.0);
float s_intensity = smoothstep(0.005, 0.01, pow(spec * d_intensity, gloss * gloss));
// rim light
vec3 rimColor = vec3(1.0);
float rimAmt = 0.7;
float rimDot = 1.0 - dot(viewDir, normal);
float r_intensity = smoothstep(rimAmt - 0.01, rimAmt +0.01, rimDot);
vec3 oColor = (ambient + (lightColor*d_intensity) + s_intensity + (rimColor * r_intensity))*color*0.8;
// vec3 oColor = (ambient + (lightColor*d_intensity) + s_intensity )*color*0.8 + (rimColor * r_intensity);
outColor = vec4(oColor,1);
}
if (bloom)
{
outBloom = vec4(1.0);
} else {
outBloom = vec4(0.0,0.0,0.0,1.0);
}
}