threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChromaticAberrationPlugin.ts 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {uiFolderContainer, uiSlider, uiToggle} from 'uiconfig.js'
  2. import {glsl, onChange, serialize} from 'ts-browser-helpers'
  3. import {uniform} from '../../three'
  4. import ChromaticAberration from './shaders/ChromaticAberrationPlugin.glsl'
  5. import {AScreenPassExtensionPlugin} from './AScreenPassExtensionPlugin'
  6. /**
  7. * Chromatic Aberration Plugin
  8. * Adds an extension to {@link ScreenPass} material
  9. * for applying chromatic aberration effect on the final buffer before rendering to screen.
  10. * The intensity of the aberration can be controlled with the `intensity`(previously aberrationIntensity) property.
  11. *
  12. * @category Plugins
  13. */
  14. @uiFolderContainer('ChromaticAberration')
  15. export class ChromaticAberrationPlugin extends AScreenPassExtensionPlugin<''> {
  16. static readonly PluginType = 'ChromaticAberration'
  17. readonly extraUniforms = {
  18. aberrationIntensity: {value: 1},
  19. } as const
  20. @onChange(ChromaticAberrationPlugin.prototype.setDirty)
  21. @uiToggle('Enable')
  22. @serialize() enabled: boolean
  23. @uiSlider('Intensity', [0., 0.3], 0.001)
  24. @uniform({propKey: 'aberrationIntensity'})
  25. @serialize('aberrationIntensity') intensity = 0.5
  26. /**
  27. * The priority of the material extension when applied to the material in ScreenPass
  28. * set to very low priority, so applied at the end
  29. */
  30. priority = -50
  31. parsFragmentSnippet = () => {
  32. if (!this.enabled) return ''
  33. return glsl`
  34. uniform float aberrationIntensity;
  35. ${ChromaticAberration}
  36. `
  37. }
  38. protected _shaderPatch = 'diffuseColor = ChromaticAberration(diffuseColor);'
  39. get aberrationIntensity() {
  40. console.warn('ChromaticAberrationPlugin.aberrationIntensity is deprecated, use ChromaticAberrationPlugin.intensity instead')
  41. return this.intensity
  42. }
  43. set aberrationIntensity(v) {
  44. console.warn('ChromaticAberrationPlugin.aberrationIntensity is deprecated, use ChromaticAberrationPlugin.intensity instead')
  45. this.intensity = v
  46. }
  47. constructor(enabled = true) {
  48. super()
  49. this.enabled = enabled
  50. }
  51. }