postprocessRefraction.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var CreatePostProcessRefractionTestScene = function (engine) {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 100, BABYLON.Vector3.Zero(), scene);
  4. var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -1, -0.2), scene);
  5. var light2 = new BABYLON.DirectionalLight("dir02", new BABYLON.Vector3(-1, -2, -1), scene);
  6. light.position = new BABYLON.Vector3(0, 30, 0);
  7. light2.position = new BABYLON.Vector3(10, 20, 10);
  8. light.intensity = 0.6;
  9. light2.intensity = 0.6;
  10. camera.setPosition(new BABYLON.Vector3(-60, 60, 0));
  11. camera.lowerBetaLimit = (Math.PI / 2) * 0.8;
  12. // Skybox
  13. var skybox = BABYLON.Mesh.CreateBox("skyBox", 1000.0, scene);
  14. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  15. skyboxMaterial.backFaceCulling = false;
  16. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("Scenes/Customs/skybox/snow", scene);
  17. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  18. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  19. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  20. skybox.material = skyboxMaterial;
  21. // Spheres
  22. var sphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 10, scene);
  23. var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 10, scene);
  24. var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 10, scene);
  25. sphere0.material = new BABYLON.StandardMaterial("red", scene);
  26. sphere0.material.specularColor = new BABYLON.Color3(0, 0, 0);
  27. sphere0.material.diffuseColor = new BABYLON.Color3(1.0, 0, 0);
  28. sphere1.material = new BABYLON.StandardMaterial("green", scene);
  29. sphere1.material.specularColor = new BABYLON.Color3(0, 0, 0);
  30. sphere1.material.diffuseColor = new BABYLON.Color3(0, 1.0, 0);
  31. sphere2.material = new BABYLON.StandardMaterial("blue", scene);
  32. sphere2.material.specularColor = new BABYLON.Color3(0, 0, 0);
  33. sphere2.material.diffuseColor = new BABYLON.Color3(0, 0, 1.0);
  34. // Post-process
  35. var postProcess = new BABYLON.RefractionPostProcess("Refraction", "/scenes/customs/refMap.jpg", new BABYLON.Color3(1.0, 1.0, 1.0), 0.5, 0.5, 1.0, camera);
  36. // Animations
  37. var alpha = 0;
  38. scene.registerBeforeRender(function() {
  39. sphere0.position = new BABYLON.Vector3(20 * Math.sin(alpha), 0, 20 * Math.cos(alpha));
  40. sphere1.position = new BABYLON.Vector3(20 * Math.sin(alpha), 0, -20 * Math.cos(alpha));
  41. sphere2.position = new BABYLON.Vector3(20 * Math.cos(alpha), 0, 20 * Math.sin(alpha));
  42. alpha += 0.01;
  43. });
  44. return scene;
  45. };