nodeMaterialBuildStateSharedData.ts 5.5 KB

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