Dies ist das Repository meines kleinen Portfolios.
Im Hintergrund läuft eine Planetensimulation, geschrieben in JavaScript und Three.js.
Die zu sehenden Texturen stammen von:
https://www.solarsystemscope.com/textures/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.1 KiB
102 lines
2.1 KiB
import { GPULoadOp } from './constants.js'; |
|
import { Color } from 'three'; |
|
|
|
let _clearAlpha; |
|
const _clearColor = new Color(); |
|
|
|
class WebGPUBackground { |
|
|
|
constructor( renderer ) { |
|
|
|
this.renderer = renderer; |
|
|
|
this.forceClear = false; |
|
|
|
} |
|
|
|
clear() { |
|
|
|
this.forceClear = true; |
|
|
|
} |
|
|
|
update( scene ) { |
|
|
|
const renderer = this.renderer; |
|
const background = ( scene.isScene === true ) ? scene.background : null; |
|
let forceClear = this.forceClear; |
|
|
|
if ( background === null ) { |
|
|
|
// no background settings, use clear color configuration from the renderer |
|
|
|
_clearColor.copy( renderer._clearColor ); |
|
_clearAlpha = renderer._clearAlpha; |
|
|
|
} else if ( background.isColor === true ) { |
|
|
|
// background is an opaque color |
|
|
|
_clearColor.copy( background ); |
|
_clearAlpha = 1; |
|
forceClear = true; |
|
|
|
} else { |
|
|
|
console.error( 'THREE.WebGPURenderer: Unsupported background configuration.', background ); |
|
|
|
} |
|
|
|
// configure render pass descriptor |
|
|
|
const renderPassDescriptor = renderer._renderPassDescriptor; |
|
const colorAttachment = renderPassDescriptor.colorAttachments[ 0 ]; |
|
const depthStencilAttachment = renderPassDescriptor.depthStencilAttachment; |
|
|
|
if ( renderer.autoClear === true || forceClear === true ) { |
|
|
|
if ( renderer.autoClearColor === true ) { |
|
|
|
colorAttachment.loadValue = { r: _clearColor.r, g: _clearColor.g, b: _clearColor.b, a: _clearAlpha }; |
|
|
|
} else { |
|
|
|
colorAttachment.loadValue = GPULoadOp.Load; |
|
|
|
} |
|
|
|
if ( renderer.autoClearDepth === true ) { |
|
|
|
depthStencilAttachment.depthLoadValue = renderer._clearDepth; |
|
|
|
} else { |
|
|
|
depthStencilAttachment.depthLoadValue = GPULoadOp.Load; |
|
|
|
} |
|
|
|
if ( renderer.autoClearStencil === true ) { |
|
|
|
depthStencilAttachment.stencilLoadValue = renderer._clearStencil; |
|
|
|
} else { |
|
|
|
depthStencilAttachment.stencilLoadValue = GPULoadOp.Load; |
|
|
|
} |
|
|
|
} else { |
|
|
|
colorAttachment.loadValue = GPULoadOp.Load; |
|
depthStencilAttachment.depthLoadValue = GPULoadOp.Load; |
|
depthStencilAttachment.stencilLoadValue = GPULoadOp.Load; |
|
|
|
} |
|
|
|
this.forceClear = false; |
|
|
|
} |
|
|
|
} |
|
|
|
export default WebGPUBackground;
|
|
|