智慧水务管理系统 - 精河县供水工程综合管理平台

DerivedCommand.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. import { MetadataComponentType } from "@cesium/engine";
  2. import defined from "../Core/defined.js";
  3. import DrawCommand from "../Renderer/DrawCommand.js";
  4. import RenderState from "../Renderer/RenderState.js";
  5. import ShaderSource from "../Renderer/ShaderSource.js";
  6. import MetadataType from "./MetadataType.js";
  7. import MetadataPickingPipelineStage from "./Model/MetadataPickingPipelineStage.js";
  8. /**
  9. * @private
  10. */
  11. function DerivedCommand() {}
  12. const fragDepthRegex = /\bgl_FragDepth\b/;
  13. const discardRegex = /\bdiscard\b/;
  14. function getDepthOnlyShaderProgram(context, shaderProgram) {
  15. const cachedShader = context.shaderCache.getDerivedShaderProgram(
  16. shaderProgram,
  17. "depthOnly",
  18. );
  19. if (defined(cachedShader)) {
  20. return cachedShader;
  21. }
  22. let fs = shaderProgram.fragmentShaderSource;
  23. let writesDepthOrDiscards = false;
  24. const sources = fs.sources;
  25. for (let i = 0; i < sources.length; ++i) {
  26. if (fragDepthRegex.test(sources[i]) || discardRegex.test(sources[i])) {
  27. writesDepthOrDiscards = true;
  28. break;
  29. }
  30. }
  31. const usesLogDepth = fs.defines.indexOf("LOG_DEPTH") >= 0;
  32. if (!writesDepthOrDiscards && !usesLogDepth) {
  33. const source = `void main()
  34. {
  35. out_FragColor = vec4(1.0);
  36. }
  37. `;
  38. fs = new ShaderSource({
  39. sources: [source],
  40. });
  41. } else if (!writesDepthOrDiscards && usesLogDepth) {
  42. const source = `void main()
  43. {
  44. out_FragColor = vec4(1.0);
  45. czm_writeLogDepth();
  46. }
  47. `;
  48. fs = new ShaderSource({
  49. defines: ["LOG_DEPTH"],
  50. sources: [source],
  51. });
  52. }
  53. return context.shaderCache.createDerivedShaderProgram(
  54. shaderProgram,
  55. "depthOnly",
  56. {
  57. vertexShaderSource: shaderProgram.vertexShaderSource,
  58. fragmentShaderSource: fs,
  59. attributeLocations: shaderProgram._attributeLocations,
  60. },
  61. );
  62. }
  63. function getDepthOnlyRenderState(scene, renderState) {
  64. const cache = scene._depthOnlyRenderStateCache;
  65. const cachedDepthOnlyState = cache[renderState.id];
  66. if (defined(cachedDepthOnlyState)) {
  67. return cachedDepthOnlyState;
  68. }
  69. const rs = RenderState.getState(renderState);
  70. rs.depthMask = true;
  71. rs.colorMask = {
  72. red: false,
  73. green: false,
  74. blue: false,
  75. alpha: false,
  76. };
  77. const depthOnlyState = RenderState.fromCache(rs);
  78. cache[renderState.id] = depthOnlyState;
  79. return depthOnlyState;
  80. }
  81. DerivedCommand.createDepthOnlyDerivedCommand = function (
  82. scene,
  83. command,
  84. context,
  85. result,
  86. ) {
  87. // For a depth only pass, we bind a framebuffer with only a depth attachment (no color attachments),
  88. // do not write color, and write depth. If the fragment shader doesn't modify the fragment depth
  89. // or discard, the driver can replace the fragment shader with a pass-through shader. We're unsure if this
  90. // actually happens so we modify the shader to use a pass-through fragment shader.
  91. if (!defined(result)) {
  92. result = {};
  93. }
  94. const shader = result.depthOnlyCommand?.shaderProgram;
  95. const renderState = result.depthOnlyCommand?.renderState;
  96. result.depthOnlyCommand = DrawCommand.shallowClone(
  97. command,
  98. result.depthOnlyCommand,
  99. );
  100. if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
  101. result.depthOnlyCommand.shaderProgram = getDepthOnlyShaderProgram(
  102. context,
  103. command.shaderProgram,
  104. );
  105. result.depthOnlyCommand.renderState = getDepthOnlyRenderState(
  106. scene,
  107. command.renderState,
  108. );
  109. result.shaderProgramId = command.shaderProgram.id;
  110. } else {
  111. result.depthOnlyCommand.shaderProgram = shader;
  112. result.depthOnlyCommand.renderState = renderState;
  113. }
  114. return result;
  115. };
  116. const writeLogDepthRegex = /\s+czm_writeLogDepth\(/;
  117. const vertexlogDepthRegex = /\s+czm_vertexLogDepth\(/;
  118. function getLogDepthShaderProgram(context, shaderProgram) {
  119. const disableLogDepthWrite =
  120. shaderProgram.fragmentShaderSource.defines.indexOf("LOG_DEPTH_READ_ONLY") >=
  121. 0;
  122. if (disableLogDepthWrite) {
  123. return shaderProgram;
  124. }
  125. const cachedShader = context.shaderCache.getDerivedShaderProgram(
  126. shaderProgram,
  127. "logDepth",
  128. );
  129. if (defined(cachedShader)) {
  130. return cachedShader;
  131. }
  132. const attributeLocations = shaderProgram._attributeLocations;
  133. const vs = shaderProgram.vertexShaderSource.clone();
  134. const fs = shaderProgram.fragmentShaderSource.clone();
  135. vs.defines = defined(vs.defines) ? vs.defines.slice(0) : [];
  136. vs.defines.push("LOG_DEPTH");
  137. fs.defines = defined(fs.defines) ? fs.defines.slice(0) : [];
  138. fs.defines.push("LOG_DEPTH");
  139. let writesLogDepth = false;
  140. let sources = vs.sources;
  141. for (let i = 0; i < sources.length; ++i) {
  142. if (vertexlogDepthRegex.test(sources[i])) {
  143. writesLogDepth = true;
  144. break;
  145. }
  146. }
  147. if (!writesLogDepth) {
  148. for (let i = 0; i < sources.length; ++i) {
  149. sources[i] = ShaderSource.replaceMain(sources[i], "czm_log_depth_main");
  150. }
  151. const logMain = `
  152. void main()
  153. {
  154. czm_log_depth_main();
  155. czm_vertexLogDepth();
  156. }
  157. `;
  158. sources.push(logMain);
  159. }
  160. sources = fs.sources;
  161. writesLogDepth = false;
  162. for (let i = 0; i < sources.length; ++i) {
  163. if (writeLogDepthRegex.test(sources[i])) {
  164. writesLogDepth = true;
  165. }
  166. }
  167. // This define indicates that a log depth value is written by the shader but doesn't use czm_writeLogDepth.
  168. if (fs.defines.indexOf("LOG_DEPTH_WRITE") !== -1) {
  169. writesLogDepth = true;
  170. }
  171. let logSource = "";
  172. if (!writesLogDepth) {
  173. for (let i = 0; i < sources.length; i++) {
  174. sources[i] = ShaderSource.replaceMain(sources[i], "czm_log_depth_main");
  175. }
  176. logSource = `
  177. void main()
  178. {
  179. czm_log_depth_main();
  180. czm_writeLogDepth();
  181. }
  182. `;
  183. }
  184. sources.push(logSource);
  185. return context.shaderCache.createDerivedShaderProgram(
  186. shaderProgram,
  187. "logDepth",
  188. {
  189. vertexShaderSource: vs,
  190. fragmentShaderSource: fs,
  191. attributeLocations: attributeLocations,
  192. },
  193. );
  194. }
  195. DerivedCommand.createLogDepthCommand = function (command, context, result) {
  196. if (!defined(result)) {
  197. result = {};
  198. }
  199. const shader = result.command?.shaderProgram;
  200. result.command = DrawCommand.shallowClone(command, result.command);
  201. if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
  202. result.command.shaderProgram = getLogDepthShaderProgram(
  203. context,
  204. command.shaderProgram,
  205. );
  206. result.shaderProgramId = command.shaderProgram.id;
  207. } else {
  208. result.command.shaderProgram = shader;
  209. }
  210. return result;
  211. };
  212. function getPickShaderProgram(context, shaderProgram, pickId) {
  213. const cachedShader = context.shaderCache.getDerivedShaderProgram(
  214. shaderProgram,
  215. "pick",
  216. );
  217. if (defined(cachedShader)) {
  218. return cachedShader;
  219. }
  220. const attributeLocations = shaderProgram._attributeLocations;
  221. const { sources, defines } = shaderProgram.fragmentShaderSource;
  222. const hasFragData = sources.some((source) => source.includes("out_FragData"));
  223. const outputColorVariable = hasFragData ? "out_FragData_0" : "out_FragColor";
  224. const newMain = `void main ()
  225. {
  226. czm_non_pick_main();
  227. if (${outputColorVariable}.a == 0.0) {
  228. discard;
  229. }
  230. ${outputColorVariable} = ${pickId};
  231. } `;
  232. const length = sources.length;
  233. const newSources = new Array(length + 1);
  234. for (let i = 0; i < length; ++i) {
  235. newSources[i] = ShaderSource.replaceMain(sources[i], "czm_non_pick_main");
  236. }
  237. newSources[length] = newMain;
  238. const fragmentShaderSource = new ShaderSource({
  239. sources: newSources,
  240. defines: defines,
  241. });
  242. return context.shaderCache.createDerivedShaderProgram(shaderProgram, "pick", {
  243. vertexShaderSource: shaderProgram.vertexShaderSource,
  244. fragmentShaderSource: fragmentShaderSource,
  245. attributeLocations: attributeLocations,
  246. });
  247. }
  248. function getPickRenderState(scene, renderState) {
  249. const cache = scene.picking.pickRenderStateCache;
  250. const cachedPickState = cache[renderState.id];
  251. if (defined(cachedPickState)) {
  252. return cachedPickState;
  253. }
  254. const rs = RenderState.getState(renderState);
  255. rs.blending.enabled = false;
  256. // Turns on depth writing for opaque and translucent passes
  257. // Overlapping translucent geometry on the globe surface may exhibit z-fighting
  258. // during the pick pass which may not match the rendered scene. Once
  259. // terrain is on by default and ground primitives are used instead
  260. // this will become less of a problem.
  261. rs.depthMask = true;
  262. const pickState = RenderState.fromCache(rs);
  263. cache[renderState.id] = pickState;
  264. return pickState;
  265. }
  266. DerivedCommand.createPickDerivedCommand = function (
  267. scene,
  268. command,
  269. context,
  270. result,
  271. ) {
  272. if (!defined(result)) {
  273. result = {};
  274. }
  275. const shader = result.pickCommand?.shaderProgram;
  276. const renderState = result.pickCommand?.renderState;
  277. result.pickCommand = DrawCommand.shallowClone(command, result.pickCommand);
  278. if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
  279. result.pickCommand.shaderProgram = getPickShaderProgram(
  280. context,
  281. command.shaderProgram,
  282. command.pickId,
  283. );
  284. result.pickCommand.renderState = getPickRenderState(
  285. scene,
  286. command.renderState,
  287. );
  288. result.shaderProgramId = command.shaderProgram.id;
  289. } else {
  290. result.pickCommand.shaderProgram = shader;
  291. result.pickCommand.renderState = renderState;
  292. }
  293. return result;
  294. };
  295. /**
  296. * Replaces the value of the specified 'define' directive identifier
  297. * with the given value.
  298. *
  299. * The given defines are the parts of the define directives that are
  300. * stored in the `ShaderSource`. For example, the defines may be
  301. * `["EXAMPLE", "EXAMPLE_VALUE 123"]`
  302. *
  303. * Calling `replaceDefine(defines, "EXAMPLE", 999)` will result in
  304. * the defines being
  305. * `["EXAMPLE 999", "EXAMPLE_VALUE 123"]`
  306. *
  307. * @param {string[]} defines The define directive identifiers
  308. * @param {string} defineName The name (identifier) of the define directive
  309. * @param {any} newDefineValue The new value whose string representation
  310. * will become the token string for the define directive
  311. * @private
  312. */
  313. function replaceDefine(defines, defineName, newDefineValue) {
  314. const n = defines.length;
  315. for (let i = 0; i < n; i++) {
  316. const define = defines[i];
  317. const tokens = define.trimStart().split(/\s+/);
  318. if (tokens[0] === defineName) {
  319. defines[i] = `${defineName} ${newDefineValue}`;
  320. }
  321. }
  322. }
  323. /**
  324. * Returns the component count for the given class property, or
  325. * its array length if it is an array.
  326. *
  327. * This will be
  328. * `[1, 2, 3, 4]` for `[SCALAR, VEC2, VEC3, VEC4`] types,
  329. * or the array length if it is an array.
  330. *
  331. * @param {MetadataClassProperty} classProperty The class property
  332. * @returns {number} The component count
  333. * @private
  334. */
  335. function getComponentCount(classProperty) {
  336. if (!classProperty.isArray) {
  337. return MetadataType.getComponentCount(classProperty.type);
  338. }
  339. return classProperty.arrayLength;
  340. }
  341. /**
  342. * Returns a shader statement that applies the inverse of the
  343. * value transform to the given value, based on the given offset
  344. * and scale.
  345. *
  346. * @param {string} input The input value
  347. * @param {string} offset The offset
  348. * @param {string} scale The scale
  349. * @returns {string} The statement
  350. */
  351. function unapplyValueTransform(input, offset, scale) {
  352. return `((${input} - float(${offset})) / float(${scale}))`;
  353. }
  354. /**
  355. * Returns a shader statement that applies the inverse of the
  356. * normalization, based on the given component type
  357. *
  358. * @param {string} input The input value
  359. * @param {string} componentType The component type
  360. * @returns {string} The statement
  361. */
  362. function unnormalize(input, componentType) {
  363. const max = MetadataComponentType.getMaximum(componentType);
  364. return `(${input}) / float(${max})`;
  365. }
  366. /**
  367. * Creates a shader statement that returns the value of the specified
  368. * property, normalized to the range [0, 1].
  369. *
  370. * @param {MetadataClassProperty} classProperty The class property
  371. * @param {object} metadataProperty The metadata property, either
  372. * a `PropertyTextureProperty` or a `PropertyAttributeProperty`
  373. * @returns {string} The string
  374. */
  375. function getSourceValueStringScalar(classProperty, metadataProperty) {
  376. let result = `float(value)`;
  377. // The 'hasValueTransform' indicates whether the property
  378. // (or its class property) did define an 'offset' or 'scale'.
  379. // Even when they had not been defined in the JSON, they are
  380. // defined in the object, with default values.
  381. if (metadataProperty.hasValueTransform) {
  382. const offset = metadataProperty.offset;
  383. const scale = metadataProperty.scale;
  384. result = unapplyValueTransform(result, offset, scale);
  385. }
  386. if (!classProperty.normalized) {
  387. result = unnormalize(result, classProperty.componentType);
  388. }
  389. return result;
  390. }
  391. /**
  392. * Creates a shader statement that returns the value of the specified
  393. * component of the given property, normalized to the range [0, 1].
  394. *
  395. * @param {MetadataClassProperty} classProperty The class property
  396. * @param {object} metadataProperty The metadata property, either
  397. * a `PropertyTextureProperty` or a `PropertyAttributeProperty`
  398. * @param {string} componentName The name, in ["x", "y", "z", "w"]
  399. * @returns {string} The string
  400. */
  401. function getSourceValueStringComponent(
  402. classProperty,
  403. metadataProperty,
  404. componentName,
  405. ) {
  406. const valueString = `value.${componentName}`;
  407. let result = `float(${valueString})`;
  408. // The 'hasValueTransform' indicates whether the property
  409. // (or its class property) did define an 'offset' or 'scale'.
  410. // Even when they had not been defined in the JSON, they are
  411. // defined in the object, with default values
  412. // Note that in the 'PropertyTextureProperty' and the
  413. // 'PropertyAttributeProperty', these values are
  414. // stored as "object types" (like 'Cartesian2'), whereas
  415. // in the 'MetadataClassProperty', they are stored as
  416. // "array types", e.g. a `[number, number]`
  417. if (metadataProperty.hasValueTransform) {
  418. const offset = metadataProperty.offset[componentName];
  419. const scale = metadataProperty.scale[componentName];
  420. result = unapplyValueTransform(result, offset, scale);
  421. }
  422. if (!classProperty.normalized) {
  423. result = unnormalize(result, classProperty.componentType);
  424. }
  425. return result;
  426. }
  427. /**
  428. * Creates a new `ShaderProgram` from the given input that renders metadata
  429. * values into the frame buffer, according to the given picked metadata info.
  430. *
  431. * This will update the `defines` of the fragment shader of the given shader
  432. * program, by setting `METADATA_PICKING_ENABLED`, and updating the
  433. * `METADATA_PICKING_VALUE_*` defines so that they reflect the components
  434. * of the metadata that should be written into the RGBA (vec4) that
  435. * ends up as the 'color' in the frame buffer.
  436. *
  437. * The RGBA values will eventually be converted back into an actual metadata
  438. * value in `Picking.js`, by calling `MetadataPicking.decodeMetadataValues`.
  439. *
  440. * @param {Context} context The context
  441. * @param {ShaderProgram} shaderProgram The shader program
  442. * @param {PickedMetadataInfo} pickedMetadataInfo The picked metadata info
  443. * @returns {ShaderProgram} The new shader program
  444. * @private
  445. */
  446. function getPickMetadataShaderProgram(
  447. context,
  448. shaderProgram,
  449. pickedMetadataInfo,
  450. ) {
  451. const schemaId = pickedMetadataInfo.schemaId;
  452. const className = pickedMetadataInfo.className;
  453. const propertyName = pickedMetadataInfo.propertyName;
  454. const keyword = `pickMetadata-${schemaId}-${className}-${propertyName}`;
  455. const shader = context.shaderCache.getDerivedShaderProgram(
  456. shaderProgram,
  457. keyword,
  458. );
  459. if (defined(shader)) {
  460. return shader;
  461. }
  462. const metadataProperty = pickedMetadataInfo.metadataProperty;
  463. const classProperty = pickedMetadataInfo.classProperty;
  464. const glslType = classProperty.getGlslType();
  465. // Define the components that will go into the output `metadataValues`.
  466. // This will be the 'color' that is written into the frame buffer,
  467. // meaning that the values should be in [0.0, 1.0], and will become
  468. // values in [0, 255] in the frame buffer.
  469. // By default, all of them are 0.0.
  470. const sourceValueStrings = ["0.0", "0.0", "0.0", "0.0"];
  471. const componentCount = getComponentCount(classProperty);
  472. if (componentCount === 1) {
  473. // When the property is a scalar, store the source value
  474. // string directly in `metadataValues.x`
  475. sourceValueStrings[0] = getSourceValueStringScalar(
  476. classProperty,
  477. metadataProperty,
  478. );
  479. } else {
  480. // When the property is an array, store the array elements
  481. // in `metadataValues.x/y/z/w`
  482. const componentNames = ["x", "y", "z", "w"];
  483. for (let i = 0; i < componentCount; i++) {
  484. sourceValueStrings[i] = getSourceValueStringComponent(
  485. classProperty,
  486. metadataProperty,
  487. componentNames[i],
  488. );
  489. }
  490. }
  491. const newDefines = shaderProgram.fragmentShaderSource.defines.slice();
  492. newDefines.push(MetadataPickingPipelineStage.METADATA_PICKING_ENABLED);
  493. // Replace the defines of the shader, using the type, property
  494. // access, and value components that have been determined
  495. replaceDefine(
  496. newDefines,
  497. MetadataPickingPipelineStage.METADATA_PICKING_VALUE_TYPE,
  498. glslType,
  499. );
  500. replaceDefine(
  501. newDefines,
  502. MetadataPickingPipelineStage.METADATA_PICKING_VALUE_STRING,
  503. `metadata.${propertyName}`,
  504. );
  505. replaceDefine(
  506. newDefines,
  507. MetadataPickingPipelineStage.METADATA_PICKING_VALUE_COMPONENT_X,
  508. sourceValueStrings[0],
  509. );
  510. replaceDefine(
  511. newDefines,
  512. MetadataPickingPipelineStage.METADATA_PICKING_VALUE_COMPONENT_Y,
  513. sourceValueStrings[1],
  514. );
  515. replaceDefine(
  516. newDefines,
  517. MetadataPickingPipelineStage.METADATA_PICKING_VALUE_COMPONENT_Z,
  518. sourceValueStrings[2],
  519. );
  520. replaceDefine(
  521. newDefines,
  522. MetadataPickingPipelineStage.METADATA_PICKING_VALUE_COMPONENT_W,
  523. sourceValueStrings[3],
  524. );
  525. const newFragmentShaderSource = new ShaderSource({
  526. sources: shaderProgram.fragmentShaderSource.sources,
  527. defines: newDefines,
  528. });
  529. const newShader = context.shaderCache.createDerivedShaderProgram(
  530. shaderProgram,
  531. keyword,
  532. {
  533. vertexShaderSource: shaderProgram.vertexShaderSource,
  534. fragmentShaderSource: newFragmentShaderSource,
  535. attributeLocations: shaderProgram._attributeLocations,
  536. },
  537. );
  538. return newShader;
  539. }
  540. /**
  541. * @private
  542. */
  543. DerivedCommand.createPickMetadataDerivedCommand = function (
  544. scene,
  545. command,
  546. context,
  547. result,
  548. ) {
  549. if (!defined(result)) {
  550. result = {};
  551. }
  552. result.pickMetadataCommand = DrawCommand.shallowClone(
  553. command,
  554. result.pickMetadataCommand,
  555. );
  556. result.pickMetadataCommand.shaderProgram = getPickMetadataShaderProgram(
  557. context,
  558. command.shaderProgram,
  559. command.pickedMetadataInfo,
  560. );
  561. result.pickMetadataCommand.renderState = getPickRenderState(
  562. scene,
  563. command.renderState,
  564. );
  565. result.shaderProgramId = command.shaderProgram.id;
  566. return result;
  567. };
  568. function getHdrShaderProgram(context, shaderProgram) {
  569. const cachedShader = context.shaderCache.getDerivedShaderProgram(
  570. shaderProgram,
  571. "HDR",
  572. );
  573. if (defined(cachedShader)) {
  574. return cachedShader;
  575. }
  576. const attributeLocations = shaderProgram._attributeLocations;
  577. const vs = shaderProgram.vertexShaderSource.clone();
  578. const fs = shaderProgram.fragmentShaderSource.clone();
  579. vs.defines = defined(vs.defines) ? vs.defines.slice(0) : [];
  580. vs.defines.push("HDR");
  581. fs.defines = defined(fs.defines) ? fs.defines.slice(0) : [];
  582. fs.defines.push("HDR");
  583. return context.shaderCache.createDerivedShaderProgram(shaderProgram, "HDR", {
  584. vertexShaderSource: vs,
  585. fragmentShaderSource: fs,
  586. attributeLocations: attributeLocations,
  587. });
  588. }
  589. DerivedCommand.createHdrCommand = function (command, context, result) {
  590. if (!defined(result)) {
  591. result = {};
  592. }
  593. const shader = result.command?.shaderProgram;
  594. result.command = DrawCommand.shallowClone(command, result.command);
  595. if (!defined(shader) || result.shaderProgramId !== command.shaderProgram.id) {
  596. result.command.shaderProgram = getHdrShaderProgram(
  597. context,
  598. command.shaderProgram,
  599. );
  600. result.shaderProgramId = command.shaderProgram.id;
  601. } else {
  602. result.command.shaderProgram = shader;
  603. }
  604. return result;
  605. };
  606. export default DerivedCommand;