addpbr.js 6.0 KB

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