postprocessConvolution.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var CreateConvolutionTestScene = function (engine) {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, 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(-40, 40, 0));
  11. // Skybox
  12. var skybox = BABYLON.Mesh.CreateBox("skyBox", 500.0, scene);
  13. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  14. skyboxMaterial.backFaceCulling = false;
  15. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("Scenes/Customs/skybox/skybox", scene);
  16. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  17. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  18. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  19. skybox.material = skyboxMaterial;
  20. skybox.infiniteDistance = true;
  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. var cube = BABYLON.Mesh.CreateBox("Cube", 10.0, scene);
  26. sphere0.material = new BABYLON.StandardMaterial("white", scene);
  27. sphere0.material.diffuseColor = new BABYLON.Color3(0.5, 0.5, 1.0);
  28. sphere1.material = sphere0.material;
  29. sphere2.material = sphere0.material;
  30. sphere0.convertToFlatShadedMesh();
  31. sphere1.convertToFlatShadedMesh();
  32. sphere2.convertToFlatShadedMesh();
  33. cube.material = new BABYLON.StandardMaterial("red", scene);
  34. cube.material.diffuseColor = new BABYLON.Color3(1.0, 0.5, 0.5);
  35. cube.material.specularColor = new BABYLON.Color3(0, 0, 0);
  36. // Post-process
  37. var postProcess = new BABYLON.ConvolutionPostProcess("convolution", BABYLON.ConvolutionPostProcess.EmbossKernel, 1.0, camera);
  38. // Animations
  39. var alpha = 0;
  40. scene.registerBeforeRender(function() {
  41. sphere0.position = new BABYLON.Vector3(20 * Math.sin(alpha), 0, 20 * Math.cos(alpha));
  42. sphere1.position = new BABYLON.Vector3(20 * Math.sin(alpha), -20 * Math.cos(alpha), 0);
  43. sphere2.position = new BABYLON.Vector3(0, 20 * Math.cos(alpha), 20 * Math.sin(alpha));
  44. cube.rotation.y += 0.01;
  45. cube.rotation.z += 0.01;
  46. alpha += 0.05;
  47. });
  48. return scene;
  49. };