pbrSubSurfaceConfiguration.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import type { Nullable } from "../../types";
  2. import type { IAnimatable } from "../../Animations/animatable.interface";
  3. import { Color3 } from "../../Maths/math.color";
  4. import type { SmartArray } from "../../Misc/smartArray";
  5. import type { BaseTexture } from "../../Materials/Textures/baseTexture";
  6. import type { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture";
  7. import type { UniformBuffer } from "../../Materials/uniformBuffer";
  8. import type { EffectFallbacks } from "../effectFallbacks";
  9. import type { SubMesh } from "../../Meshes/subMesh";
  10. import { MaterialPluginBase } from "../materialPluginBase";
  11. import { MaterialDefines } from "../materialDefines";
  12. import type { Engine } from "../../Engines/engine";
  13. import type { Scene } from "../../scene";
  14. import type { PBRBaseMaterial } from "./pbrBaseMaterial";
  15. /**
  16. * @internal
  17. */
  18. export declare class MaterialSubSurfaceDefines extends MaterialDefines {
  19. SUBSURFACE: boolean;
  20. SS_REFRACTION: boolean;
  21. SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS: boolean;
  22. SS_TRANSLUCENCY: boolean;
  23. SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS: boolean;
  24. SS_SCATTERING: boolean;
  25. SS_DISPERSION: boolean;
  26. SS_THICKNESSANDMASK_TEXTURE: boolean;
  27. SS_THICKNESSANDMASK_TEXTUREDIRECTUV: number;
  28. SS_HAS_THICKNESS: boolean;
  29. SS_REFRACTIONINTENSITY_TEXTURE: boolean;
  30. SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV: number;
  31. SS_TRANSLUCENCYINTENSITY_TEXTURE: boolean;
  32. SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV: number;
  33. SS_REFRACTIONMAP_3D: boolean;
  34. SS_REFRACTIONMAP_OPPOSITEZ: boolean;
  35. SS_LODINREFRACTIONALPHA: boolean;
  36. SS_GAMMAREFRACTION: boolean;
  37. SS_RGBDREFRACTION: boolean;
  38. SS_LINEARSPECULARREFRACTION: boolean;
  39. SS_LINKREFRACTIONTOTRANSPARENCY: boolean;
  40. SS_ALBEDOFORREFRACTIONTINT: boolean;
  41. SS_ALBEDOFORTRANSLUCENCYTINT: boolean;
  42. SS_USE_LOCAL_REFRACTIONMAP_CUBIC: boolean;
  43. SS_USE_THICKNESS_AS_DEPTH: boolean;
  44. SS_USE_GLTF_TEXTURES: boolean;
  45. }
  46. /**
  47. * Plugin that implements the sub surface component of the PBR material
  48. */
  49. export declare class PBRSubSurfaceConfiguration extends MaterialPluginBase {
  50. protected _material: PBRBaseMaterial;
  51. private _isRefractionEnabled;
  52. /**
  53. * Defines if the refraction is enabled in the material.
  54. */
  55. isRefractionEnabled: boolean;
  56. private _isTranslucencyEnabled;
  57. /**
  58. * Defines if the translucency is enabled in the material.
  59. */
  60. isTranslucencyEnabled: boolean;
  61. private _isDispersionEnabled;
  62. /**
  63. * Defines if dispersion is enabled in the material.
  64. */
  65. isDispersionEnabled: boolean;
  66. private _isScatteringEnabled;
  67. /**
  68. * Defines if the sub surface scattering is enabled in the material.
  69. */
  70. isScatteringEnabled: boolean;
  71. private _scatteringDiffusionProfileIndex;
  72. /**
  73. * Diffusion profile for subsurface scattering.
  74. * Useful for better scattering in the skins or foliages.
  75. */
  76. get scatteringDiffusionProfile(): Nullable<Color3>;
  77. set scatteringDiffusionProfile(c: Nullable<Color3>);
  78. /**
  79. * Defines the refraction intensity of the material.
  80. * The refraction when enabled replaces the Diffuse part of the material.
  81. * The intensity helps transitioning between diffuse and refraction.
  82. */
  83. refractionIntensity: number;
  84. /**
  85. * Defines the translucency intensity of the material.
  86. * When translucency has been enabled, this defines how much of the "translucency"
  87. * is added to the diffuse part of the material.
  88. */
  89. translucencyIntensity: number;
  90. /**
  91. * When enabled, transparent surfaces will be tinted with the albedo colour (independent of thickness)
  92. */
  93. useAlbedoToTintRefraction: boolean;
  94. /**
  95. * When enabled, translucent surfaces will be tinted with the albedo colour (independent of thickness)
  96. */
  97. useAlbedoToTintTranslucency: boolean;
  98. private _thicknessTexture;
  99. /**
  100. * Stores the average thickness of a mesh in a texture (The texture is holding the values linearly).
  101. * The red (or green if useGltfStyleTextures=true) channel of the texture should contain the thickness remapped between 0 and 1.
  102. * 0 would mean minimumThickness
  103. * 1 would mean maximumThickness
  104. * The other channels might be use as a mask to vary the different effects intensity.
  105. */
  106. thicknessTexture: Nullable<BaseTexture>;
  107. private _refractionTexture;
  108. /**
  109. * Defines the texture to use for refraction.
  110. */
  111. refractionTexture: Nullable<BaseTexture>;
  112. /** @internal */
  113. _indexOfRefraction: number;
  114. /**
  115. * Index of refraction of the material base layer.
  116. * https://en.wikipedia.org/wiki/List_of_refractive_indices
  117. *
  118. * This does not only impact refraction but also the Base F0 of Dielectric Materials.
  119. *
  120. * From dielectric fresnel rules: F0 = square((iorT - iorI) / (iorT + iorI))
  121. */
  122. indexOfRefraction: number;
  123. private _volumeIndexOfRefraction;
  124. /**
  125. * Index of refraction of the material's volume.
  126. * https://en.wikipedia.org/wiki/List_of_refractive_indices
  127. *
  128. * This ONLY impacts refraction. If not provided or given a non-valid value,
  129. * the volume will use the same IOR as the surface.
  130. */
  131. get volumeIndexOfRefraction(): number;
  132. set volumeIndexOfRefraction(value: number);
  133. private _invertRefractionY;
  134. /**
  135. * Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.
  136. */
  137. invertRefractionY: boolean;
  138. /** @internal */
  139. _linkRefractionWithTransparency: boolean;
  140. /**
  141. * This parameters will make the material used its opacity to control how much it is refracting against not.
  142. * Materials half opaque for instance using refraction could benefit from this control.
  143. */
  144. linkRefractionWithTransparency: boolean;
  145. /**
  146. * Defines the minimum thickness stored in the thickness map.
  147. * If no thickness map is defined, this value will be used to simulate thickness.
  148. */
  149. minimumThickness: number;
  150. /**
  151. * Defines the maximum thickness stored in the thickness map.
  152. */
  153. maximumThickness: number;
  154. /**
  155. * Defines that the thickness should be used as a measure of the depth volume.
  156. */
  157. useThicknessAsDepth: boolean;
  158. /**
  159. * Defines the volume tint of the material.
  160. * This is used for both translucency and scattering.
  161. */
  162. tintColor: Color3;
  163. /**
  164. * Defines the distance at which the tint color should be found in the media.
  165. * This is used for refraction only.
  166. */
  167. tintColorAtDistance: number;
  168. /**
  169. * Defines the Abbe number for the volume.
  170. */
  171. dispersion: number;
  172. /**
  173. * Defines how far each channel transmit through the media.
  174. * It is defined as a color to simplify it selection.
  175. */
  176. diffusionDistance: Color3;
  177. private _useMaskFromThicknessTexture;
  178. /**
  179. * Stores the intensity of the different subsurface effects in the thickness texture.
  180. * Note that if refractionIntensityTexture and/or translucencyIntensityTexture is provided it takes precedence over thicknessTexture + useMaskFromThicknessTexture
  181. * * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.
  182. * * the blue channel is the translucency intensity.
  183. */
  184. useMaskFromThicknessTexture: boolean;
  185. private _refractionIntensityTexture;
  186. /**
  187. * Stores the intensity of the refraction. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture
  188. * * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.
  189. */
  190. refractionIntensityTexture: Nullable<BaseTexture>;
  191. private _translucencyIntensityTexture;
  192. /**
  193. * Stores the intensity of the translucency. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture
  194. * * the blue channel is the translucency intensity.
  195. */
  196. translucencyIntensityTexture: Nullable<BaseTexture>;
  197. private _scene;
  198. private _useGltfStyleTextures;
  199. /**
  200. * Use channels layout used by glTF:
  201. * * thicknessTexture: the green (instead of red) channel is the thickness
  202. * * thicknessTexture/refractionIntensityTexture: the red (instead of green) channel is the refraction intensity
  203. * * thicknessTexture/translucencyIntensityTexture: no change, use the blue channel for the translucency intensity
  204. */
  205. useGltfStyleTextures: boolean;
  206. /** @internal */
  207. private _internalMarkAllSubMeshesAsTexturesDirty;
  208. private _internalMarkScenePrePassDirty;
  209. /** @internal */
  210. _markAllSubMeshesAsTexturesDirty(): void;
  211. /** @internal */
  212. _markScenePrePassDirty(): void;
  213. constructor(material: PBRBaseMaterial, addToPluginList?: boolean);
  214. isReadyForSubMesh(defines: MaterialSubSurfaceDefines, scene: Scene): boolean;
  215. prepareDefinesBeforeAttributes(defines: MaterialSubSurfaceDefines, scene: Scene): void;
  216. /**
  217. * Binds the material data (this function is called even if mustRebind() returns false)
  218. * @param uniformBuffer defines the Uniform buffer to fill in.
  219. * @param scene defines the scene the material belongs to.
  220. * @param engine defines the engine the material belongs to.
  221. * @param subMesh the submesh to bind data for
  222. */
  223. hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void;
  224. bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void;
  225. /**
  226. * Returns the texture used for refraction or null if none is used.
  227. * @param scene defines the scene the material belongs to.
  228. * @returns - Refraction texture if present. If no refraction texture and refraction
  229. * is linked with transparency, returns environment texture. Otherwise, returns null.
  230. */
  231. private _getRefractionTexture;
  232. /**
  233. * Returns true if alpha blending should be disabled.
  234. */
  235. get disableAlphaBlending(): boolean;
  236. /**
  237. * Fills the list of render target textures.
  238. * @param renderTargets the list of render targets to update
  239. */
  240. fillRenderTargetTextures(renderTargets: SmartArray<RenderTargetTexture>): void;
  241. hasTexture(texture: BaseTexture): boolean;
  242. hasRenderTargetTextures(): boolean;
  243. getActiveTextures(activeTextures: BaseTexture[]): void;
  244. getAnimatables(animatables: IAnimatable[]): void;
  245. dispose(forceDisposeTextures?: boolean): void;
  246. getClassName(): string;
  247. addFallbacks(defines: MaterialSubSurfaceDefines, fallbacks: EffectFallbacks, currentRank: number): number;
  248. getSamplers(samplers: string[]): void;
  249. getUniforms(): {
  250. ubo?: Array<{
  251. name: string;
  252. size: number;
  253. type: string;
  254. }>;
  255. vertex?: string;
  256. fragment?: string;
  257. };
  258. }