tonemapPostProcess.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { PostProcess } from "./postProcess.js";
  2. import "../Shaders/tonemap.fragment.js";
  3. /** Defines operator used for tonemapping */
  4. export var TonemappingOperator;
  5. (function (TonemappingOperator) {
  6. /** Hable */
  7. TonemappingOperator[TonemappingOperator["Hable"] = 0] = "Hable";
  8. /** Reinhard */
  9. TonemappingOperator[TonemappingOperator["Reinhard"] = 1] = "Reinhard";
  10. /** HejiDawson */
  11. TonemappingOperator[TonemappingOperator["HejiDawson"] = 2] = "HejiDawson";
  12. /** Photographic */
  13. TonemappingOperator[TonemappingOperator["Photographic"] = 3] = "Photographic";
  14. })(TonemappingOperator || (TonemappingOperator = {}));
  15. /**
  16. * Defines a post process to apply tone mapping
  17. */
  18. export class TonemapPostProcess extends PostProcess {
  19. /**
  20. * Gets a string identifying the name of the class
  21. * @returns "TonemapPostProcess" string
  22. */
  23. getClassName() {
  24. return "TonemapPostProcess";
  25. }
  26. /**
  27. * Creates a new TonemapPostProcess
  28. * @param name defines the name of the postprocess
  29. * @param _operator defines the operator to use
  30. * @param exposureAdjustment defines the required exposure adjustment
  31. * @param camera defines the camera to use (can be null)
  32. * @param samplingMode defines the required sampling mode (BABYLON.Texture.BILINEAR_SAMPLINGMODE by default)
  33. * @param engine defines the hosting engine (can be ignore if camera is set)
  34. * @param textureFormat defines the texture format to use (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)
  35. * @param reusable If the post process can be reused on the same frame. (default: false)
  36. */
  37. constructor(name, _operator,
  38. /** Defines the required exposure adjustment */
  39. exposureAdjustment, camera, samplingMode = 2, engine, textureFormat = 0, reusable) {
  40. super(name, "tonemap", ["_ExposureAdjustment"], null, 1.0, camera, samplingMode, engine, reusable, null, textureFormat);
  41. this._operator = _operator;
  42. this.exposureAdjustment = exposureAdjustment;
  43. let defines = "#define ";
  44. if (this._operator === TonemappingOperator.Hable) {
  45. defines += "HABLE_TONEMAPPING";
  46. }
  47. else if (this._operator === TonemappingOperator.Reinhard) {
  48. defines += "REINHARD_TONEMAPPING";
  49. }
  50. else if (this._operator === TonemappingOperator.HejiDawson) {
  51. defines += "OPTIMIZED_HEJIDAWSON_TONEMAPPING";
  52. }
  53. else if (this._operator === TonemappingOperator.Photographic) {
  54. defines += "PHOTOGRAPHIC_TONEMAPPING";
  55. }
  56. //sadly a second call to create the effect.
  57. this.updateEffect(defines);
  58. this.onApply = (effect) => {
  59. effect.setFloat("_ExposureAdjustment", this.exposureAdjustment);
  60. };
  61. }
  62. }
  63. //# sourceMappingURL=tonemapPostProcess.js.map