-
Notifications
You must be signed in to change notification settings - Fork 59
/
shaders.ts
86 lines (77 loc) · 2.22 KB
/
shaders.ts
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
const PointCloudFS = `
varying vec3 vColor;
void main() {
if (vColor == vec3(0.0, 0.0, 0.0)) {
discard;
} else {
gl_FragColor = vec4( vColor, 1.0 );
}
}
`;
const PointCloudVS = `
varying vec3 vColor;
uniform sampler2D gradient;
uniform sampler2D grayscale;
attribute float intensity;
attribute float classification;
uniform vec3 rootCenter;
uniform vec3 rootNormal;
uniform vec2 elevationRange;
uniform int coloring;
uniform bool hideGround;
uniform float maxIntensity;
uniform float intensityContrast;
#ifdef USE_COLOR
vec3 getRGB() {
vec3 rgb = color;
return rgb;
}
#endif
vec3 getElevation(){
vec4 world = modelMatrix * vec4( position, 1.0 );
float diff = abs(dot(rootNormal, (vec3(world) - rootCenter)));
float w = max(diff - elevationRange.x,0.0) / max(elevationRange.y - elevationRange.x,1.0);
vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;
return cElevation;
}
vec3 getIntensity(){
// TODO: real contrast enhancement. Check https://github.com/yuki-koyama/enhancer/blob/master/shaders/enhancer.fs
float intmod = pow(intensity, intensityContrast);
vec3 cIntensity = texture2D(grayscale, vec2(intmod / maxIntensity ,1.0-(intmod / maxIntensity))).rgb;
return cIntensity;
}
vec3 getClassification(){
float classNormalized = classification / 255.0;
vec3 cClassification = texture2D(gradient, vec2(classNormalized * 5.0,1.0-classNormalized * 5.0)).rgb;
return cClassification;
}
vec3 getColor(){
vec3 color;
if (hideGround && classification == 2.0) {
return vec3(0.0, 0.0, 0.0);
}
if (coloring == 1) {
color = getIntensity();
}
else if (coloring == 2) {
color = getClassification();
} else if (coloring == 3) {
color = getElevation();
}
#ifdef USE_COLOR
else if (coloring == 4) {
color = getRGB();
}
#endif
else {
color = vec3(1.0, 1.0, 1.0);
}
return color;
}
void main() {
vColor = getColor();
gl_PointSize = 1.0;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
`;
export { PointCloudFS, PointCloudVS };