babylon.pbrBaseSimpleMaterial.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. module BABYLON {
  2. /**
  3. * The Physically based simple base material of BJS.
  4. *
  5. * This enables better naming and convention enforcements on top of the pbrMaterial.
  6. * It is used as the base class for both the specGloss and metalRough conventions.
  7. */
  8. export abstract class PBRBaseSimpleMaterial extends PBRBaseMaterial {
  9. /**
  10. * Number of Simultaneous lights allowed on the material.
  11. */
  12. @serialize()
  13. @expandToProperty("_markAllSubMeshesAsLightsDirty")
  14. public maxSimultaneousLights = 4;
  15. /**
  16. * If sets to true, disables all the lights affecting the material.
  17. */
  18. @serialize()
  19. @expandToProperty("_markAllSubMeshesAsLightsDirty")
  20. public disableLighting = false;
  21. /**
  22. * Environment Texture used in the material (this is use for both reflection and environment lighting).
  23. */
  24. @serializeAsTexture()
  25. @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_reflectionTexture")
  26. public environmentTexture: BaseTexture;
  27. /**
  28. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  29. */
  30. @serialize()
  31. @expandToProperty("_markAllSubMeshesAsTexturesDirty")
  32. public invertNormalMapX = false;
  33. /**
  34. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  35. */
  36. @serialize()
  37. @expandToProperty("_markAllSubMeshesAsTexturesDirty")
  38. public invertNormalMapY = false;
  39. /**
  40. * Normal map used in the model.
  41. */
  42. @serializeAsTexture()
  43. @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_bumpTexture")
  44. public normalTexture: BaseTexture;
  45. /**
  46. * Emissivie color used to self-illuminate the model.
  47. */
  48. @serializeAsColor3("emissive")
  49. @expandToProperty("_markAllSubMeshesAsTexturesDirty")
  50. public emissiveColor = new Color3(0, 0, 0);
  51. /**
  52. * Emissivie texture used to self-illuminate the model.
  53. */
  54. @serializeAsTexture()
  55. @expandToProperty("_markAllSubMeshesAsTexturesDirty")
  56. public emissiveTexture: BaseTexture;
  57. /**
  58. * Occlusion Channel Strenght.
  59. */
  60. @serialize()
  61. @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_ambientTextureStrength")
  62. public occlusionStrength: number = 1.0;
  63. /**
  64. * Occlusion Texture of the material (adding extra occlusion effects).
  65. */
  66. @serializeAsTexture()
  67. @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_ambientTexture")
  68. public occlusionTexture: BaseTexture;
  69. /**
  70. * Defines the alpha limits in alpha test mode.
  71. */
  72. @serialize()
  73. @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_alphaCutOff")
  74. public alphaCutOff: number;
  75. /**
  76. * Gets the current double sided mode.
  77. */
  78. @serialize()
  79. public get doubleSided(): boolean {
  80. return this._twoSidedLighting;
  81. }
  82. /**
  83. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  84. */
  85. public set doubleSided(value: boolean) {
  86. if (this._twoSidedLighting === value) {
  87. return;
  88. }
  89. this._twoSidedLighting = value;
  90. this.backFaceCulling = !value;
  91. this._markAllSubMeshesAsTexturesDirty();
  92. }
  93. @serializeAsTexture()
  94. @expandToProperty("_markAllSubMeshesAsTexturesDirty", null)
  95. public lightmapTexture: BaseTexture;
  96. @serialize()
  97. @expandToProperty("_markAllSubMeshesAsTexturesDirty")
  98. public useLightmapAsShadowmap = false;
  99. /**
  100. * Return the active textures of the material.
  101. */
  102. public getActiveTextures(): BaseTexture[] {
  103. var activeTextures = super.getActiveTextures();
  104. if (this.environmentTexture) {
  105. activeTextures.push(this.environmentTexture);
  106. }
  107. if (this.normalTexture) {
  108. activeTextures.push(this.normalTexture);
  109. }
  110. if (this.emissiveTexture) {
  111. activeTextures.push(this.emissiveTexture);
  112. }
  113. if (this.occlusionTexture) {
  114. activeTextures.push(this.occlusionTexture);
  115. }
  116. if (this.lightmapTexture) {
  117. activeTextures.push(this.lightmapTexture);
  118. }
  119. return activeTextures;
  120. }
  121. public hasTexture(texture: BaseTexture): boolean {
  122. if (super.hasTexture(texture)) {
  123. return true;
  124. }
  125. if (this.lightmapTexture === texture) {
  126. return true;
  127. }
  128. return false;
  129. }
  130. /**
  131. * Instantiates a new PBRMaterial instance.
  132. *
  133. * @param name The material name
  134. * @param scene The scene the material will be use in.
  135. */
  136. constructor(name: string, scene: Scene) {
  137. super(name, scene);
  138. this._useAlphaFromAlbedoTexture = true;
  139. this._useAmbientInGrayScale = true;
  140. }
  141. public getClassName(): string {
  142. return "PBRBaseSimpleMaterial";
  143. }
  144. }
  145. }