RenderPass.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;(function () {
  2. class RenderPass extends THREE.Pass {
  3. constructor(scene, camera, overrideMaterial, clearColor, clearAlpha) {
  4. super()
  5. this.scene = scene
  6. this.camera = camera
  7. this.overrideMaterial = overrideMaterial
  8. this.clearColor = clearColor
  9. this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0
  10. this.clear = true
  11. this.clearDepth = false
  12. this.needsSwap = false
  13. this._oldClearColor = new THREE.Color()
  14. }
  15. render(
  16. renderer,
  17. writeBuffer,
  18. readBuffer
  19. /*, deltaTime, maskActive */
  20. ) {
  21. const oldAutoClear = renderer.autoClear
  22. renderer.autoClear = false
  23. let oldClearAlpha, oldOverrideMaterial
  24. if (this.overrideMaterial !== undefined) {
  25. oldOverrideMaterial = this.scene.overrideMaterial
  26. this.scene.overrideMaterial = this.overrideMaterial
  27. }
  28. if (this.clearColor) {
  29. renderer.getClearColor(this._oldClearColor)
  30. oldClearAlpha = renderer.getClearAlpha()
  31. renderer.setClearColor(this.clearColor, this.clearAlpha)
  32. }
  33. if (this.clearDepth) {
  34. renderer.clearDepth()
  35. }
  36. renderer.setRenderTarget(this.renderToScreen ? null : readBuffer) // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  37. if (this.clear) renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil)
  38. renderer.render(this.scene, this.camera)
  39. if (this.clearColor) {
  40. renderer.setClearColor(this._oldClearColor, oldClearAlpha)
  41. }
  42. if (this.overrideMaterial !== undefined) {
  43. this.scene.overrideMaterial = oldOverrideMaterial
  44. }
  45. renderer.autoClear = oldAutoClear
  46. }
  47. }
  48. THREE.RenderPass = RenderPass
  49. })()