webgl_postprocessing_smaa.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - postprocessing smaa</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. margin: 0px;
  10. background-color: #000000;
  11. overflow: hidden;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="container"></div>
  17. <script src="../build/three.min.js"></script>
  18. <script src="js/libs/stats.min.js"></script>
  19. <script src="js/postprocessing/SMAAPass.js"></script>
  20. <script src="js/shaders/CopyShader.js"></script>
  21. <script src="js/shaders/SMAAShader.js"></script>
  22. <script src="js/postprocessing/EffectComposer.js"></script>
  23. <script src="js/postprocessing/RenderPass.js"></script>
  24. <script src="js/postprocessing/MaskPass.js"></script>
  25. <script src="js/postprocessing/ShaderPass.js"></script>
  26. <script>
  27. var camera, scene, renderer, composer, pass, stats;
  28. var geometry, material, object;
  29. var textureLoader = new THREE.TextureLoader();
  30. container = document.getElementById( "container" );
  31. stats = new Stats();
  32. stats.domElement.style.position = 'absolute';
  33. stats.domElement.style.top = '0px';
  34. container.appendChild( stats.domElement );
  35. textureLoader.load( "./textures/brick_diffuse.jpg", function( meshTexture ) {
  36. init( meshTexture );
  37. animate();
  38. });
  39. function init( meshTexture ) {
  40. renderer = new THREE.WebGLRenderer( { antialias: false } );
  41. renderer.setPixelRatio( window.devicePixelRatio );
  42. renderer.setSize( window.innerWidth, window.innerHeight );
  43. document.body.appendChild( renderer.domElement );
  44. //
  45. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  46. camera.position.z = 400;
  47. scene = new THREE.Scene();
  48. geometry = new THREE.BoxGeometry( 200, 200, 200 );
  49. material = new THREE.MeshBasicMaterial( { map: meshTexture } );
  50. meshTexture.anisotropy = 4;
  51. object = new THREE.Mesh( geometry, material );
  52. scene.add( object );
  53. // postprocessing
  54. composer = new THREE.EffectComposer( renderer );
  55. composer.addPass( new THREE.RenderPass( scene, camera ) );
  56. pass = new THREE.SMAAPass( window.innerWidth, window.innerHeight );
  57. pass.renderToScreen = true;
  58. composer.addPass( pass );
  59. window.addEventListener( 'resize', onWindowResize, false );
  60. }
  61. function onWindowResize() {
  62. var width = window.innerWidth;
  63. var height = window.innerHeight;
  64. camera.aspect = width / height;
  65. camera.updateProjectionMatrix();
  66. renderer.setSize( width, height );
  67. var pixelRatio = renderer.getPixelRatio();
  68. var newWidth = Math.floor( width / pixelRatio ) || 1;
  69. var newHeight = Math.floor( height / pixelRatio ) || 1;
  70. composer.setSize( newWidth, newHeight );
  71. pass.setSize( newWidth, newHeight );
  72. }
  73. function animate() {
  74. requestAnimationFrame( animate );
  75. object.rotation.x += 0.005;
  76. object.rotation.y += 0.01;
  77. composer.render();
  78. stats.update();
  79. }
  80. </script>
  81. </body>
  82. </html>