fxaaPostProcess.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Nullable } from "types";
  2. import { Camera } from "Cameras/camera";
  3. import { Effect } from "Materials/effect";
  4. import { Texture } from "Materials/Textures/texture";
  5. import { PostProcess, PostProcessOptions } from "./postProcess";
  6. import { Engine } from "Engine/engine";
  7. /**
  8. * Fxaa post process
  9. * @see https://doc.babylonjs.com/how_to/how_to_use_postprocesses#fxaa
  10. */
  11. export class FxaaPostProcess extends PostProcess {
  12. /** @hidden */
  13. public texelWidth: number;
  14. /** @hidden */
  15. public texelHeight: number;
  16. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
  17. super(name, "fxaa", ["texelSize"], null, options, camera, samplingMode || Texture.BILINEAR_SAMPLINGMODE, engine, reusable, null, textureType, "fxaa", undefined, true);
  18. const defines = this._getDefines();
  19. this.updateEffect(defines);
  20. this.onApplyObservable.add((effect: Effect) => {
  21. var texelSize = this.texelSize;
  22. effect.setFloat2("texelSize", texelSize.x, texelSize.y);
  23. });
  24. }
  25. private _getDefines(): Nullable<string> {
  26. const engine = this.getEngine();
  27. if (!engine) {
  28. return null;
  29. }
  30. const glInfo = engine.getGlInfo();
  31. if (glInfo && glInfo.renderer && glInfo.renderer.toLowerCase().indexOf("mali") > -1) {
  32. return "#define MALI 1\n";
  33. }
  34. return null;
  35. }
  36. }