WebGPUBackground.js 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { GPULoadOp } from './constants.js';
  2. import { Color } from '../../../../build/three.module.js';
  3. class WebGPUBackground {
  4. constructor() {
  5. this.clearAlpha = 0;
  6. this.clearColor = new Color( 0x000000 );
  7. }
  8. render( scene, renderPassDescriptor, autoClear ) {
  9. const background = ( scene.isScene === true ) ? scene.background : null;
  10. const clearColor = this.clearColor;
  11. let clearAlpha = this.clearAlpha;
  12. let forceClear = false;
  13. if ( background !== null && background.isColor === true ) {
  14. clearColor.copy( background );
  15. clearAlpha = 1;
  16. forceClear = true;
  17. }
  18. const colorAttachment = renderPassDescriptor.colorAttachments[ 0 ];
  19. if ( autoClear === true || forceClear === true ) {
  20. colorAttachment.loadValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearAlpha };
  21. } else {
  22. colorAttachment.loadValue = GPULoadOp.Load;
  23. }
  24. }
  25. }
  26. export default WebGPUBackground;