addlegacypbr.js 7.3 KB

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