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.
68 lines
1.4 KiB
68 lines
1.4 KiB
import { |
|
ShaderMaterial, |
|
UniformsUtils |
|
} from 'three'; |
|
import { Pass, FullScreenQuad } from './Pass.js'; |
|
|
|
class ShaderPass extends Pass { |
|
|
|
constructor( shader, textureID ) { |
|
|
|
super(); |
|
|
|
this.textureID = ( textureID !== undefined ) ? textureID : 'tDiffuse'; |
|
|
|
if ( shader instanceof ShaderMaterial ) { |
|
|
|
this.uniforms = shader.uniforms; |
|
|
|
this.material = shader; |
|
|
|
} else if ( shader ) { |
|
|
|
this.uniforms = UniformsUtils.clone( shader.uniforms ); |
|
|
|
this.material = new ShaderMaterial( { |
|
|
|
defines: Object.assign( {}, shader.defines ), |
|
uniforms: this.uniforms, |
|
vertexShader: shader.vertexShader, |
|
fragmentShader: shader.fragmentShader |
|
|
|
} ); |
|
|
|
} |
|
|
|
this.fsQuad = new FullScreenQuad( this.material ); |
|
|
|
} |
|
|
|
render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) { |
|
|
|
if ( this.uniforms[ this.textureID ] ) { |
|
|
|
this.uniforms[ this.textureID ].value = readBuffer.texture; |
|
|
|
} |
|
|
|
this.fsQuad.material = this.material; |
|
|
|
if ( this.renderToScreen ) { |
|
|
|
renderer.setRenderTarget( null ); |
|
this.fsQuad.render( renderer ); |
|
|
|
} else { |
|
|
|
renderer.setRenderTarget( writeBuffer ); |
|
// TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600 |
|
if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); |
|
this.fsQuad.render( renderer ); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
export { ShaderPass };
|
|
|