nodeMaterialBuildStateSharedData.ts 5.2 KB

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