123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgpu - postprocessing anamorphic</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - postprocessing anamorphic<br />
- Battle Damaged Sci-fi Helmet by
- <a href="https://sketchfab.com/theblueturtle_" target="_blank" rel="noopener">theblueturtle_</a><br />
- </div>
- <script type="importmap">
- {
- "imports": {
- "three": "../build/three.webgpu.js",
- "three/tsl": "../build/three.webgpu.js",
- "three/addons/": "./jsm/"
- }
- }
- </script>
- <script type="module">
- import * as THREE from 'three';
- import { pass, cubeTexture, screenUV, grayscale, uniform } from 'three/tsl';
- import { anamorphic } from 'three/addons/tsl/display/AnamorphicNode.js';
- import { RGBMLoader } from 'three/addons/loaders/RGBMLoader.js';
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
- import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
- let camera, scene, renderer;
- let postProcessing;
- init();
- async function init() {
- const container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
- camera.position.set( - 1.8, - 0.6, 2.7 );
- scene = new THREE.Scene();
- const rgbmUrls = [ 'px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png' ];
- const cube1Texture = await new RGBMLoader()
- .setMaxRange( 16 )
- .setPath( './textures/cube/pisaRGBM16/' )
- .loadCubemapAsync( rgbmUrls );
- scene.environment = cube1Texture;
- scene.backgroundNode = grayscale( cubeTexture( cube1Texture ).mul( screenUV.distance( .5 ).oneMinus().remapClamp( .1, 4 ) ) );
- const loader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
- loader.load( 'DamagedHelmet.gltf', function ( gltf ) {
- scene.add( gltf.scene );
- } );
- renderer = new THREE.WebGPURenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.toneMapping = THREE.LinearToneMapping;
- renderer.toneMappingExposure = 1;
- renderer.setAnimationLoop( render );
- container.appendChild( renderer.domElement );
- const controls = new OrbitControls( camera, renderer.domElement );
- controls.minDistance = 2;
- controls.maxDistance = 10;
- // post-processing
- const scenePass = pass( scene, camera );
- const threshold = uniform( 1.4 );
- const scaleNode = uniform( 5 );
- const intensity = uniform( 1 );
- const samples = 64;
- const anamorphicPass = anamorphic( scenePass.getTextureNode(), threshold, scaleNode, samples );
- anamorphicPass.resolution = new THREE.Vector2( .2, .2 ); // 1 = full resolution
- postProcessing = new THREE.PostProcessing( renderer );
- postProcessing.outputNode = scenePass.add( anamorphicPass.mul( intensity ) );
- //postProcessing.outputNode = scenePass.add( anamorphicPass.getTextureNode().gaussianBlur() );
- // gui
- const gui = new GUI();
- gui.add( intensity, 'value', 0, 4, 0.1 ).name( 'intensity' );
- gui.add( threshold, 'value', .8, 3, .001 ).name( 'threshold' );
- gui.add( scaleNode, 'value', 1, 10, 0.1 ).name( 'scale' );
- gui.add( anamorphicPass.resolution, 'x', .1, 1, 0.1 ).name( 'resolution' ).onChange( ( v ) => anamorphicPass.resolution.y = v );
- //
- window.addEventListener( 'resize', onWindowResize );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- //
- function render() {
- postProcessing.render();
- }
- </script>
- </body>
- </html>
|