index.html 2.6 KB

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