WebGPUBackground.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { GPULoadOp } from './constants.js';
  2. import { Color } from '../../../../build/three.module.js';
  3. class WebGPUBackground {
  4. constructor( renderer ) {
  5. this.renderer = renderer;
  6. this.clearAlpha = 1;
  7. this.clearColor = new Color( 0x000000 );
  8. }
  9. render( scene ) {
  10. const renderer = this.renderer;
  11. const background = ( scene.isScene === true ) ? scene.background : null;
  12. const clearColor = this.clearColor;
  13. let clearAlpha = this.clearAlpha;
  14. let forceClear = false;
  15. if ( background === null ) {
  16. // no background settings, use clear color configuration from the renderer
  17. this.clearColor.copy( renderer._clearColor );
  18. this.clearAlpha = renderer._clearAlpha;
  19. } else if ( background !== null && background.isColor === true ) {
  20. // background is an opaque color
  21. clearColor.copy( background );
  22. clearAlpha = 1;
  23. forceClear = true;
  24. }
  25. // configure render pass descriptor
  26. const renderPassDescriptor = renderer._renderPassDescriptor;
  27. const colorAttachment = renderPassDescriptor.colorAttachments[ 0 ];
  28. if ( renderer.autoClear === true || forceClear === true ) {
  29. colorAttachment.loadValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearAlpha };
  30. } else {
  31. colorAttachment.loadValue = GPULoadOp.Load;
  32. }
  33. }
  34. }
  35. export default WebGPUBackground;
粤ICP备19079148号