addpbr.js 6.5 KB

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