* @param {Object} [hooks] The hooks in the shader to replace. * @returns {p5.Shader}
(hooks)
| 412 | * @returns {p5.Shader} |
| 413 | */ |
| 414 | modify(hooks) { |
| 415 | // p5._validateParameters('p5.Shader.modify', arguments); |
| 416 | const newHooks = { |
| 417 | vertex: {}, |
| 418 | fragment: {}, |
| 419 | compute: {}, |
| 420 | helpers: {} |
| 421 | }; |
| 422 | for (const key in hooks) { |
| 423 | if (key === 'declarations') continue; |
| 424 | if (key === 'uniforms') continue; |
| 425 | if (key === 'storageUniforms') continue; |
| 426 | if (key === 'varyingVariables') continue; |
| 427 | if (key === 'instanceIDVarying') continue; |
| 428 | if (key === 'vertexDeclarations') { |
| 429 | newHooks.vertex.declarations = |
| 430 | (newHooks.vertex.declarations || '') + '\n' + hooks[key]; |
| 431 | } else if (key === 'fragmentDeclarations') { |
| 432 | newHooks.fragment.declarations = |
| 433 | (newHooks.fragment.declarations || '') + '\n' + hooks[key]; |
| 434 | } else if (key === 'computeDeclarations') { |
| 435 | newHooks.compute.declarations = |
| 436 | (newHooks.compute.declarations || '') + '\n' + hooks[key]; |
| 437 | } else if (this.hooks.vertex[key]) { |
| 438 | newHooks.vertex[key] = hooks[key]; |
| 439 | } else if (this.hooks.fragment[key]) { |
| 440 | newHooks.fragment[key] = hooks[key]; |
| 441 | } else if (this.hooks.compute[key]) { |
| 442 | newHooks.compute[key] = hooks[key]; |
| 443 | } else { |
| 444 | newHooks.helpers[key] = hooks[key]; |
| 445 | } |
| 446 | } |
| 447 | const modifiedVertex = Object.assign({}, this.hooks.modified.vertex); |
| 448 | const modifiedFragment = Object.assign({}, this.hooks.modified.fragment); |
| 449 | const modifiedCompute = Object.assign({}, this.hooks.modified.compute); |
| 450 | for (const key in newHooks.vertex || {}) { |
| 451 | if (key === 'declarations') continue; |
| 452 | modifiedVertex[key] = true; |
| 453 | } |
| 454 | for (const key in newHooks.fragment || {}) { |
| 455 | if (key === 'declarations') continue; |
| 456 | modifiedFragment[key] = true; |
| 457 | } |
| 458 | for (const key in newHooks.compute || {}) { |
| 459 | if (key === 'declarations') continue; |
| 460 | modifiedCompute[key] = true; |
| 461 | } |
| 462 | |
| 463 | const args = [this._renderer]; |
| 464 | if (this.shaderType === 'compute') { |
| 465 | args.push(this._computeSrc); |
| 466 | } else { |
| 467 | args.push(this._vertSrc, this._fragSrc); |
| 468 | } |
| 469 | args.push({ |
| 470 | declarations: |
| 471 | (this.hooks.declarations || '') + '\n' + (hooks.declarations || ''), |
no test coverage detected