fxaaPostProcess.ts 1.7 KB

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