addpbr.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. window.preparePBR = function() {
  2. var pbr = new BABYLON.PBRMaterial("pbr", scene);
  3. pbr.albedoTexture = new BABYLON.Texture("textures/amiga.jpg", scene);
  4. pbr.albedoTexture.uScale = 5;
  5. pbr.albedoTexture.vScale = 5;
  6. var hdrTexture = new BABYLON.HDRCubeTexture("textures/hdr/environment.hdr", scene, 512);
  7. pbr.reflectionTexture = hdrTexture;
  8. pbr.refractionTexture = hdrTexture;
  9. pbr.linkRefractionWithTransparency = true;
  10. pbr.indexOfRefraction = 0.52;
  11. pbr.reflectivityColor = new BABYLON.Color3(0.3, 0.3, 0.3);
  12. pbr.microSurface = 0.9;
  13. // Skybox
  14. var hdrSkybox = BABYLON.Mesh.CreateBox("hdrSkyBox", 1000.0, scene);
  15. var hdrSkyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  16. hdrSkyboxMaterial.backFaceCulling = false;
  17. hdrSkyboxMaterial.reflectionTexture = hdrTexture.clone();
  18. hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  19. hdrSkyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  20. hdrSkyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  21. hdrSkyboxMaterial.disableLighting = true;
  22. hdrSkybox.material = hdrSkyboxMaterial;
  23. hdrSkybox.infiniteDistance = true;
  24. hdrSkybox.setEnabled(false);
  25. registerButtonUI("pbr", "Default", function() {
  26. setRangeValues({
  27. "directIntensity": 1,
  28. "emissiveIntensity": 1,
  29. "environmentIntensity": 1,
  30. "specularIntensity": 1,
  31. "ShadowIntensity": 1,
  32. "ShadeIntensity": 1,
  33. "cameraExposure": 1,
  34. "cameraContrast": 1,
  35. "microSurface": 0.9,
  36. "reflectivityColorR": 0.3,
  37. "reflectivityColorG": 0.3,
  38. "reflectivityColorB": 0.3,
  39. "albedoColorR": 1,
  40. "albedoColorG": 1,
  41. "albedoColorB": 1,
  42. "albedoColorLevel": 0
  43. });
  44. });
  45. registerButtonUI("pbr", "Env Irradiance No Lighting", function() {
  46. setRangeValues({
  47. "directIntensity": 0,
  48. "emissiveIntensity": 1,
  49. "environmentIntensity": 1,
  50. "specularIntensity": 1,
  51. "ShadowIntensity": 1,
  52. "ShadeIntensity": 1,
  53. "cameraExposure": 1,
  54. "cameraContrast": 1,
  55. "microSurface": 0,
  56. "reflectivityColorR": 0,
  57. "reflectivityColorG": 0,
  58. "reflectivityColorB": 0,
  59. "albedoColorR": 1,
  60. "albedoColorG": 1,
  61. "albedoColorB": 1,
  62. "albedoColorLevel": 1
  63. });
  64. hdrSkybox.setEnabled(true);
  65. });
  66. registerButtonUI("pbr", "Rough Gold", function() {
  67. setRangeValues({
  68. "directIntensity": 1.3439461727881254,
  69. "emissiveIntensity": 1,
  70. "environmentIntensity": 0.3685013699580344,
  71. "specularIntensity": 1,
  72. "ShadowIntensity": 1,
  73. "ShadeIntensity": 1,
  74. "cameraExposure": 0.7153261887420668,
  75. "cameraContrast": 1.6474178892241538,
  76. "microSurface": 0.42269274789303946,
  77. "reflectivityColorR": 1,
  78. "reflectivityColorG": 0.8453854957860789,
  79. "reflectivityColorB": 0.5093989525890475,
  80. "albedoColorR": 0,
  81. "albedoColorG": 0,
  82. "albedoColorB": 0,
  83. "albedoColorLevel": 1
  84. });
  85. });
  86. registerButtonUI("pbr", "Plastic", function() {
  87. setRangeValues({
  88. "directIntensity": 0.9971213540040931,
  89. "emissiveIntensity": 1,
  90. "environmentIntensity": 0.3685013699580344,
  91. "specularIntensity": 1,
  92. "ShadowIntensity": 0.975444802830091,
  93. "ShadeIntensity": 0.8020323934380749,
  94. "cameraExposure": 0.7586792910900708,
  95. "cameraContrast": 1.5823882357021477,
  96. "microSurface": 0.8562237713730799,
  97. "reflectivityColorR": 0.05,
  98. "reflectivityColorG": 0.05,
  99. "reflectivityColorB": 0.05,
  100. "albedoColorR": 0.20592723615301922,
  101. "albedoColorG": 0.942929976069088,
  102. "albedoColorB": 1,
  103. "albedoColorLevel": 1
  104. });
  105. });
  106. registerRangeUI("pbr", "indiceOfRefraction", 0, 2, function(value) {
  107. pbr.indexOfRefraction = value;
  108. }, function() {
  109. return pbr.indexOfRefraction;
  110. });
  111. registerRangeUI("pbr", "alpha", 0, 1, function(value) {
  112. pbr.alpha = value;
  113. }, function() {
  114. return pbr.alpha;
  115. });
  116. registerRangeUI("pbr", "directIntensity", 0, 2, function(value) {
  117. pbr.directIntensity = value;
  118. }, function() {
  119. return pbr.directIntensity;
  120. });
  121. registerRangeUI("pbr", "emissiveIntensity", 0, 2, function(value) {
  122. pbr.emissiveIntensity = value;
  123. }, function() {
  124. return pbr.emissiveIntensity;
  125. });
  126. registerRangeUI("pbr", "environmentIntensity", 0, 2, function(value) {
  127. pbr.environmentIntensity = value;
  128. }, function() {
  129. return pbr.environmentIntensity;
  130. });
  131. registerRangeUI("pbr", "specularIntensity", 0, 2, function(value) {
  132. pbr.specularIntensity = value;
  133. }, function() {
  134. return pbr.specularIntensity;
  135. });
  136. registerRangeUI("pbr", "ShadowIntensity", 0, 2, function(value) {
  137. pbr.overloadedShadowIntensity = value;
  138. }, function() {
  139. return pbr.overloadedShadowIntensity;
  140. });
  141. registerRangeUI("pbr", "ShadeIntensity", 0, 2, function(value) {
  142. pbr.overloadedShadeIntensity = value;
  143. }, function() {
  144. return pbr.overloadedShadeIntensity;
  145. });
  146. registerRangeUI("pbr", "cameraExposure", 0, 2, function(value) {
  147. pbr.cameraExposure = value;
  148. }, function() {
  149. return pbr.cameraExposure;
  150. });
  151. registerRangeUI("pbr", "cameraContrast", 0, 2, function(value) {
  152. pbr.cameraContrast = value;
  153. }, function() {
  154. return pbr.cameraContrast;
  155. });
  156. registerRangeUI("pbr", "microSurface", 0, 1, function(value) {
  157. pbr.microSurface = value;
  158. }, function() {
  159. return pbr.microSurface;
  160. });
  161. registerRangeUI("pbr", "reflectivityColorR", 0, 1, function(value) {
  162. pbr.reflectivityColor.r = value;
  163. }, function() {
  164. return pbr.reflectivityColor.r;
  165. });
  166. registerRangeUI("pbr", "reflectivityColorG", 0, 1, function(value) {
  167. pbr.reflectivityColor.g = value;
  168. }, function() {
  169. return pbr.reflectivityColor.g;
  170. });
  171. registerRangeUI("pbr", "reflectivityColorB", 0, 1, function(value) {
  172. pbr.reflectivityColor.b = value;
  173. }, function() {
  174. return pbr.reflectivityColor.b;
  175. });
  176. registerRangeUI("pbr", "albedoColorR", 0, 1, function(value) {
  177. pbr.overloadedAlbedo.r = value;
  178. }, function() {
  179. return pbr.overloadedAlbedo.r;
  180. });
  181. registerRangeUI("pbr", "albedoColorG", 0, 1, function(value) {
  182. pbr.overloadedAlbedo.g = value;
  183. }, function() {
  184. return pbr.overloadedAlbedo.g;
  185. });
  186. registerRangeUI("pbr", "albedoColorB", 0, 1, function(value) {
  187. pbr.overloadedAlbedo.b = value;
  188. }, function() {
  189. return pbr.overloadedAlbedo.b;
  190. });
  191. registerRangeUI("pbr", "albedoColorLevel", 0, 1, function(value) {
  192. pbr.overloadedAlbedoIntensity = value;
  193. }, function() {
  194. return pbr.overloadedAlbedoIntensity;
  195. });
  196. registerButtonUI("pbr", "Toggle Skybox", function() {
  197. hdrSkybox.setEnabled(!hdrSkybox.isEnabled());
  198. });
  199. return pbr;
  200. }