@openglobus/og 0.20.2 → 0.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/css/og.css +55 -23
  2. package/lib/@openglobus/js/Globe.d.ts +3 -0
  3. package/lib/@openglobus/js/control/Atmosphere.d.ts +27 -3
  4. package/lib/@openglobus/js/control/AtmosphereConfig.d.ts +59 -0
  5. package/lib/@openglobus/js/control/index.d.ts +29 -29
  6. package/lib/@openglobus/js/scene/Planet.d.ts +6 -0
  7. package/lib/@openglobus/js/shaders/atmos.d.ts +19 -3
  8. package/lib/@openglobus/js/shaders/drawnode.d.ts +2 -1
  9. package/lib/@openglobus/js/webgl/Handler.d.ts +3 -1
  10. package/lib/@openglobus/og.css +1 -1
  11. package/lib/@openglobus/og.esm.js +1 -1
  12. package/lib/@openglobus/og.esm.js.map +1 -1
  13. package/lib/@openglobus/og.umd.js +1 -1
  14. package/lib/@openglobus/og.umd.js.map +1 -1
  15. package/lib/js/Globe.d.ts +3 -0
  16. package/lib/js/Globe.js +3 -1
  17. package/lib/js/control/Atmosphere.d.ts +27 -3
  18. package/lib/js/control/Atmosphere.js +109 -43
  19. package/lib/js/control/AtmosphereConfig.d.ts +59 -0
  20. package/lib/js/control/AtmosphereConfig.js +348 -0
  21. package/lib/js/control/DebugInfo.js +5 -4
  22. package/lib/js/control/Lighting.js +13 -5
  23. package/lib/js/control/index.d.ts +29 -29
  24. package/lib/js/control/index.js +29 -29
  25. package/lib/js/layer/Layer.js +2 -2
  26. package/lib/js/scene/Planet.d.ts +6 -0
  27. package/lib/js/scene/Planet.js +24 -10
  28. package/lib/js/shaders/atmos.d.ts +19 -3
  29. package/lib/js/shaders/atmos.js +40 -26
  30. package/lib/js/shaders/drawnode.d.ts +2 -1
  31. package/lib/js/shaders/drawnode.js +15 -12
  32. package/lib/js/ui/Slider.js +3 -3
  33. package/lib/js/webgl/Handler.d.ts +3 -1
  34. package/lib/js/webgl/Handler.js +38 -28
  35. package/package.json +1 -1
package/lib/js/Globe.d.ts CHANGED
@@ -9,6 +9,7 @@ import { Sun } from "./control/Sun";
9
9
  import { HTMLDivElementExt, Renderer } from "./renderer/Renderer";
10
10
  import { RenderNode } from "./scene/RenderNode";
11
11
  import { Extent } from "./Extent";
