123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgpu - postprocessing sobel</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>
- <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 } from 'three/tsl';
- import { sobel } from 'three/addons/tsl/display/SobelOperatorNode.js';
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
- import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
- let camera, scene, renderer;
- let postProcessing;
- const params = {
- enable: true
- };
- init();
- function init() {
- scene = new THREE.Scene();
- camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 );
- camera.position.set( 0, 1, 3 );
- camera.lookAt( scene.position );
- //
- const ambientLight = new THREE.AmbientLight( 0xe7e7e7 );
- scene.add( ambientLight );
- const pointLight = new THREE.PointLight( 0xffffff, 20 );
- camera.add( pointLight );
- scene.add( camera );
- //
- const geometry = new THREE.TorusKnotGeometry( 1, 0.3, 256, 32 );
- const material = new THREE.MeshPhongMaterial( { color: 0xffff00 } );
- const mesh = new THREE.Mesh( geometry, material );
- scene.add( mesh );
- //
- renderer = new THREE.WebGPURenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.setAnimationLoop( animate );
- renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
- document.body.appendChild( renderer.domElement );
- //
- const controls = new OrbitControls( camera, renderer.domElement );
- controls.enableZoom = false;
- // postprocessing
- postProcessing = new THREE.PostProcessing( renderer );
- const scenePass = pass( scene, camera );
- const scenePassColor = scenePass.getTextureNode();
- postProcessing.outputNode = sobel( scenePassColor );
- //
- const gui = new GUI();
- gui.add( params, 'enable' );
- gui.open();
- //
- window.addEventListener( 'resize', onWindowResize );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- if ( params.enable === true ) {
- postProcessing.render();
- } else {
- renderer.render( scene, camera );
- }
- }
- </script>
- </body>
- </html>
|