fresnel.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
  4. var material = new BABYLON.StandardMaterial("kosh", scene);
  5. var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 32, 3, scene);
  6. var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 32, 3, scene);
  7. var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 32, 3, scene);
  8. var sphere4 = BABYLON.Mesh.CreateSphere("Sphere4", 32, 3, scene);
  9. var sphere5 = BABYLON.Mesh.CreateSphere("Sphere5", 32, 3, scene);
  10. var light = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(-17.6, 18.8, -49.9), scene);
  11. camera.setPosition(new BABYLON.Vector3(-15, 3, 0));
  12. camera.attachControl(canvas, true);
  13. sphere2.position.z -= 5;
  14. sphere3.position.z += 5;
  15. sphere4.position.x += 5;
  16. sphere5.position.x -= 5;
  17. // Sphere1 material
  18. material.reflectionTexture = new BABYLON.CubeTexture("textures/TropicalSunnyDay", scene);
  19. material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  20. material.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  21. material.alpha = 0.2;
  22. material.specularPower = 16;
  23. // Fresnel
  24. material.reflectionFresnelParameters = new BABYLON.FresnelParameters();
  25. material.reflectionFresnelParameters.bias = 0.1;
  26. material.emissiveFresnelParameters = new BABYLON.FresnelParameters();
  27. material.emissiveFresnelParameters.bias = 0.6;
  28. material.emissiveFresnelParameters.power = 4;
  29. material.emissiveFresnelParameters.leftColor = BABYLON.Color3.White();
  30. material.emissiveFresnelParameters.rightColor = BABYLON.Color3.Black();
  31. material.opacityFresnelParameters = new BABYLON.FresnelParameters();
  32. material.opacityFresnelParameters.leftColor = BABYLON.Color3.White();
  33. material.opacityFresnelParameters.rightColor = BABYLON.Color3.Black();
  34. sphere1.material = material;
  35. // Sphere2 material
  36. material = new BABYLON.StandardMaterial("kosh2", scene);
  37. material.reflectionTexture = new BABYLON.CubeTexture("textures/TropicalSunnyDay", scene);
  38. material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  39. material.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  40. material.specularPower = 32;
  41. // Fresnel
  42. material.reflectionFresnelParameters = new BABYLON.FresnelParameters();
  43. material.reflectionFresnelParameters.bias = 0.1;
  44. material.emissiveFresnelParameters = new BABYLON.FresnelParameters();
  45. material.emissiveFresnelParameters.bias = 0.5;
  46. material.emissiveFresnelParameters.power = 4;
  47. material.emissiveFresnelParameters.leftColor = BABYLON.Color3.White();
  48. material.emissiveFresnelParameters.rightColor = BABYLON.Color3.Black();
  49. sphere2.material = material;
  50. // Sphere3 material
  51. material = new BABYLON.StandardMaterial("kosh3", scene);
  52. material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  53. material.emissiveColor = BABYLON.Color3.White();
  54. material.specularPower = 64;
  55. material.alpha = 0.2;
  56. // Fresnel
  57. material.emissiveFresnelParameters = new BABYLON.FresnelParameters();
  58. material.emissiveFresnelParameters.bias = 0.2;
  59. material.emissiveFresnelParameters.leftColor = BABYLON.Color3.White();
  60. material.emissiveFresnelParameters.rightColor = BABYLON.Color3.Black();
  61. material.opacityFresnelParameters = new BABYLON.FresnelParameters();
  62. material.opacityFresnelParameters.power = 4;
  63. material.opacityFresnelParameters.leftColor = BABYLON.Color3.White();
  64. material.opacityFresnelParameters.rightColor = BABYLON.Color3.Black();
  65. sphere3.material = material;
  66. // Sphere4 material
  67. material = new BABYLON.StandardMaterial("kosh4", scene);
  68. material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  69. material.emissiveColor = BABYLON.Color3.White();
  70. material.specularPower = 64;
  71. // Fresnel
  72. material.emissiveFresnelParameters = new BABYLON.FresnelParameters();
  73. material.emissiveFresnelParameters.power = 4;
  74. material.emissiveFresnelParameters.bias = 0.5;
  75. material.emissiveFresnelParameters.leftColor = BABYLON.Color3.White();
  76. material.emissiveFresnelParameters.rightColor = BABYLON.Color3.Black();
  77. sphere4.material = material;
  78. // Sphere5 material
  79. material = new BABYLON.StandardMaterial("kosh5", scene);
  80. material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  81. material.reflectionTexture = new BABYLON.CubeTexture("textures/TropicalSunnyDay", scene);
  82. material.reflectionTexture.level = 0.5;
  83. material.specularPower = 64;
  84. material.emissiveColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  85. // Fresnel
  86. material.emissiveFresnelParameters = new BABYLON.FresnelParameters();
  87. material.emissiveFresnelParameters.bias = 0.4;
  88. material.emissiveFresnelParameters.power = 2;
  89. material.emissiveFresnelParameters.leftColor = BABYLON.Color3.Black();
  90. material.emissiveFresnelParameters.rightColor = BABYLON.Color3.White();
  91. sphere5.material = material;
  92. // Skybox
  93. var skybox = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
  94. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  95. skyboxMaterial.backFaceCulling = false;
  96. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/TropicalSunnyDay", scene);
  97. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  98. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  99. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  100. skyboxMaterial.disableLighting = true;
  101. skybox.material = skyboxMaterial;
  102. return scene;
  103. }