volumetric light scattering.js 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. //Adding a light
  4. var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
  5. //Adding an Arc Rotate Camera
  6. var camera = new BABYLON.ArcRotateCamera("Camera", -0.5, 2.2, 100, BABYLON.Vector3.Zero(), scene);
  7. camera.attachControl(canvas, false);
  8. // The first parameter can be used to specify which mesh to import. Here we import all meshes
  9. BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) {
  10. // Set the target of the camera to the first imported mesh
  11. camera.target = newMeshes[0];
  12. newMeshes[0].material = new BABYLON.StandardMaterial("skull", scene);
  13. newMeshes[0].material.emissiveColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  14. });
  15. // Create the "God Rays" effect (volumetric light scattering)
  16. var godrays = new BABYLON.VolumetricLightScatteringPostProcess('godrays', 1.0, camera, null, 100, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false);
  17. // By default it uses a billboard to render the sun, just apply the desired texture
  18. // position and scale
  19. godrays.mesh.material.diffuseTexture = new BABYLON.Texture('textures/sun.png', scene, true, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  20. godrays.mesh.material.diffuseTexture.hasAlpha = true;
  21. godrays.mesh.position = new BABYLON.Vector3(-150, 150, 150);
  22. godrays.mesh.scaling = new BABYLON.Vector3(350, 350, 350);
  23. light.position = godrays.mesh.position;
  24. return scene;
  25. }