particleBlendMultiplyBlock.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { NodeMaterialBlock } from '../../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../../Enums/nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
  4. import { NodeMaterialBlockTargets } from '../../Enums/nodeMaterialBlockTargets';
  5. import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
  6. import { _TypeStore } from '../../../../Misc/typeStore';
  7. /**
  8. * Block used for the particle blend multiply section
  9. */
  10. export class ParticleBlendMultiplyBlock extends NodeMaterialBlock {
  11. /**
  12. * Create a new ParticleBlendMultiplyBlock
  13. * @param name defines the block name
  14. */
  15. public constructor(name: string) {
  16. super(name, NodeMaterialBlockTargets.Fragment);
  17. this._isUnique = true;
  18. this.registerInput("color", NodeMaterialBlockConnectionPointTypes.Color4, false, NodeMaterialBlockTargets.Fragment);
  19. this.registerInput("alphaTexture", NodeMaterialBlockConnectionPointTypes.Float, false, NodeMaterialBlockTargets.Fragment);
  20. this.registerInput("alphaColor", NodeMaterialBlockConnectionPointTypes.Float, false, NodeMaterialBlockTargets.Fragment);
  21. this.registerOutput("blendColor", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Fragment);
  22. }
  23. /**
  24. * Gets the current class name
  25. * @returns the class name
  26. */
  27. public getClassName() {
  28. return "ParticleBlendMultiplyBlock";
  29. }
  30. /**
  31. * Gets the color input component
  32. */
  33. public get color(): NodeMaterialConnectionPoint {
  34. return this._inputs[0];
  35. }
  36. /**
  37. * Gets the alphaTexture input component
  38. */
  39. public get alphaTexture(): NodeMaterialConnectionPoint {
  40. return this._inputs[1];
  41. }
  42. /**
  43. * Gets the alphaColor input component
  44. */
  45. public get alphaColor(): NodeMaterialConnectionPoint {
  46. return this._inputs[2];
  47. }
  48. /**
  49. * Gets the blendColor output component
  50. */
  51. public get blendColor(): NodeMaterialConnectionPoint {
  52. return this._outputs[0];
  53. }
  54. /**
  55. * Initialize the block and prepare the context for build
  56. * @param state defines the state that will be used for the build
  57. */
  58. public initialize(state: NodeMaterialBuildState) {
  59. state._excludeVariableName("sourceAlpha");
  60. }
  61. protected _buildBlock(state: NodeMaterialBuildState) {
  62. super._buildBlock(state);
  63. if (state.target === NodeMaterialBlockTargets.Vertex) {
  64. return;
  65. }
  66. state.compilationString += `
  67. #ifdef BLENDMULTIPLYMODE
  68. ${this._declareOutput(this.blendColor, state)};
  69. float sourceAlpha = ${this.alphaColor.associatedVariableName} * ${this.alphaTexture.associatedVariableName};
  70. ${this.blendColor.associatedVariableName}.rgb = ${this.color.associatedVariableName}.rgb * sourceAlpha + vec3(1.0) * (1.0 - sourceAlpha);
  71. ${this.blendColor.associatedVariableName}.a = ${this.color.associatedVariableName}.a;
  72. #else
  73. ${this._declareOutput(this.blendColor, state)} = ${this.color.associatedVariableName};
  74. #endif
  75. `;
  76. return this;
  77. }
  78. }
  79. _TypeStore.RegisteredTypes["BABYLON.ParticleBlendMultiplyBlock"] = ParticleBlendMultiplyBlock;