index.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. var skybox = BABYLON.Mesh.CreateBox("skyBox", 1000.0, scene);
  53. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  54. skyboxMaterial.backFaceCulling = false;
  55. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("/Playground/textures/TropicalSunnyDay", scene);
  56. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  57. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  58. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  59. skyboxMaterial.disableLighting = true;
  60. skybox.material = skyboxMaterial;
  61. skybox.setEnabled(false);
  62. // Materials
  63. sphere.material = new BABYLON.StandardMaterial("std", scene);
  64. sphere.material.diffuseTexture = new BABYLON.Texture("/Playground/textures/amiga.jpg", scene);
  65. sphere.material.diffuseTexture.uScale = 5;
  66. sphere.material.diffuseTexture.vScale = 5;
  67. // Register a render loop to repeatedly render the scene
  68. engine.runRenderLoop(function () {
  69. scene.render();
  70. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  71. });
  72. // Resize
  73. window.addEventListener("resize", function () {
  74. engine.resize();
  75. });
  76. // Post-processes
  77. var aaPostProcess = new BABYLON.AsciiArtPostProcess("AsciiArt", camera);
  78. var drPostProcess = new BABYLON.DigitalRainPostProcess("AsciiArt", camera);
  79. //camera.detachPostProcess(aaPostProcess);
  80. camera.detachPostProcess(drPostProcess);
  81. var gui = new dat.GUI();
  82. var options = {
  83. postProcess: "asciiArt"
  84. }
  85. gui.add(options, 'postProcess', ['asciiArt', 'digitalRain']).onFinishChange(function () {
  86. camera.detachPostProcess(aaPostProcess);
  87. camera.detachPostProcess(drPostProcess);
  88. skybox.setEnabled(false);
  89. switch (options.postProcess) {
  90. case "asciiArt":
  91. camera.attachPostProcess(aaPostProcess);
  92. break;
  93. case "digitalRain":
  94. camera.attachPostProcess(drPostProcess);
  95. break;
  96. }
  97. });
  98. }
  99. });
  100. </script>
  101. </body>
  102. </html>