15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { Cesium3DTileStyle } from "../../Source/Cesium.js";
import { HeadingPitchRange } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { PerspectiveFrustum } from "../../Source/Cesium.js";
import { PointCloudEyeDomeLighting } from "../../Source/Cesium.js";
import Cesium3DTilesTester from "../Cesium3DTilesTester.js";
import createScene from "../createScene.js";
 
describe(
  "Scene/PointCloudEyeDomeLighting",
  function () {
    var scene;
    var centerLongitude = -1.31968;
    var centerLatitude = 0.698874;
 
    var pointCloudNoColorUrl =
      "./Data/Cesium3DTiles/PointCloud/PointCloudNoColor/tileset.json";
 
    function setCamera(longitude, latitude) {
      // Point the camera to the center of the tile
      var center = Cartesian3.fromRadians(longitude, latitude, 5.0);
      scene.camera.lookAt(center, new HeadingPitchRange(0.0, -1.57, 5.0));
    }
 
    beforeAll(function () {
      scene = createScene();
    });
 
    afterAll(function () {
      scene.destroyForSpecs();
    });
 
    beforeEach(function () {
      var camera = scene.camera;
      camera.frustum = new PerspectiveFrustum();
      camera.frustum.aspectRatio =
        scene.drawingBufferWidth / scene.drawingBufferHeight;
      camera.frustum.fov = CesiumMath.toRadians(60.0);
 
      setCamera(centerLongitude, centerLatitude);
    });
 
    afterEach(function () {
      scene.primitives.removeAll();
    });
 
    it("adds a clear command and a post-processing draw call", function () {
      if (!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)) {
        return;
      }
 
      return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(
        function (tileset) {
          tileset.pointCloudShading.eyeDomeLighting = true;
 
          scene.renderForSpecs();
          var originalLength = scene.frameState.commandList.length;
 
          tileset.pointCloudShading.attenuation = true;
          scene.renderForSpecs();
          var newLength = scene.frameState.commandList.length;
          expect(newLength).toEqual(originalLength + 2);
        }
      );
    });
 
    it("does not change commands for pick calls", function () {
      if (!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)) {
        return;
      }
 
      return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(
        function (tileset) {
          tileset.pointCloudShading.eyeDomeLighting = true;
 
          scene.pickForSpecs();
          var originalLength = scene.frameState.commandList.length;
 
          tileset.pointCloudShading.attenuation = true;
          scene.pickForSpecs();
          var newLength = scene.frameState.commandList.length;
          expect(newLength).toEqual(originalLength);
        }
      );
    });
 
    it("works when point cloud shader changes", function () {
      if (!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)) {
        return;
      }
 
      return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(
        function (tileset) {
          tileset.pointCloudShading.attenuation = true;
          tileset.pointCloudShading.eyeDomeLighting = true;
 
          scene.renderForSpecs();
 
          tileset.pointCloudShading.eyeDomeLighting = false;
 
          scene.renderForSpecs();
 
          tileset.style = new Cesium3DTileStyle({
            color: "color('red')",
          });
 
          scene.renderForSpecs();
 
          // Forces destroyed shaders to be released
          scene.context.shaderCache.destroyReleasedShaderPrograms();
 
          tileset.pointCloudShading.eyeDomeLighting = true;
 
          scene.renderForSpecs();
 
          expect(scene.frameState.commandList.length).toBe(3);
        }
      );
    });
  },
  "WebGL"
);