123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - postprocessing manual msaa</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <style>
- body {
- margin: 0px;
- background-color: #000000;
- overflow: hidden;
- }
- </style>
- </head>
- <body>
- <div id="container"></div>
- <div id="info">
- <a href="http://threejs.org" target="_blank">three.js</a> - Manual Multi-Sample Anti-Aliasing (MSAA) pass by <a href="https://clara.io" target="_blank">Ben Houston</a>
- </div>
- <script src="../build/three.min.js"></script>
- <script src="js/postprocessing/MSAAPass.js"></script>
- <script src="js/shaders/CopyShader.js"></script>
- <script src="js/shaders/MSAAShader.js"></script>
- <script src="js/postprocessing/EffectComposer.js"></script>
- <script src="js/postprocessing/RenderPass.js"></script>
- <script src="js/postprocessing/MaskPass.js"></script>
- <script src="js/postprocessing/ShaderPass.js"></script>
- <script>
- var camera, scene, renderer, composer, pass;
- var geometry, material, object;
- var textureLoader = new THREE.TextureLoader();
- textureLoader.load( "textures/brick_diffuse.jpg", function( meshTexture ) {
- init( meshTexture );
- animate();
- });
- function init( meshTexture ) {
- renderer = new THREE.WebGLRenderer( { antialias: false } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
- camera.position.z = 400;
- scene = new THREE.Scene();
- geometry = new THREE.BoxGeometry( 200, 200, 200 );
- material = new THREE.MeshBasicMaterial( { map: meshTexture } );
- meshTexture.anisotropy = 4;
- object = new THREE.Mesh( geometry, material );
- scene.add( object );
- // postprocessing
- composer = new THREE.EffectComposer( renderer );
- var massPass = new THREE.MSAAPass( scene, camera, new THREE.Color( 1.0, 1.0, 1.0 ), 1.0 );
- massPass.currentSampleLevel = 4;
- composer.addPass( massPass );
- var copyPass = new THREE.ShaderPass(THREE.CopyShader);
- copyPass.renderToScreen = true;
- composer.addPass( copyPass );
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- var width = window.innerWidth;
- var height = window.innerHeight;
- camera.aspect = width / height;
- camera.updateProjectionMatrix();
- renderer.setSize( width, height );
- var pixelRatio = renderer.getPixelRatio();
- var newWidth = Math.floor( width / pixelRatio ) || 1;
- var newHeight = Math.floor( height / pixelRatio ) || 1;
- composer.setSize( newWidth, newHeight );
- pass.setSize( newWidth, newHeight );
- }
- function animate() {
- requestAnimationFrame( animate );
- object.rotation.x += 0.005;
- object.rotation.y += 0.01;
- composer.render();
- }
- </script>
- </body>
- </html>
|