/home/lindsay/xeolabs/xeogl-next/xeogl/src/materials/fresnel.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/src/materials/fresnel.js

  1. /**
  2. A **Fresnel** specifies a Fresnel effect for attached {{#crossLink "PhongMaterial"}}PhongMaterials{{/crossLink}}.
  3.  
  4. <a href="../../examples/#materials_phong_fresnel"><img src="../../assets/images/screenshots/PhongMaterial/fresnelWide.png"></img></a>
  5.  
  6. ## Overview
  7.  
  8. * Fresnels are grouped within {{#crossLink "PhongMaterial"}}{{/crossLink}}s, which are attached to
  9. {{#crossLink "Mesh"}}Meshes{{/crossLink}}.
  10.  
  11. ## Examples
  12.  
  13. * [PhongMaterials with Fresnels](../../examples/#materials_phong_fresnel)
  14.  
  15. ## Usage
  16.  
  17. ````javascript
  18. var mesh = new xeogl.Mesh({
  19.  
  20. material: new xeogl.PhongMaterial({
  21. ambient: [0.3, 0.3, 0.3],
  22. shininess: 30,
  23.  
  24. diffuseFresnel: new xeogl.Fresnel({
  25. edgeColor: [1.0, 1.0, 1.0],
  26. centerColor: [0.0, 0.0, 0.0],
  27. power: 4,
  28. bias: 0.6
  29. }),
  30.  
  31. specularFresnel: new xeogl.Fresnel({
  32. edgeColor: [1.0, 1.0, 1.0],
  33. centerColor: [0.0, 0.0, 0.0],
  34. power: 4,
  35. bias: 0.2
  36. })
  37. }),
  38.  
  39. new xeogl.TorusGeometry()
  40. });
  41. ````
  42.  
  43. @class Fresnel
  44. @module xeogl
  45. @submodule materials
  46. @constructor
  47. @param [owner] {Component} Owner component. When destroyed, the owner will destroy this component as well. Creates this component within the default {{#crossLink "Scene"}}{{/crossLink}} when omitted.
  48. @param [cfg] {*} Configs
  49. @param [cfg.id] {String} Optional ID, unique among all components in the parent scene, generated automatically when omitted.
  50. @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this Fresnel.
  51. @param [cfg.edgeColor=[ 0.0, 0.0, 0.0 ]] {Array of Number} Color used on edges.
  52. @param [cfg.centerColor=[ 1.0, 1.0, 1.0 ]] {Array of Number} Color used on center.
  53. @param [cfg.edgeBias=0] {Number} Bias at the edge.
  54. @param [cfg.centerBias=1] {Number} Bias at the center.
  55. @param [cfg.power=0] {Number} The power.
  56. @extends Component
  57. */
  58.  
  59. import {Component} from '../component.js';
  60. import {State} from '../renderer/state.js';
  61. import {math} from '../math/math.js';
  62. import {componentClasses} from "./../componentClasses.js";
  63.  
  64. const type = "xeogl.Fresnel";
  65.  
  66. class Fresnel extends Component {
  67.  
  68. /**
  69. JavaScript class name for this Component.
  70.  
  71. For example: "xeogl.AmbientLight", "xeogl.MetallicMaterial" etc.
  72.  
  73. @property type
  74. @type String
  75. @final
  76. */
  77. get type() {
  78. return type;
  79. }
  80.  
  81. init(cfg) {
  82.  
  83. super.init(cfg);
  84.  
  85. this._state = new State({
  86. edgeColor: math.vec3([0, 0, 0]),
  87. centerColor: math.vec3([1, 1, 1]),
  88. edgeBias: 0,
  89. centerBias: 1,
  90. power: 1
  91. });
  92.  
  93. this.edgeColor = cfg.edgeColor;
  94. this.centerColor = cfg.centerColor;
  95. this.edgeBias = cfg.edgeBias;
  96. this.centerBias = cfg.centerBias;
  97. this.power = cfg.power;
  98. }
  99.  
  100. /**
  101. This Fresnel's edge color.
  102.  
  103. @property edgeColor
  104. @default [0.0, 0.0, 0.0]
  105. @type Float32Array
  106. */
  107. set edgeColor(value) {
  108. this._state.edgeColor.set(value || [0.0, 0.0, 0.0]);
  109. this._renderer.imageDirty();
  110. }
  111.  
  112. get edgeColor() {
  113. return this._state.edgeColor;
  114. }
  115.  
  116. /**
  117. This Fresnel's center color.
  118.  
  119. @property centerColor
  120. @default [1.0, 1.0, 1.0]
  121. @type Float32Array
  122. */
  123. set centerColor(value) {
  124. this._state.centerColor.set(value || [1.0, 1.0, 1.0]);
  125. this._renderer.imageDirty();
  126. }
  127.  
  128. get centerColor() {
  129. return this._state.centerColor;
  130. }
  131.  
  132. /**
  133. * Indicates this Fresnel's edge bias.
  134. *
  135. * @property edgeBias
  136. * @default 0
  137. * @type Number
  138. */
  139. set edgeBias(value) {
  140. this._state.edgeBias = value || 0;
  141. this._renderer.imageDirty();
  142. }
  143.  
  144. get edgeBias() {
  145. return this._state.edgeBias;
  146. }
  147.  
  148. /**
  149. * Indicates this Fresnel's center bias.
  150. *
  151. * @property centerBias
  152. * @default 1
  153. * @type Number
  154. */
  155. set centerBias(value) {
  156. this._state.centerBias = (value !== undefined && value !== null) ? value : 1;
  157. this._renderer.imageDirty();
  158. }
  159.  
  160. get centerBias() {
  161. return this._state.centerBias;
  162. }
  163.  
  164. /**
  165. * Indicates this Fresnel's power.
  166. *
  167. * @property power
  168. * @default 1
  169. * @type Number
  170. */
  171. set power(value) {
  172. this._state.power = (value !== undefined && value !== null) ? value : 1;
  173. this._renderer.imageDirty();
  174. }
  175.  
  176. get power() {
  177. return this._state.power;
  178. }
  179.  
  180. destroy() {
  181. super.destroy();
  182. this._state.destroy();
  183. }
  184. }
  185.  
  186. componentClasses[type] = Fresnel;
  187.  
  188. export{Fresnel};