12
+ import { IAtmosphereParams } from "./control/Atmosphere";
12
13
  export interface IGlobeParams {
13
14
  attributionContainer?: HTMLElement;
14
15
  target?: string | HTMLElement;
@@ -43,6 +44,7 @@ export interface IGlobeParams {
43
44
  autoActivate?: boolean;
44
45
  fontsSrc?: string;
45
46
  resourcesSrc?: string;
47
+ atmosphereParameters?: IAtmosphereParams;
46
48
  }
47
49
  /**
48
50
  * Creates a WebGL context with globe.
@@ -94,6 +96,7 @@ export interface IGlobeParams {
94
96
  * @param {number} [options.dpi] - Device pixel ratio. Default is current screen DPI.
95
97
  * @param {boolean} [options.atmosphereEnabled] - Enables atmosphere effect.
96
98
  * @param {boolean} [options.transtitionOpacityEnabled] - Enables terrain smooth opacity transition effect.
99
+ * @param {IAtmosphereParams} [options.atmosphereParameters] - Atmosphere model parameters.
97
100
  */
98
101
  declare class Globe {
99
102
  static __counter__: number;
package/lib/js/Globe.js CHANGED
@@ -67,6 +67,7 @@ const PLANET_NAME_PREFIX = "globus_planet_";
67
67
  * @param {number} [options.dpi] - Device pixel ratio. Default is current screen DPI.
68
68
  * @param {boolean} [options.atmosphereEnabled] - Enables atmosphere effect.
69
69
  * @param {boolean} [options.transtitionOpacityEnabled] - Enables terrain smooth opacity transition effect.
70
+ * @param {IAtmosphereParams} [options.atmosphereParameters] - Atmosphere model parameters.
70
71
  */
71
72
  class Globe {
72
73
  constructor(options) {
@@ -148,7 +149,8 @@ class Globe {
148
149
  quadTreeStrategyPrototype: options.quadTreeStrategyPrototype,
149
150
  maxLoadingRequests: options.maxLoadingRequests,
150
151
  atmosphereEnabled: options.atmosphereEnabled,
151
- transitionOpacityEnabled: options.transitionOpacityEnabled
152
+ transitionOpacityEnabled: options.transitionOpacityEnabled,
153
+ atmosphereParameters: options.atmosphereParameters
152
154
  });
153
155
  // Attach terrain provider (can be one object or array)
154
156
  if (options.terrain) {
@@ -1,16 +1,40 @@
1
+ import { AtmosphereParameters } from "../shaders/atmos";
1
2
  import { Framebuffer } from "../webgl/Framebuffer";
2
3
  import { Control, IControlParams } from "./Control";
3
- interface IAtmosphereParams extends IControlParams {
4
+ import { NumberArray3 } from '../math/Vec3';
5
+ export interface IAtmosphereParams extends IControlParams {
6
+ height?: number;
7
+ rayleighScale?: number;
8
+ mieScale?: number;
9
+ groundAlbedo?: number;
10
+ bottomRadius?: number;
11
+ rayleighScatteringCoefficient?: NumberArray3;
12
+ mieScatteringCoefficient?: number;
13
+ mieExtinctionCoefficient?: number;
14
+ ozoneAbsorptionCoefficient?: NumberArray3;
15
+ sunAngularRadius?: number;
16
+ sunIntensity?: number;
17
+ ozoneDensityHeight?: number;
18
+ ozoneDensityWide?: number;
4
19
  }
5
20
  export declare class Atmosphere extends Control {
6
21
  _transmittanceBuffer: Framebuffer | null;
7
22
  _scatteringBuffer: Framebuffer | null;
8
23
  opacity: number;
24
+ protected _parameters: AtmosphereParameters;
9
25
  constructor(options?: IAtmosphereParams);
26
+ setParameters(parameters: AtmosphereParameters): void;
27
+ get parameters(): AtmosphereParameters;
28
+ initPlanetAtmosphereShader(): void;
10
29
  oninit(): void;
30
+ initLookupTexturesShaders(): void;
31
+ initBackgroundShader(): void;
32
+ removeBackgroundShader(): void;
33
+ removeLookupTexturesShaders(): void;
11
34
  onactivate(): void;
12
35
  ondeactivate(): void;
13
- protected _drawAtmosphereTextures(): void;
36
+ protected _initLookupTextures(): void;
37
+ protected _renderLookupTextures(): void;
38
+ drawLookupTextures(): void;
14
39
  protected _drawBackground(): void;
15
40
  }
16
- export {};
@@ -1,4 +1,4 @@
1
- import * as atmos from "../shaders/atmos";
1
+ import { COMMON, transmittance, scattering } from "../shaders/atmos";
2
2
  import { Framebuffer } from "../webgl/Framebuffer";
3
3
  import { Program } from '../webgl/Program';
4
4
  import { Control } from "./Control";
@@ -11,16 +11,75 @@ export class Atmosphere extends Control {
11
11
  this._transmittanceBuffer = null;
12
12
  this._scatteringBuffer = null;
13
13
  this.opacity = 1.0;
14
+ this._parameters = {
15
+ ATMOS_HEIGHT: options.height || 100000.0,
16
+ RAYLEIGH_SCALE: options.rayleighScale || 0.08,
17
+ MIE_SCALE: options.mieScale || 0.012,
18
+ GROUND_ALBEDO: options.groundAlbedo || 0.05,
19
+ BOTTOM_RADIUS: options.bottomRadius || 6356752.3142451793,
20
+ rayleighScatteringCoefficient: options.rayleighScatteringCoefficient || [5.802, 13.558, 33.100],
21
+ mieScatteringCoefficient: options.mieScatteringCoefficient || 3.996,
22
+ mieExtinctionCoefficient: options.mieExtinctionCoefficient || 4.440,
23
+ ozoneAbsorptionCoefficient: options.ozoneAbsorptionCoefficient || [0.650, 1.881, 0.085],
24
+ SUN_ANGULAR_RADIUS: options.sunAngularRadius || 0.004685,
25
+ SUN_INTENSITY: options.sunIntensity || 1.0,
26
+ ozoneDensityHeight: options.ozoneDensityHeight || 25e3,
27
+ ozoneDensityWide: options.ozoneDensityWide || 15e3,
28
+ };
29
+ }
30
+ setParameters(parameters) {
31
+ this._parameters = JSON.parse(JSON.stringify(parameters));
32
+ this.initLookupTexturesShaders();
33
+ this.drawLookupTextures();
34
+ this.removeLookupTexturesShaders();
35
+ this.initPlanetAtmosphereShader();
36
+ }
37
+ get parameters() {
38
+ return JSON.parse(JSON.stringify(this._parameters));
39
+ }
40
+ initPlanetAtmosphereShader() {
41
+ this.planet?.initAtmosphereShader(this._parameters);
14
42
  }
15
43
  oninit() {
16
44
  if (this.renderer) {
17
- this.renderer.handler.addProgram(atmos.transmittance(), true);
18
- this.renderer.handler.addProgram(atmos.scattering(), true);
19
- this.renderer.handler.addProgram(atmosphereBackgroundShader(), true);
20
- this._drawAtmosphereTextures();
45
+ //
46
+ // Draw atmosphere lookup textures
47
+ //
48
+ this._initLookupTextures();
49
+ this.initLookupTexturesShaders();
50
+ this.drawLookupTextures();
51
+ this.removeLookupTexturesShaders();
52
+ this.initBackgroundShader();
21
53
  this.activate();
22
54
  }
23
55
  }
56
+ initLookupTexturesShaders() {
57
+ if (this.renderer) {
58
+ this.renderer.handler.addProgram(transmittance(this._parameters), true);
59
+ this.renderer.handler.addProgram(scattering(this._parameters), true);
60
+ }
61
+ }
62
+ initBackgroundShader() {
63
+ if (this.renderer) {
64
+ this.renderer.handler.addProgram(atmosphereBackgroundShader(this._parameters), true);
65
+ }
66
+ }
67
+ removeBackgroundShader() {
68
+ if (this.renderer) {
69
+ this.renderer.handler.removeProgram("atmosphereBackground");
70
+ }
71
+ }
72
+ removeLookupTexturesShaders() {
73
+ if (this.renderer) {
74
+ let h = this.renderer.handler;
75
+ if (this._scatteringBuffer?.isComplete()) {
76
+ h.removeProgram("scattering");
77
+ }
78
+ if (this._transmittanceBuffer?.isComplete()) {
79
+ h.removeProgram("transmittance");
80
+ }
81
+ }
82
+ }
24
83
  onactivate() {
25
84
  super.onactivate();
26
85
  this.planet && this.planet.events.on("draw", this._drawBackground, this);
@@ -29,7 +88,7 @@ export class Atmosphere extends Control {
29
88
  super.ondeactivate();
30
89
  this.planet && this.planet.events.off("draw", this._drawBackground);
31
90
  }
32
- _drawAtmosphereTextures() {
91
+ _initLookupTextures() {
33
92
  let width = 1024, height = 1024;
34
93
  this._transmittanceBuffer = new Framebuffer(this.renderer.handler, {
35
94
  width: width,
@@ -49,51 +108,54 @@ export class Atmosphere extends Control {
49
108
  internalFormat: "RGBA16F"
50
109
  });
51
110
  this._scatteringBuffer.init();
111
+ }
112
+ _renderLookupTextures() {
113
+ if (!this.renderer)
114
+ return;
52
115
  let positionBuffer = this.renderer.screenFramePositionBuffer;
53
116
  let h = this.renderer.handler;
54
117
  let gl = h.gl;
55
118
  //
56
119
  // Draw transmittance texture
57
120
  //
58
- this._transmittanceBuffer.activate();
59
- let p = h.programs.transmittance;
60
- let sha = p._program.attributes;
61
- let shu = p._program.uniforms;
62
- p.activate();
63
- gl.clearColor(0.0, 0.0, 0.0, 1.0);
64
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
65
- gl.uniform2fv(shu.iResolution, [this._transmittanceBuffer.width, this._transmittanceBuffer.height]);
66
- gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
67
- gl.vertexAttribPointer(sha.a_position, positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
68
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, positionBuffer.numItems);
69
- this._transmittanceBuffer.deactivate();
121
+ if (this._transmittanceBuffer) {
122
+ this._transmittanceBuffer.activate();
123
+ let p = h.programs.transmittance;
124
+ let sha = p._program.attributes;
125
+ let shu = p._program.uniforms;
126
+ p.activate();
127
+ gl.clearColor(0.0, 0.0, 0.0, 1.0);
128
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
129
+ gl.uniform2fv(shu.iResolution, [this._transmittanceBuffer.width, this._transmittanceBuffer.height]);
130
+ gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
131
+ gl.vertexAttribPointer(sha.a_position, positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
132
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, positionBuffer.numItems);
133
+ this._transmittanceBuffer.deactivate();
134
+ }
70
135
  //
71
136
  // Draw scattering texture
72
137
  //
73
- this._scatteringBuffer.activate();
74
- p = h.programs.scattering;
75
- sha = p._program.attributes;
76
- shu = p._program.uniforms;
77
- p.activate();
78
- gl.clearColor(0.0, 0.0, 0.0, 1.0);
79
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
80
- gl.uniform2fv(shu.iResolution, [this._scatteringBuffer.width, this._scatteringBuffer.height]);
81
- gl.activeTexture(gl.TEXTURE0);
82
- gl.bindTexture(gl.TEXTURE_2D, this._transmittanceBuffer.textures[0]);
83
- gl.uniform1i(shu.transmittanceTexture, 0);
84
- gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
85
- gl.vertexAttribPointer(sha.a_position, positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
86
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, positionBuffer.numItems);
87
- this._scatteringBuffer.deactivate();
88
- //
89
- // remove shaders
90
- if (this._scatteringBuffer.isComplete()) {
91
- h.removeProgram("scattering");
92
- }
93
- if (this._transmittanceBuffer.isComplete()) {
94
- h.removeProgram("transmittance");
138
+ if (this._scatteringBuffer && this._transmittanceBuffer) {
139
+ this._scatteringBuffer.activate();
140
+ let p = h.programs.scattering;
141
+ let sha = p._program.attributes;
142
+ let shu = p._program.uniforms;
143
+ p.activate();
144
+ gl.clearColor(0.0, 0.0, 0.0, 1.0);
145
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
146
+ gl.uniform2fv(shu.iResolution, [this._scatteringBuffer.width, this._scatteringBuffer.height]);
147
+ gl.activeTexture(gl.TEXTURE0);
148
+ gl.bindTexture(gl.TEXTURE_2D, this._transmittanceBuffer.textures[0]);
149
+ gl.uniform1i(shu.transmittanceTexture, 0);
150
+ gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
151
+ gl.vertexAttribPointer(sha.a_position, positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
152
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, positionBuffer.numItems);
153
+ this._scatteringBuffer.deactivate();
95
154
  }
96
155
  }
156
+ drawLookupTextures() {
157
+ this._renderLookupTextures();
158
+ }
97
159
  _drawBackground() {
98
160
  let h = this.renderer.handler;
99
161
  let sh = h.programs.atmosphereBackground, p = sh._program, shu = p.uniforms, gl = h.gl;
@@ -120,7 +182,7 @@ export class Atmosphere extends Control {
120
182
  gl.enable(gl.DEPTH_TEST);
121
183
  }
122
184
  }
123
- function atmosphereBackgroundShader() {
185
+ function atmosphereBackgroundShader(atmosParams) {
124
186
  return new Program("atmosphereBackground", {
125
187
  uniforms: {
126
188
  iResolution: "vec2",
@@ -144,7 +206,7 @@ function atmosphereBackgroundShader() {
144
206
  fragmentShader: `
145
207
  precision lowp float;
146
208
 
147
- ${atmos.COMMON}
209
+ ${COMMON(atmosParams)}
148
210
 
149
211
  uniform mat4 viewMatrix;
150
212
  uniform vec3 sunPos;
@@ -233,6 +295,10 @@ function atmosphereBackgroundShader() {
233
295
  rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);
234
296
  cameraPosition *= SPHERE_TO_ELLIPSOID_SCALE;
235
297
  lightDirection = normalize(lightDirection * SPHERE_TO_ELLIPSOID_SCALE);
298
+
299
+ if(length(cameraPosition) < BOTTOM_RADIUS + 100.0){
300
+ cameraPosition = normalize(cameraPosition) * (BOTTOM_RADIUS + 100.0);
301
+ }
236
302
 
237
303
  if (intersectSphere(cameraPosition, rayDirection, TOP_RADIUS, offset, distanceToSpace))
238
304
  {
@@ -258,7 +324,7 @@ function atmosphereBackgroundShader() {
258
324
 
259
325
  bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;
260
326
 
261
- if(intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS - 15000.0, distanceToGround) && hitGround)
327
+ if(intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS - 100000.0, distanceToGround) && hitGround)
262
328
  {
263
329
  discard;
264
330
  }
@@ -0,0 +1,59 @@
1
+ import { Control, IControlParams } from "./Control";
2
+ import { Dialog } from '../ui/Dialog';
3
+ import { Slider } from "../ui/Slider";
4
+ import { ToggleButton } from "../ui/ToggleButton";
5
+ import { View } from '../ui/View';
6
+ import { AtmosphereParameters } from "../shaders/atmos";
7
+ interface IAtmosphereConfigParams extends IControlParams {
8
+ }
9
+ /**
10
+ * Helps to set up atmosphere parameters.
11
+ */
12
+ export declare class AtmosphereConfig extends Control {
13
+ protected _toggleBtn: ToggleButton;
14
+ protected _dialog: Dialog<null>;
15
+ protected _panel: View<null>;
16
+ $maxOpacity: HTMLElement | null;
17
+ $minOpacity: HTMLElement | null;
18
+ $rayleight: HTMLElement | null;
19
+ $mie: HTMLElement | null;
20
+ $height: HTMLElement | null;
21
+ $bottomRadius: HTMLElement | null;
22
+ $mieScatteringCoefficient: HTMLElement | null;
23
+ $mieExtinctionCoefficient: HTMLElement | null;
24
+ $rayleighScatteringCoefficientA: HTMLElement | null;
25
+ $rayleighScatteringCoefficientB: HTMLElement | null;
26
+ $rayleighScatteringCoefficientC: HTMLElement | null;
27
+ $ozoneAbsorptionCoefficientA: HTMLElement | null;
28
+ $ozoneAbsorptionCoefficientB: HTMLElement | null;
29
+ $ozoneAbsorptionCoefficientC: HTMLElement | null;
30
+ $sunAngularRadius: HTMLElement | null;
31
+ $sunIntensity: HTMLElement | null;
32
+ $groundAlbedo: HTMLElement | null;
33
+ $ozoneDensityHeight: HTMLElement | null;
34
+ $ozoneDensityWide: HTMLElement | null;
35
+ protected _maxOpacity: Slider;
36
+ protected _minOpacity: Slider;
37
+ protected _rayleight: Slider;
38
+ protected _mie: Slider;
39
+ protected _height: Slider;
40
+ protected _bottomRadius: Slider;
41
+ protected _mieScatteringCoefficient: Slider;
42
+ protected _mieExtinctionCoefficient: Slider;
43
+ protected _rayleighScatteringCoefficientA: Slider;
44
+ protected _rayleighScatteringCoefficientB: Slider;
45
+ protected _rayleighScatteringCoefficientC: Slider;
46
+ protected _ozoneAbsorptionCoefficientA: Slider;
47
+ protected _ozoneAbsorptionCoefficientB: Slider;
48
+ protected _ozoneAbsorptionCoefficientC: Slider;
49
+ protected _sunAngularRadius: Slider;
50
+ protected _sunIntensity: Slider;
51
+ protected _groundAlbedo: Slider;
52
+ protected _ozoneDensityHeight: Slider;
53
+ protected _ozoneDensityWide: Slider;
54
+ protected _parameters: AtmosphereParameters;
55
+ constructor(options?: IAtmosphereConfigParams);
56
+ oninit(): void;
57
+ protected _update(): void;
58
+ }
59
+ export {};