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
|
#version 430
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
uniform sampler2D textu;
uniform sampler2D normu;
in vec2 texCoord;
in vec4 fragCoord;
out vec4 FragColor;
uniform vec3 LightPos[32];
uniform vec4 LightColor[32];
uniform int LightNum;
void main()
{
vec3 Falloff = vec3(0.1, 0.2, 0.0);
vec4 DiffuseColor = texture2D(textu, texCoord);
if (DiffuseColor.a < 0.1f)
discard;
vec3 NormalMap = texture2D(normu, texCoord).rgb;
vec3 SumLight = vec3(0.0);
for (int i = 0; i < LightNum; i++) {
vec3 LightDir = vec3(LightPos[i].xy - fragCoord.xy, LightPos[i].z);
float D = length(LightDir);
vec3 N = normalize(NormalMap * 2.0 - 1.0);
vec3 L = normalize(LightDir);
vec3 Diffuse = (LightColor[i].rgb * LightColor[i].a) * max(dot(N, L), 0.0);
vec3 Ambient = vec3(0.0);
float Attenuation =
1.0 / (Falloff.x + (Falloff.y * D) + (Falloff.z * D * D));
vec3 Intensity = Ambient + Diffuse + Attenuation;
vec3 FinalColor = DiffuseColor.rgb * Intensity;
SumLight += FinalColor;
}
FragColor = vec4(SumLight, DiffuseColor.a);
};
/*
vec4 normalMap = texture2D(normu, texCoord);
vec3 normal = normalMap.xyz * 2.0 - 1.0;
if (pixTex.a < 0.1f)
discard;
vec4 shadeColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
float dist = length(light.xy - fragCoord.xy);
if (dist < light.w) {
float attenuation = clamp(1.0f - dist*dist/(light.w*light.w), 0.0f, 1.0f);
attenuation *= attenuation;
shadeColor += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(normal.xyz, 1);
//shadeColor = vec4(1.0) + 0.1*normal;
//shadeColor = vec4(1.0);
}
//FragColor = pixTex * shadeColor;
FragColor = vec4(normal.xyz, 1);
}
*/
/*
vec2 texLoc = vec2(texCoord.x, 1-texCoord.y);
vec4 pixTex = texture2D(texture, texLoc);
if (pixTex.a < 0.1f)
discard;
vec4 shadeColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
if (lightImpact > 0.0f) {
for (int i = 0; i < lightSize; i++) {
vec2 loc = light[i].xy;
float dist = length(loc - fragCoord.xy);
if (dist < light[i].w) {
float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f);
attenuation *= attenuation;
shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;
}
}
}
shadeColor += ambientLight;
*/
|