tonemapPostProcess.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Camera } from "../Cameras/camera";
  2. import { Effect } from "../Materials/effect";
  3. import { PostProcess } from "./postProcess";
  4. import { Constants } from "../Engines/constants";
  5. import "../Shaders/tonemap.fragment";
  6. declare type Engine = import("../Engines/engine").Engine;
  7. /** Defines operator used for tonemapping */
  8. export enum TonemappingOperator {
  9. /** Hable */
  10. Hable = 0,
  11. /** Reinhard */
  12. Reinhard = 1,
  13. /** HejiDawson */
  14. HejiDawson = 2,
  15. /** Photographic */
  16. Photographic = 3,
  17. }
  18. /**
  19. * Defines a post process to apply tone mapping
  20. */
  21. export class TonemapPostProcess extends PostProcess {
  22. /**
  23. * Creates a new TonemapPostProcess
  24. * @param name defines the name of the postprocess
  25. * @param _operator defines the operator to use
  26. * @param exposureAdjustment defines the required exposure adjustement
  27. * @param camera defines the camera to use (can be null)
  28. * @param samplingMode defines the required sampling mode (BABYLON.Texture.BILINEAR_SAMPLINGMODE by default)
  29. * @param engine defines the hosting engine (can be ignore if camera is set)
  30. * @param textureFormat defines the texture format to use (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)
  31. */
  32. constructor(name: string, private _operator: TonemappingOperator,
  33. /** Defines the required exposure adjustement */
  34. public exposureAdjustment: number, camera: Camera, samplingMode: number = Constants.TEXTURE_BILINEAR_SAMPLINGMODE, engine?: Engine, textureFormat = Constants.TEXTURETYPE_UNSIGNED_INT) {
  35. super(name, "tonemap", ["_ExposureAdjustment"], null, 1.0, camera, samplingMode, engine, true, null, textureFormat);
  36. var defines = "#define ";
  37. if (this._operator === TonemappingOperator.Hable) {
  38. defines += "HABLE_TONEMAPPING";
  39. }
  40. else if (this._operator === TonemappingOperator.Reinhard) {
  41. defines += "REINHARD_TONEMAPPING";
  42. }
  43. else if (this._operator === TonemappingOperator.HejiDawson) {
  44. defines += "OPTIMIZED_HEJIDAWSON_TONEMAPPING";
  45. }
  46. else if (this._operator === TonemappingOperator.Photographic) {
  47. defines += "PHOTOGRAPHIC_TONEMAPPING";
  48. }
  49. //sadly a second call to create the effect.
  50. this.updateEffect(defines);
  51. this.onApply = (effect: Effect) => {
  52. effect.setFloat("_ExposureAdjustment", this.exposureAdjustment);
  53. };
  54. }
  55. }