pbr.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI / 4, Math.PI / 2.5, 200, BABYLON.Vector3.Zero(), scene);
  4. camera.attachControl(canvas, true);
  5. camera.minZ = 0.1;
  6. // Light
  7. new BABYLON.PointLight("point", new BABYLON.Vector3(20, 20, 10), scene);
  8. // Environment Texture
  9. var hdrTexture = new BABYLON.HDRCubeTexture("textures/room.hdr", scene, 512);
  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. // Create meshes
  22. var sphereGlass = BABYLON.Mesh.CreateSphere("sphere", 48, 30.0, scene);
  23. sphereGlass.translate(new BABYLON.Vector3(1, 0, 0), -50);
  24. var sphereMetal = BABYLON.Mesh.CreateSphere("sphere", 48, 30.0, scene);
  25. sphereMetal.translate(new BABYLON.Vector3(1, 0, 0), 50);
  26. var woodPlank = BABYLON.MeshBuilder.CreateBox("plane", { width: 45, height: 1, depth: 90 }, scene);
  27. // Create materials
  28. var glass = new BABYLON.PBRMaterial("glass", scene);
  29. glass.reflectionTexture = hdrTexture;
  30. glass.refractionTexture = hdrTexture;
  31. glass.linkRefractionWithTransparency = true;
  32. glass.indexOfRefraction = 0.52;
  33. glass.alpha = 0;
  34. glass.directIntensity = 0.0;
  35. glass.environmentIntensity = 0.5;
  36. glass.cameraExposure = 0.5;
  37. glass.cameraContrast = 1.7;
  38. glass.microSurface = 1;
  39. glass.reflectivityColor = new BABYLON.Color3(0.1, 0.1, 0.1);
  40. glass.albedoColor = new BABYLON.Color3(0.3, 0.3, 0.3);
  41. sphereGlass.material = glass;
  42. var metal = new BABYLON.PBRMaterial("metal", scene);
  43. metal.reflectionTexture = hdrTexture;
  44. metal.directIntensity = 0.3;
  45. metal.environmentIntensity = 0.7;
  46. metal.cameraExposure = 0.6;
  47. metal.cameraContrast = 1.6;
  48. metal.microSurface = 0.96;
  49. metal.reflectivityColor = new BABYLON.Color3(0.9, 0.9, 0.9);
  50. metal.albedoColor = new BABYLON.Color3(1, 1, 1);
  51. sphereMetal.material = metal;
  52. var wood = new BABYLON.PBRMaterial("wood", scene);
  53. wood.reflectionTexture = hdrTexture;
  54. wood.directIntensity = 1.5;
  55. wood.environmentIntensity = 0.5;
  56. wood.specularIntensity = 0.3;
  57. wood.cameraExposure = 0.9;
  58. wood.cameraContrast = 1.6;
  59. wood.reflectivityTexture = new BABYLON.Texture("textures/reflectivity.png", scene);
  60. wood.useMicroSurfaceFromReflectivityMapAlpha = true;
  61. wood.albedoColor = BABYLON.Color3.White();
  62. wood.albedoTexture = new BABYLON.Texture("textures/albedo.png", scene);
  63. woodPlank.material = wood;
  64. return scene;
  65. };