/
fcolorboxshader.fsh
141 lines (123 loc) · 4.65 KB
/
fcolorboxshader.fsh
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
uniform sampler2D s2DEarthTexture;
uniform sampler2D s2DEarthPoliticalTexture;
uniform bool bShowCenters;
uniform bool bShowPoliticalEarthMap;
uniform float fCentersRadius;
uniform lowp mat4 m4Projection;
uniform lowp mat4 m4ModelView;
varying highp vec4 v4Vertex;
highp mat4 m4ModelViewProjectionMatrix = m4Projection*m4ModelView;
float random()
{
return fract(sin(dot(v4Vertex.xyz/vec3(100.0, 100.0, 100.0), vec3(12.9898, 78.233, 23.11)))*43758.5453123);
}
vec3 fmMiddle(vec3 v3V1, vec3 v3V2)
{
vec3 v3Result;
v3Result[0] = (v3V1[0] + v3V2[0])/2.0;
v3Result[1] = (v3V1[1] + v3V2[1])/2.0;
v3Result[2] = (v3V1[2] + v3V2[2])/2.0;
return v3Result;
}
float fnVectorPlaneDistanse(vec3 v3Vertex, vec3 v3PlanePoint, vec3 v3PlaneNormal)
{
float fSn, fSd, fSb;
vec3 v3B;
fSn = -dot(v3PlaneNormal, (v3Vertex-v3PlanePoint));
fSd = dot(v3PlaneNormal, v3PlaneNormal);
fSb = fSn / fSd;
v3B = v3Vertex + fSb * v3PlaneNormal;
return distance(v3Vertex, v3B);
}
vec3 fnGetColorByPosition()
{
vec3 v3_h_h_h = (vec4(1.0, 1.0, 1.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_h_h_l = vec3(1.0, 1.0, -1.0);
vec3 v3_l_h_l = vec3(-1.0, 1.0, -1.0);
vec3 v3_l_h_h = vec3(-1.0, 1.0, 1.0);
vec3 v3_h_l_h = vec3(1.0, -1.0, 1.0);
vec3 v3_h_l_l = vec3(1.0, -1.0, -1.0);
vec3 v3_l_l_l = (vec4(-1.0, -1.0, -1.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_l_l_h = vec3(-1.0, -1.0, 1.0);
vec3 v3Vertex = v4Vertex.xyz;
vec3 v3_normal_p_0_0 = (vec4(1.0, 0.0, 0.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_normal_n_0_0 = (vec4(-1.0, 0.0, 0.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_normal_0_p_0 = (vec4(0.0, 1.0, 0.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_normal_0_n_0 = (vec4(0.0, -1.0, 0.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_normal_0_0_p = (vec4(0.0, 0.0, 1.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
vec3 v3_normal_0_0_n = (vec4(0.0, 0.0, -1.0, 0.0)*m4ModelViewProjectionMatrix).xyz;
float fD_p_x = fnVectorPlaneDistanse(v3Vertex, v3_h_h_h, v3_normal_p_0_0);
float fD_n_x = fnVectorPlaneDistanse(v3Vertex, v3_l_l_l, v3_normal_n_0_0);
float fD_p_y = fnVectorPlaneDistanse(v3Vertex, v3_h_h_h, v3_normal_0_p_0);
float fD_n_y = fnVectorPlaneDistanse(v3Vertex, v3_l_l_l, v3_normal_0_n_0);
float fD_p_z = fnVectorPlaneDistanse(v3Vertex, v3_h_h_h, v3_normal_0_0_p);
float fD_n_z = fnVectorPlaneDistanse(v3Vertex, v3_l_l_l, v3_normal_0_0_n);
float fMinD;
fMinD = min(fD_p_x, fD_n_x);
fMinD = min(fMinD, fD_p_y);
fMinD = min(fMinD, fD_n_y);
fMinD = min(fMinD, fD_p_z);
fMinD = min(fMinD, fD_n_z);
if (bShowCenters) {
if (distance(normalize(v3Vertex), v3_normal_0_0_n)<fCentersRadius) {
return vec3(1.0, 0.0, 0.0);
}
if (distance(normalize(v3Vertex), v3_normal_0_0_p)<fCentersRadius) {
return vec3(1.0, 0.0, 0.0);
}
if (distance(normalize(v3Vertex), v3_normal_0_p_0)<fCentersRadius) {
return vec3(1.0, 1.0, 0.0);
}
if (distance(normalize(v3Vertex), v3_normal_0_n_0)<fCentersRadius) {
return vec3(1.0, 0.0, 0.0);
}
if (distance(normalize(v3Vertex), v3_normal_p_0_0)<fCentersRadius) {
return vec3(1.0, 0.0, 0.0);
}
if (distance(normalize(v3Vertex), v3_normal_n_0_0)<fCentersRadius) {
return vec3(1.0, 0.0, 0.0);
}
}
if (fMinD==fD_p_x) {
return vec3(0.0, 1.0, 0.0);
}
if (fMinD==fD_n_x) {
return vec3(0.0, 0.0, 1.0);
}
if (fMinD==fD_p_y) {
return vec3(1.0, 0.0, 0.0);
}
if (fMinD==fD_n_y) {
return vec3(1.0, 1.0, 0.0);
}
if (fMinD==fD_p_z) {
return vec3(0.0, 0.0, 0.0);
}
if (fMinD==fD_n_z) {
return vec3(1.0, 1.0, 1.0);
}
/*
float fDot_h_h_h = dot(v3Vertex, v3_h_h_h)/(length(v3Vertex)*length(v3_h_h_h));
float fDot_h_h_l = dot(v3Vertex, v3_h_h_l)/(length(v3Vertex)*length(v3_h_h_l));
*/
return vec3(0);
}
void main(void)
{
gl_FragColor = mix(
vec4(fnGetColorByPosition(), 1.0),
vec4(texture2D(s2DEarthTexture, gl_TexCoord[0].xy).rgb, 1.0),
vec4(0.5)
);
if (bShowPoliticalEarthMap) {
vec2 v2EarthPoliticalTextureCoords = gl_TexCoord[0].xy;
v2EarthPoliticalTextureCoords[0] += 0.417;
gl_FragColor = mix(
gl_FragColor,
vec4(texture2D(s2DEarthPoliticalTexture, v2EarthPoliticalTextureCoords).rgb, 1.0),
vec4(0.5)
);
}
//gl_FragColor = vec4(vertex[0]/length(vertex), vertex[1]/length(vertex), vertex[2]/length(vertex), 0.5) + gl_Color;
//texture2D(texture, gl_TexCoord[0].xy);
}