nodeMaterialBuildStateSharedData.ts 5.3 KB

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