123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - post processing - Scalable Ambient Occlusion (SAO)</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 {
- background-color: #000000;
- margin: 0px;
- overflow: hidden;
- font-family:Monospace;
- font-size:13px;
- text-align:center;
- font-weight: bold;
- }
- a { color:#00ff78; }
- #info {
- color: #fff;
- position: absolute;
- top: 0px;
- width: 100%;
- padding: 5px;
- }
- .dg.ac {
- z-index: 1 !important; /* FIX DAT.GUI */
- }
- </style>
- </head>
- <body>
- <script src="../build/three.js"></script>
- <script src="js/postprocessing/EffectComposer.js"></script>
- <script src="js/postprocessing/RenderPass.js"></script>
- <script src="js/postprocessing/ShaderPass.js"></script>
- <script src="js/postprocessing/SAOPass.js"></script>
- <script src="js/shaders/CopyShader.js"></script>
- <script src="js/shaders/SAOShader.js"></script>
- <script src="js/shaders/DepthLimitedBlurShader.js"></script>
- <script src="js/shaders/UnpackDepthRGBAShader.js"></script>
- <script src="js/WebGL.js"></script>
- <script src="js/libs/stats.min.js"></script>
- <script src='js/libs/dat.gui.min.js'></script>
- <div id="info">
- <a href="http://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> - Scalable Ambient Occlusion (SAO) shader by <a href="http://clara.io">Ben Houston</a> / Post-processing pass by <a href="http://ludobaka.github.io">Ludobaka</a>
- </div>
- <script>
- if ( WEBGL.isWebGLAvailable() === false ) {
- document.body.appendChild( WEBGL.getWebGLErrorMessage() );
- }
- var container, stats;
- var camera, scene, renderer;
- var composer, renderPass, saoPass;
- var group;
- init();
- animate();
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- var width = window.innerWidth || 1;
- var height = window.innerHeight || 1;
- var devicePixelRatio = window.devicePixelRatio || 1;
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setClearColor( 0x000000 );
- renderer.setPixelRatio( devicePixelRatio );
- renderer.setSize( width, height );
- document.body.appendChild( renderer.domElement );
- camera = new THREE.PerspectiveCamera( 65, width / height, 3, 10 );
- camera.position.z = 7;
- scene = new THREE.Scene();
- group = new THREE.Object3D();
- scene.add( group );
- var light = new THREE.PointLight( 0xddffdd, 0.8 );
- light.position.z = 70;
- light.position.y = - 70;
- light.position.x = - 70;
- scene.add( light );
- var light2 = new THREE.PointLight( 0xffdddd, 0.8 );
- light2.position.z = 70;
- light2.position.x = - 70;
- light2.position.y = 70;
- scene.add( light2 );
- var light3 = new THREE.PointLight( 0xddddff, 0.8 );
- light3.position.z = 70;
- light3.position.x = 70;
- light3.position.y = - 70;
- scene.add( light3 );
- var light3 = new THREE.AmbientLight( 0xffffff, 0.05 );
- scene.add( light3 );
- var geometry = new THREE.SphereBufferGeometry( 3, 48, 24 );
- for ( var i = 0; i < 120; i ++ ) {
- var material = new THREE.MeshStandardMaterial();
- material.roughness = 0.5 * Math.random() + 0.25;
- material.metalness = 0;
- material.color.setHSL( Math.random(), 1.0, 0.3 );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.position.x = Math.random() * 4 - 2;
- mesh.position.y = Math.random() * 4 - 2;
- mesh.position.z = Math.random() * 4 - 2;
- mesh.rotation.x = Math.random();
- mesh.rotation.y = Math.random();
- mesh.rotation.z = Math.random();
- mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 0.2 + 0.05;
- group.add( mesh );
- }
- stats = new Stats();
- container.appendChild( stats.dom );
- composer = new THREE.EffectComposer( renderer );
- renderPass = new THREE.RenderPass( scene, camera );
- composer.addPass( renderPass );
- saoPass = new THREE.SAOPass( scene, camera, false, true );
- composer.addPass( saoPass );
- // Init gui
- var gui = new dat.GUI();
- gui.add( saoPass.params, 'output', {
- 'Beauty': THREE.SAOPass.OUTPUT.Beauty,
- 'Beauty+SAO': THREE.SAOPass.OUTPUT.Default,
- 'SAO': THREE.SAOPass.OUTPUT.SAO,
- 'Depth': THREE.SAOPass.OUTPUT.Depth,
- 'Normal': THREE.SAOPass.OUTPUT.Normal
- } ).onChange( function ( value ) {
- saoPass.params.output = parseInt( value );
- } );
- gui.add( saoPass.params, 'saoBias', - 1, 1 );
- gui.add( saoPass.params, 'saoIntensity', 0, 1 );
- gui.add( saoPass.params, 'saoScale', 0, 10 );
- gui.add( saoPass.params, 'saoKernelRadius', 1, 100 );
- gui.add( saoPass.params, 'saoMinResolution', 0, 1 );
- gui.add( saoPass.params, 'saoBlur' );
- gui.add( saoPass.params, 'saoBlurRadius', 0, 200 );
- gui.add( saoPass.params, 'saoBlurStdDev', 0.5, 150 );
- gui.add( saoPass.params, 'saoBlurDepthCutoff', 0.0, 0.1 );
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- var width = window.innerWidth || 1;
- var height = window.innerHeight || 1;
- camera.aspect = width / height;
- camera.updateProjectionMatrix();
- renderer.setSize( width, height );
- composer.setSize( width, height );
- }
- function animate() {
- requestAnimationFrame( animate );
- stats.begin();
- render();
- stats.end();
- }
- function render() {
- var timer = performance.now();
- group.rotation.x = timer * 0.0002;
- group.rotation.y = timer * 0.0001;
- composer.render();
- }
- </script>
- </body>
- </html>
|