Source: material/PBRMaterial.js

  1. import { MATERIAL_TYPE } from '../const.js';
  2. import { Material } from './Material.js';
  3. /**
  4. * A standard physically based material, using Metallic-Roughness workflow.
  5. * Physically based rendering (PBR) has recently become the standard in many 3D applications, such as Unity, Unreal and 3D Studio Max.
  6. * This approach differs from older approaches in that instead of using approximations for the way in which light interacts with a surface, a physically correct model is used.
  7. * The idea is that, instead of tweaking materials to look good under specific lighting, a material can be created that will react 'correctly' under all lighting scenarios.
  8. * @constructor
  9. * @extends zen3d.Material
  10. * @memberof zen3d
  11. */
  12. function PBRMaterial() {
  13. Material.call(this);
  14. this.type = MATERIAL_TYPE.PBR;
  15. /**
  16. * How rough the material appears. 0.0 means a smooth mirror reflection, 1.0 means fully diffuse.
  17. * If roughnessMap is also provided, both values are multiplied.
  18. * @type {number}
  19. * @default 0.5
  20. */
  21. this.roughness = 0.5;
  22. /**
  23. * How much the material is like a metal.
  24. * Non-metallic materials such as wood or stone use 0.0, metallic use 1.0, with nothing (usually) in between.
  25. * A value between 0.0 and 1.0 could be used for a rusty metal look. If metalnessMap is also provided, both values are multiplied.
  26. * @type {number}
  27. * @default 0.5
  28. */
  29. this.metalness = 0.5;
  30. /**
  31. * The green channel of this texture is used to alter the roughness of the material.
  32. * @type {zen3d.Texture2D}
  33. * @default null
  34. */
  35. this.roughnessMap = null;
  36. /**
  37. * The blue channel of this texture is used to alter the metalness of the material.
  38. * @type {zen3d.Texture2D}
  39. * @default null
  40. */
  41. this.metalnessMap = null;
  42. /**
  43. * PBR material is affected by lights.
  44. * @type {boolean}
  45. * @default true
  46. */
  47. this.acceptLight = true;
  48. }
  49. PBRMaterial.prototype = Object.assign(Object.create(Material.prototype), /** @lends zen3d.PBRMaterial.prototype */{
  50. constructor: PBRMaterial,
  51. copy: function(source) {
  52. Material.prototype.copy.call(this, source);
  53. this.roughness = source.roughness;
  54. this.metalness = source.metalness;
  55. this.roughnessMap = source.roughnessMap;
  56. this.metalnessMap = source.metalnessMap;
  57. return this;
  58. }
  59. });
  60. export { PBRMaterial };