nodeMaterialBuildStateSharedData.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { NodeMaterialConnectionPoint } from './nodeMaterialBlockConnectionPoint';
  2. import { NodeMaterialBlock } from './nodeMaterialBlock';
  3. import { InputBlock } from './Blocks/Input/inputBlock';
  4. import { TextureBlock } from './Blocks/Dual/textureBlock';
  5. import { ReflectionTextureBaseBlock } from './Blocks/Dual/reflectionTextureBaseBlock';
  6. import { RefractionBlock } from './Blocks/PBR/refractionBlock';
  7. import { Scene } from '../../scene';
  8. /**
  9. * Class used to store shared data between 2 NodeMaterialBuildState
  10. */
  11. export class NodeMaterialBuildStateSharedData {
  12. /**
  13. * Gets the list of emitted varyings
  14. */
  15. public temps = new Array<string>();
  16. /**
  17. * Gets the list of emitted varyings
  18. */
  19. public varyings = new Array<string>();
  20. /**
  21. * Gets the varying declaration string
  22. */
  23. public varyingDeclaration = "";
  24. /**
  25. * Input blocks
  26. */
  27. public inputBlocks = new Array<InputBlock>();
  28. /**
  29. * Input blocks
  30. */
  31. public textureBlocks = new Array<TextureBlock | ReflectionTextureBaseBlock | RefractionBlock>();
  32. /**
  33. * Bindable blocks (Blocks that need to set data to the effect)
  34. */
  35. public bindableBlocks = new Array<NodeMaterialBlock>();
  36. /**
  37. * List of blocks that can provide a compilation fallback
  38. */
  39. public blocksWithFallbacks = new Array<NodeMaterialBlock>();
  40. /**
  41. * List of blocks that can provide a define update
  42. */
  43. public blocksWithDefines = new Array<NodeMaterialBlock>();
  44. /**
  45. * List of blocks that can provide a repeatable content
  46. */
  47. public repeatableContentBlocks = new Array<NodeMaterialBlock>();
  48. /**
  49. * List of blocks that can provide a dynamic list of uniforms
  50. */
  51. public dynamicUniformBlocks = new Array<NodeMaterialBlock>();
  52. /**
  53. * List of blocks that can block the isReady function for the material
  54. */
  55. public blockingBlocks = new Array<NodeMaterialBlock>();
  56. /**
  57. * Gets the list of animated inputs
  58. */
  59. public animatedInputs = new Array<InputBlock>();
  60. /**
  61. * Build Id used to avoid multiple recompilations
  62. */
  63. public buildId: number;
  64. /** List of emitted variables */
  65. public variableNames: { [key: string]: number } = {};
  66. /** List of emitted defines */
  67. public defineNames: { [key: string]: number } = {};
  68. /** Should emit comments? */
  69. public emitComments: boolean;
  70. /** Emit build activity */
  71. public verbose: boolean;
  72. /** Gets or sets the hosting scene */
  73. public scene: Scene;
  74. /**
  75. * Gets the compilation hints emitted at compilation time
  76. */
  77. public hints = {
  78. needWorldViewMatrix: false,
  79. needWorldViewProjectionMatrix: false,
  80. needAlphaBlending: false,
  81. needAlphaTesting: false
  82. };
  83. /**
  84. * List of compilation checks
  85. */
  86. public checks = {
  87. emitVertex: false,
  88. emitFragment: false,
  89. notConnectedNonOptionalInputs: new Array<NodeMaterialConnectionPoint>()
  90. };
  91. /** Creates a new shared data */
  92. public constructor() {
  93. // Exclude usual attributes from free variable names
  94. this.variableNames["position"] = 0;
  95. this.variableNames["normal"] = 0;
  96. this.variableNames["tangent"] = 0;
  97. this.variableNames["uv"] = 0;
  98. this.variableNames["uv2"] = 0;
  99. this.variableNames["uv3"] = 0;
  100. this.variableNames["uv4"] = 0;
  101. this.variableNames["uv4"] = 0;
  102. this.variableNames["uv5"] = 0;
  103. this.variableNames["uv6"] = 0;
  104. this.variableNames["color"] = 0;
  105. this.variableNames["matricesIndices"] = 0;
  106. this.variableNames["matricesWeights"] = 0;
  107. this.variableNames["matricesIndicesExtra"] = 0;
  108. this.variableNames["matricesWeightsExtra"] = 0;
  109. this.variableNames["diffuseBase"] = 0;
  110. this.variableNames["specularBase"] = 0;
  111. this.variableNames["worldPos"] = 0;
  112. this.variableNames["shadow"] = 0;
  113. // Exclude known varyings
  114. this.variableNames["vTBN"] = 0;
  115. // Exclude defines
  116. this.defineNames["MAINUV0"] = 0;
  117. this.defineNames["MAINUV1"] = 0;
  118. this.defineNames["MAINUV2"] = 0;
  119. this.defineNames["MAINUV3"] = 0;
  120. this.defineNames["MAINUV4"] = 0;
  121. this.defineNames["MAINUV5"] = 0;
  122. this.defineNames["MAINUV6"] = 0;
  123. this.defineNames["MAINUV7"] = 0;
  124. }
  125. /**
  126. * Emits console errors and exceptions if there is a failing check
  127. */
  128. public emitErrors() {
  129. let errorMessage = "";
  130. if (!this.checks.emitVertex) {
  131. errorMessage += "NodeMaterial does not have a vertex output. You need to at least add a block that generates a glPosition value.\r\n";
  132. }
  133. if (!this.checks.emitFragment) {
  134. errorMessage += "NodeMaterial does not have a fragment output. You need to at least add a block that generates a glFragColor value.\r\n";
  135. }
  136. for (var notConnectedInput of this.checks.notConnectedNonOptionalInputs) {
  137. errorMessage += `input ${notConnectedInput.name} from block ${notConnectedInput.ownerBlock.name}[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.\r\n`;
  138. }
  139. if (errorMessage) {
  140. throw "Build of NodeMaterial failed:\r\n" + errorMessage;
  141. }
  142. }
  143. }