* Updates the compound shader material. * * @protected
()
| 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 |
no test coverage detected