threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VignettePlugin.ts 2.1KB

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