|
@@ -7,13 +7,13 @@
|
|
|
<link type="text/css" rel="stylesheet" href="main.css">
|
|
|
<style>
|
|
|
body {
|
|
|
- background-color: #bfe3dd;
|
|
|
+ background-color: #ffffff;
|
|
|
color: #000;
|
|
|
}
|
|
|
a {
|
|
|
color: #2983ff;
|
|
|
}
|
|
|
- </style>f
|
|
|
+ </style>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div id="info">
|
|
@@ -43,16 +43,69 @@
|
|
|
import { GTAOPass } from 'three/addons/postprocessing/GTAOPass.js';
|
|
|
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
|
|
|
|
|
|
- const dracoLoader = new DRACOLoader();
|
|
|
- dracoLoader.setDecoderPath( 'jsm/libs/draco/' );
|
|
|
- dracoLoader.setDecoderConfig( { type: 'js' } );
|
|
|
- const loader = new GLTFLoader();
|
|
|
- loader.setDRACOLoader( dracoLoader );
|
|
|
- loader.setPath( 'models/gltf/' );
|
|
|
+ let camera, scene, renderer, composer, controls, clock, stats, mixer;
|
|
|
|
|
|
- let mixer;
|
|
|
+ init();
|
|
|
+ animate();
|
|
|
+
|
|
|
+ function init() {
|
|
|
+
|
|
|
+ const dracoLoader = new DRACOLoader();
|
|
|
+ dracoLoader.setDecoderPath( 'jsm/libs/draco/' );
|
|
|
+ dracoLoader.setDecoderConfig( { type: 'js' } );
|
|
|
+ const loader = new GLTFLoader();
|
|
|
+ loader.setDRACOLoader( dracoLoader );
|
|
|
+ loader.setPath( 'models/gltf/' );
|
|
|
+
|
|
|
+ clock = new THREE.Clock();
|
|
|
+ const container = document.createElement( 'div' );
|
|
|
+ document.body.appendChild( container );
|
|
|
+
|
|
|
+ stats = new Stats();
|
|
|
+ container.appendChild( stats.dom );
|
|
|
+
|
|
|
+ renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ document.body.appendChild( renderer.domElement );
|
|
|
|
|
|
- const generateLittlestTokyoScene = ( scene ) => {
|
|
|
+ const pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+ scene.background = new THREE.Color( 0xbfe3dd );
|
|
|
+ scene.environment = pmremGenerator.fromScene( new RoomEnvironment( renderer ), 0.04 ).texture;
|
|
|
+
|
|
|
+ camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
|
|
|
+ camera.position.set( 5, 2, 8 );
|
|
|
+
|
|
|
+ controls = new OrbitControls( camera, renderer.domElement );
|
|
|
+ controls.target.set( 0, 0.5, 0 );
|
|
|
+ controls.update();
|
|
|
+ controls.enablePan = false;
|
|
|
+ controls.enableDamping = true;
|
|
|
+
|
|
|
+ const width = window.innerWidth;
|
|
|
+ const height = window.innerHeight;
|
|
|
+ const pixelRatio = renderer.getPixelRatio();
|
|
|
+ const maxSamples = renderer.capabilities.maxSamples;
|
|
|
+
|
|
|
+ const renderTarget = new THREE.WebGLRenderTarget( width * pixelRatio, height * pixelRatio, {
|
|
|
+ type: THREE.HalfFloatType,
|
|
|
+ samples: maxSamples,
|
|
|
+ } );
|
|
|
+ renderTarget.texture.name = 'EffectComposer.rt1';
|
|
|
+ composer = new EffectComposer( renderer, renderTarget );
|
|
|
+
|
|
|
+ const renderPass = new RenderPass( scene, camera );
|
|
|
+ composer.addPass( renderPass );
|
|
|
+
|
|
|
+ const gtaoPass = new GTAOPass( scene, camera, width, height );
|
|
|
+ gtaoPass.output = GTAOPass.OUTPUT.Denoise;
|
|
|
+ composer.addPass( gtaoPass );
|
|
|
+
|
|
|
+ const outputPass = new OutputPass();
|
|
|
+ composer.addPass( outputPass );
|
|
|
+
|
|
|
+ //
|
|
|
|
|
|
loader.load( 'LittlestTokyo.glb', ( gltf ) => {
|
|
|
|
|
@@ -67,119 +120,67 @@
|
|
|
const box = new THREE.Box3().setFromObject( scene );
|
|
|
gtaoPass.setSceneClipBox( box );
|
|
|
|
|
|
- animate();
|
|
|
-
|
|
|
}, undefined, ( e ) => console.error( e ) );
|
|
|
|
|
|
- };
|
|
|
-
|
|
|
- const clock = new THREE.Clock();
|
|
|
- const container = document.createElement( 'div' );
|
|
|
- document.body.appendChild( container );
|
|
|
-
|
|
|
- const stats = new Stats();
|
|
|
- container.appendChild( stats.dom );
|
|
|
-
|
|
|
- const renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
- renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
- document.body.appendChild( renderer.domElement );
|
|
|
-
|
|
|
- const pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
|
-
|
|
|
- const scene = new THREE.Scene();
|
|
|
- scene.background = new THREE.Color( 0xbfe3dd );
|
|
|
- scene.environment = pmremGenerator.fromScene( new RoomEnvironment( renderer ), 0.04 ).texture;
|
|
|
-
|
|
|
- const camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
|
|
|
- camera.position.set( 5, 2, 8 );
|
|
|
-
|
|
|
- const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
- controls.target.set( 0, 0.5, 0 );
|
|
|
- controls.update();
|
|
|
- controls.enablePan = false;
|
|
|
- controls.enableDamping = true;
|
|
|
-
|
|
|
- const width = window.innerWidth;
|
|
|
- const height = window.innerHeight;
|
|
|
- const pixelRatio = renderer.getPixelRatio();
|
|
|
- const maxSamples = renderer.capabilities.maxSamples;
|
|
|
-
|
|
|
- const renderTarget = new THREE.WebGLRenderTarget( width * pixelRatio, height * pixelRatio, {
|
|
|
- type: THREE.HalfFloatType,
|
|
|
- samples: maxSamples,
|
|
|
- } );
|
|
|
- renderTarget.texture.name = 'EffectComposer.rt1';
|
|
|
- const composer = new EffectComposer( renderer, renderTarget );
|
|
|
-
|
|
|
- const renderPass = new RenderPass( scene, camera );
|
|
|
- composer.addPass( renderPass );
|
|
|
-
|
|
|
- const gtaoPass = new GTAOPass( scene, camera, width, height );
|
|
|
- gtaoPass.output = GTAOPass.OUTPUT.Denoise;
|
|
|
- composer.addPass( gtaoPass );
|
|
|
-
|
|
|
- const outputPass = new OutputPass();
|
|
|
- composer.addPass( outputPass );
|
|
|
-
|
|
|
- generateLittlestTokyoScene( scene );
|
|
|
-
|
|
|
- // Init gui
|
|
|
- const gui = new GUI();
|
|
|
-
|
|
|
- gui.add( gtaoPass, 'output', {
|
|
|
- 'Default': GTAOPass.OUTPUT.Default,
|
|
|
- 'Diffuse': GTAOPass.OUTPUT.Diffuse,
|
|
|
- 'AO Only': GTAOPass.OUTPUT.AO,
|
|
|
- 'AO Only + Denoise': GTAOPass.OUTPUT.Denoise,
|
|
|
- 'Depth': GTAOPass.OUTPUT.Depth,
|
|
|
- 'Normal': GTAOPass.OUTPUT.Normal
|
|
|
- } ).onChange( function ( value ) {
|
|
|
-
|
|
|
- gtaoPass.output = value;
|
|
|
-
|
|
|
- } );
|
|
|
-
|
|
|
- const aoParameters = {
|
|
|
- radius: 0.25,
|
|
|
- distanceExponent: 1.,
|
|
|
- thickness: 1.,
|
|
|
- bias: 0.001,
|
|
|
- scale: 1.,
|
|
|
- samples: 16,
|
|
|
- distanceFallOff: true,
|
|
|
- clipRangeCheck: true,
|
|
|
- depthRelativeBias: false,
|
|
|
- nvAlignedSamples: false,
|
|
|
- screenSpaceRadius: false,
|
|
|
- };
|
|
|
- const pdParameters = {
|
|
|
- lumaPhi: 10.,
|
|
|
- depthPhi: 2.,
|
|
|
- normalPhi: 3.,
|
|
|
- radius: 4.,
|
|
|
- radiusExponent: 1.,
|
|
|
- rings: 2.,
|
|
|
- samples: 16,
|
|
|
- };
|
|
|
- gtaoPass.updateGtaoMaterial( aoParameters );
|
|
|
- gtaoPass.updatePdMaterial( pdParameters );
|
|
|
- gui.add( gtaoPass, 'blendIntensity' ).min( 0 ).max( 1 ).step( 0.01 );
|
|
|
- gui.add( aoParameters, 'radius' ).min( 0.01 ).max( 1 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( aoParameters, 'distanceExponent' ).min( 1 ).max( 4 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( aoParameters, 'thickness' ).min( 0.01 ).max( 10 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( aoParameters, 'bias' ).min( 0 ).max( 0.1 ).step( 0.0001 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( aoParameters, 'scale' ).min( 0.01 ).max( 2.0 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( aoParameters, 'samples' ).min( 2 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( aoParameters, 'screenSpaceRadius' ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
- gui.add( pdParameters, 'lumaPhi' ).min( 0 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
- gui.add( pdParameters, 'depthPhi' ).min( 0.01 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
- gui.add( pdParameters, 'normalPhi' ).min( 0.01 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
- gui.add( pdParameters, 'radius' ).min( 0 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
- gui.add( pdParameters, 'radiusExponent' ).min( 0.1 ).max( 4. ).step( 0.1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
- gui.add( pdParameters, 'rings' ).min( 1 ).max( 16 ).step( 0.125 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
- gui.add( pdParameters, 'samples' ).min( 2 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ // Init gui
|
|
|
+ const gui = new GUI();
|
|
|
+
|
|
|
+ gui.add( gtaoPass, 'output', {
|
|
|
+ 'Default': GTAOPass.OUTPUT.Default,
|
|
|
+ 'Diffuse': GTAOPass.OUTPUT.Diffuse,
|
|
|
+ 'AO Only': GTAOPass.OUTPUT.AO,
|
|
|
+ 'AO Only + Denoise': GTAOPass.OUTPUT.Denoise,
|
|
|
+ 'Depth': GTAOPass.OUTPUT.Depth,
|
|
|
+ 'Normal': GTAOPass.OUTPUT.Normal
|
|
|
+ } ).onChange( function ( value ) {
|
|
|
+
|
|
|
+ gtaoPass.output = value;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ const aoParameters = {
|
|
|
+ radius: 0.25,
|
|
|
+ distanceExponent: 1.,
|
|
|
+ thickness: 1.,
|
|
|
+ bias: 0.001,
|
|
|
+ scale: 1.,
|
|
|
+ samples: 16,
|
|
|
+ distanceFallOff: true,
|
|
|
+ clipRangeCheck: true,
|
|
|
+ depthRelativeBias: false,
|
|
|
+ nvAlignedSamples: false,
|
|
|
+ screenSpaceRadius: false,
|
|
|
+ };
|
|
|
+ const pdParameters = {
|
|
|
+ lumaPhi: 10.,
|
|
|
+ depthPhi: 2.,
|
|
|
+ normalPhi: 3.,
|
|
|
+ radius: 4.,
|
|
|
+ radiusExponent: 1.,
|
|
|
+ rings: 2.,
|
|
|
+ samples: 16,
|
|
|
+ };
|
|
|
+ gtaoPass.updateGtaoMaterial( aoParameters );
|
|
|
+ gtaoPass.updatePdMaterial( pdParameters );
|
|
|
+ gui.add( gtaoPass, 'blendIntensity' ).min( 0 ).max( 1 ).step( 0.01 );
|
|
|
+ gui.add( aoParameters, 'radius' ).min( 0.01 ).max( 1 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( aoParameters, 'distanceExponent' ).min( 1 ).max( 4 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( aoParameters, 'thickness' ).min( 0.01 ).max( 10 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( aoParameters, 'bias' ).min( 0 ).max( 0.1 ).step( 0.0001 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( aoParameters, 'scale' ).min( 0.01 ).max( 2.0 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( aoParameters, 'samples' ).min( 2 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( aoParameters, 'screenSpaceRadius' ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
|
|
|
+ gui.add( pdParameters, 'lumaPhi' ).min( 0 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ gui.add( pdParameters, 'depthPhi' ).min( 0.01 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ gui.add( pdParameters, 'normalPhi' ).min( 0.01 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ gui.add( pdParameters, 'radius' ).min( 0 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ gui.add( pdParameters, 'radiusExponent' ).min( 0.1 ).max( 4. ).step( 0.1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ gui.add( pdParameters, 'rings' ).min( 1 ).max( 16 ).step( 0.125 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
+ gui.add( pdParameters, 'samples' ).min( 2 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
|
|
|
|
|
|
- window.addEventListener( 'resize', onWindowResize );
|
|
|
+ window.addEventListener( 'resize', onWindowResize );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
function onWindowResize() {
|
|
|
|
|
@@ -214,8 +215,6 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- animate();
|
|
|
-
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|