index.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Shaders Library</title>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
  6. <script src="../tools/DevLoader/BabylonLoader.js"></script>
  7. <style>
  8. html,
  9. body {
  10. width: 100%;
  11. height: 100%;
  12. padding: 0;
  13. margin: 0;
  14. overflow: hidden;
  15. }
  16. #renderCanvas {
  17. width: 100%;
  18. height: 100%;
  19. }
  20. #fps {
  21. position: absolute;
  22. background-color: black;
  23. border: 2px solid red;
  24. text-align: center;
  25. font-size: 16px;
  26. color: white;
  27. top: 15px;
  28. left: 10px;
  29. width: 60px;
  30. height: 20px;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div id="fps">0</div>
  36. <canvas id="renderCanvas"></canvas>
  37. <script>
  38. BABYLONDEVTOOLS.Loader.load(function() {
  39. if (BABYLON.Engine.isSupported()) {
  40. var canvas = document.getElementById("renderCanvas");
  41. var engine = new BABYLON.Engine(canvas, true);
  42. BABYLONDEVTOOLS.Loader.debugShortcut(engine);
  43. var divFps = document.getElementById("fps");
  44. var scene = new BABYLON.Scene(engine);
  45. var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 6, 50, BABYLON.Vector3.Zero(), scene);
  46. camera.attachControl(canvas, true);
  47. camera.minZ = 0.1;
  48. // Lights
  49. var hemisphericLight = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);
  50. // Create meshes
  51. var sphere = BABYLON.Mesh.CreateSphere("sphere", 48, 30.0, scene);
  52. // Register a render loop to repeatedly render the scene
  53. engine.runRenderLoop(function () {
  54. scene.render();
  55. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  56. });
  57. // Resize
  58. window.addEventListener("resize", function () {
  59. engine.resize();
  60. });
  61. var aaPostProcess = new BABYLON.AsciiArtPostProcess("AsciiArt", camera);
  62. var drPostProcess = new BABYLON.DigitalRainPostProcess("AsciiArt", camera);
  63. //camera.detachPostProcess(aaPostProcess);
  64. camera.detachPostProcess(drPostProcess);
  65. var gui = new dat.GUI();
  66. var options = {
  67. postProcess: "asciiArt"
  68. }
  69. gui.add(options, 'postProcess', ['asciiArt', 'digitalRain']).onFinishChange(function () {
  70. switch (options.postProcess) {
  71. case "asciiArt":
  72. camera.detachPostProcess(aaPostProcess);
  73. camera.detachPostProcess(drPostProcess);
  74. camera.attachPostProcess(aaPostProcess);
  75. break;
  76. case "digitalRain":
  77. camera.detachPostProcess(aaPostProcess);
  78. camera.detachPostProcess(drPostProcess);
  79. camera.attachPostProcess(drPostProcess);
  80. break;
  81. }
  82. });
  83. }
  84. });
  85. </script>
  86. </body>
  87. </html>