MCPcopy Create free account
hub / github.com/pmndrs/postprocessing / updateMaterial

Method updateMaterial

src/passes/EffectPass.js:415–509  ·  view source on GitHub ↗

* Updates the compound shader material. * * @protected

()

Source from the content-addressed store, hash-verified

413 */
414
415 updateMaterial() {
416
417 const data = new EffectShaderData();
418 let id = 0;
419
420 for(const effect of this.effects) {
421
422 if(effect.blendMode.blendFunction === BlendFunction.DST) {
423
424 // Check if this effect relies on depth and continue.
425 data.attributes |= (effect.getAttributes() & EffectAttribute.DEPTH);
426
427 } else if((data.attributes & effect.getAttributes() & EffectAttribute.CONVOLUTION) !== 0) {
428
429 throw new Error(`Convolution effects cannot be merged (${effect.name})`);
430
431 } else {
432
433 integrateEffect("e" + id++, effect, data);
434
435 }
436
437 }
438
439 let fragmentHead = data.shaderParts.get(Section.FRAGMENT_HEAD);
440 let fragmentMainImage = data.shaderParts.get(Section.FRAGMENT_MAIN_IMAGE);
441 let fragmentMainUv = data.shaderParts.get(Section.FRAGMENT_MAIN_UV);
442
443 // Integrate the relevant blend functions.
444 const blendRegExp = /\bblend\b/g;
445
446 for(const blendMode of data.blendModes.values()) {
447
448 fragmentHead += blendMode.getShaderCode().replace(blendRegExp, `blend${blendMode.blendFunction}`) + "\n";
449
450 }
451
452 // Check if any effect relies on depth.
453 if((data.attributes & EffectAttribute.DEPTH) !== 0) {
454
455 // Check if depth should be read.
456 if(data.readDepth) {
457
458 fragmentMainImage = "float depth = readDepth(UV);\n\n\t" + fragmentMainImage;
459
460 }
461
462 // Only request a depth texture if none has been provided yet.
463 this.needsDepthTexture = (this.getDepthTexture() === null);
464
465 } else {
466
467 this.needsDepthTexture = false;
468
469 }
470
471 if(data.colorSpace === SRGBColorSpace) {
472

Callers 2

recompileMethod · 0.95
initializeMethod · 0.95

Calls 6

getDepthTextureMethod · 0.95
integrateEffectFunction · 0.85
getAttributesMethod · 0.80
getShaderCodeMethod · 0.80
setMethod · 0.80
setShaderDataMethod · 0.80

Tested by

no test coverage detected