-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathGroundPushGlobeSurfaceShaderSet.js
executable file
·106 lines (90 loc) · 3.63 KB
/
GroundPushGlobeSurfaceShaderSet.js
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
/**
* Replacement for the original GlobeSurfaceShaderSet in Cesium.
*/
var GroundPushGlobeSurfaceShaderSet= function(attributeLocations) {
"use strict";
this.baseVertexShaderString = undefined;
this.baseFragmentShaderString = undefined;
this._attributeLocations = Cesium.terrainAttributeLocations;
this._shaders = {};
};
GroundPushGlobeSurfaceShaderSet.prototype.invalidateShaders = function() {
var shaders = this._shaders;
for ( var keyword in shaders) {
if (shaders.hasOwnProperty(keyword)) {
shaders[keyword].release();
}
}
this.getShaderKey = function(textureCount, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha) {
var key = '';
key += textureCount;
if (applyBrightness) {
key += '_brightness';
}
if (applyContrast) {
key += '_contrast';
}
if (applyHue) {
key += '_hue';
}
if (applySaturation) {
key += '_saturation';
}
if (applyGamma) {
key += '_gamma';
}
if (applyAlpha) {
key += '_alpha';
}
return key;
};
this._shaders = {};
};
GroundPushGlobeSurfaceShaderSet.prototype.getShaderProgram = function(context, textureCount, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha) {
var key = this.getShaderKey(textureCount, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha);
var shader = this._shaders[key];
if (!Cesium.defined(shader)) {
var vs = this.baseVertexShaderString;
var fs =
(applyBrightness ? '#define APPLY_BRIGHTNESS\n' : '') +
(applyContrast ? '#define APPLY_CONTRAST\n' : '') +
(applyHue ? '#define APPLY_HUE\n' : '') +
(applySaturation ? '#define APPLY_SATURATION\n' : '') +
(applyGamma ? '#define APPLY_GAMMA\n' : '') +
(applyAlpha ? '#define APPLY_ALPHA\n' : '') +
'#define TEXTURE_UNITS ' + textureCount + '\n' +
this.baseFragmentShaderString + '\n' +
'vec4 computeDayColor(vec4 initialColor, vec2 textureCoordinates)\n' +
'{\n' +
' vec4 color = initialColor;\n';
for (var i = 0; i < textureCount; ++i) {
fs +=
'color = sampleAndBlend(\n' +
' color,\n' +
' u_dayTextures[' + i + '],\n' +
' textureCoordinates,\n' +
' u_dayTextureTexCoordsRectangle[' + i + '],\n' +
' u_dayTextureTranslationAndScale[' + i + '],\n' +
(applyAlpha ? ' u_dayTextureAlpha[' + i + '],\n' : '1.0,\n') +
(applyBrightness ? ' u_dayTextureBrightness[' + i + '],\n' : '0.0,\n') +
(applyContrast ? ' u_dayTextureContrast[' + i + '],\n' : '0.0,\n') +
(applyHue ? ' u_dayTextureHue[' + i + '],\n' : '0.0,\n') +
(applySaturation ? ' u_dayTextureSaturation[' + i + '],\n' : '0.0,\n') +
(applyGamma ? ' u_dayTextureOneOverGamma[' + i + '],\n' : '0.0,\n') +
' u_showOnlyInPushedRegion[' + i + ']);\n' ;
}
fs +=
' return color;\n' +
'}';
shader = context.shaderCache.getShaderProgram(
vs,
fs,
this._attributeLocations);
this._shaders[key] = shader;
}
return shader;
};
GroundPushGlobeSurfaceShaderSet.prototype.destroy = function() {
this.invalidateShaders();
return Cesium.destroyObject(this);
};