threepipe
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FilmicGrainPlugin.ts 2.2KB

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