grainPostProcess.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { __decorate } from "../tslib.es6.js";
  2. import { PostProcess } from "./postProcess.js";
  3. import "../Shaders/grain.fragment.js";
  4. import { RegisterClass } from "../Misc/typeStore.js";
  5. import { serialize } from "../Misc/decorators.js";
  6. import { SerializationHelper } from "../Misc/decorators.serialization.js";
  7. /**
  8. * The GrainPostProcess adds noise to the image at mid luminance levels
  9. */
  10. export class GrainPostProcess extends PostProcess {
  11. /**
  12. * Gets a string identifying the name of the class
  13. * @returns "GrainPostProcess" string
  14. */
  15. getClassName() {
  16. return "GrainPostProcess";
  17. }
  18. /**
  19. * Creates a new instance of @see GrainPostProcess
  20. * @param name The name of the effect.
  21. * @param options The required width/height ratio to downsize to before computing the render pass.
  22. * @param camera The camera to apply the render pass to.
  23. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  24. * @param engine The engine which the post process will be applied. (default: current engine)
  25. * @param reusable If the post process can be reused on the same frame. (default: false)
  26. * @param textureType Type of textures used when performing the post process. (default: 0)
  27. * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
  28. */
  29. constructor(name, options, camera, samplingMode, engine, reusable, textureType = 0, blockCompilation = false) {
  30. super(name, "grain", ["intensity", "animatedSeed"], [], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, blockCompilation);
  31. /**
  32. * The intensity of the grain added (default: 30)
  33. */
  34. this.intensity = 30;
  35. /**
  36. * If the grain should be randomized on every frame
  37. */
  38. this.animated = false;
  39. this.onApplyObservable.add((effect) => {
  40. effect.setFloat("intensity", this.intensity);
  41. effect.setFloat("animatedSeed", this.animated ? Math.random() + 1 : 1);
  42. });
  43. }
  44. /**
  45. * @internal
  46. */
  47. static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {
  48. return SerializationHelper.Parse(() => {
  49. return new GrainPostProcess(parsedPostProcess.name, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, scene.getEngine(), parsedPostProcess.reusable);
  50. }, parsedPostProcess, scene, rootUrl);
  51. }
  52. }
  53. __decorate([
  54. serialize()
  55. ], GrainPostProcess.prototype, "intensity", void 0);
  56. __decorate([
  57. serialize()
  58. ], GrainPostProcess.prototype, "animated", void 0);
  59. RegisterClass("BABYLON.GrainPostProcess", GrainPostProcess);
  60. //# sourceMappingURL=grainPostProcess.js.map