nodeMaterialBuildStateSharedData.ts 5.7 KB

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