You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.3 KiB
HTML
138 lines
3.3 KiB
HTML
2 months ago
|
<!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>
|
||
|
<div id="info">
|
||
|
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - Edge Detection with Sobel
|
||
|
</div>
|
||
|
|
||
|
<script type="importmap">
|
||
|
{
|
||
|
"imports": {
|
||
|
"three": "../build/three.webgpu.js",
|
||
|
"three/webgpu": "../build/three.webgpu.js",
|
||
|
"three/tsl": "../build/three.tsl.js",
|
||
|
"three/addons/": "./jsm/"
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<script type="module">
|
||
|
|
||
|
import * as THREE from 'three';
|
||
|
import { pass, renderOutput } from 'three/tsl';
|
||
|
import { sobel } from 'three/addons/tsl/display/SobelOperatorNode.js';
|
||
|
|
||
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
||
|
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
||
|
|
||
|
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
||
|
|
||
|
let camera, scene, renderer, controls;
|
||
|
let postProcessing;
|
||
|
|
||
|
const params = {
|
||
|
enabled: true
|
||
|
};
|
||
|
|
||
|
init();
|
||
|
|
||
|
async function init() {
|
||
|
|
||
|
scene = new THREE.Scene();
|
||
|
|
||
|
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 );
|
||
|
camera.position.set( 0, 1, 3 );
|
||
|
|
||
|
//
|
||
|
|
||
|
const loader = new GLTFLoader();
|
||
|
const gltf = await loader.loadAsync( 'models/gltf/DragonAttenuation.glb' );
|
||
|
const model = gltf.scene.children[ 1 ];
|
||
|
model.material = new THREE.MeshStandardNodeMaterial();
|
||
|
|
||
|
scene.add( model );
|
||
|
|
||
|
//
|
||
|
|
||
|
renderer = new THREE.WebGPURenderer( { antialias: true } );
|
||
|
renderer.setPixelRatio( window.devicePixelRatio );
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
renderer.setAnimationLoop( animate );
|
||
|
renderer.toneMapping = THREE.LinearToneMapping;
|
||
|
document.body.appendChild( renderer.domElement );
|
||
|
|
||
|
await renderer.init();
|
||
|
|
||
|
const environment = new RoomEnvironment();
|
||
|
const pmremGenerator = new THREE.PMREMGenerator( renderer );
|
||
|
|
||
|
scene.environment = pmremGenerator.fromScene( environment ).texture;
|
||
|
pmremGenerator.dispose();
|
||
|
|
||
|
//
|
||
|
|
||
|
controls = new OrbitControls( camera, renderer.domElement );
|
||
|
controls.enableDamping = true;
|
||
|
controls.enableZoom = false;
|
||
|
controls.target.set( 0, 0.5, 0 );
|
||
|
controls.update();
|
||
|
|
||
|
|
||
|
// postprocessing
|
||
|
|
||
|
postProcessing = new THREE.PostProcessing( renderer );
|
||
|
postProcessing.outputColorTransform = false;
|
||
|
|
||
|
const scenePass = pass( scene, camera );
|
||
|
|
||
|
postProcessing.outputNode = sobel( renderOutput( scenePass ) );
|
||
|
|
||
|
//
|
||
|
|
||
|
const gui = new GUI();
|
||
|
|
||
|
gui.add( params, 'enabled' );
|
||
|
gui.open();
|
||
|
|
||
|
//
|
||
|
|
||
|
window.addEventListener( 'resize', onWindowResize );
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
function onWindowResize() {
|
||
|
|
||
|
camera.aspect = window.innerWidth / window.innerHeight;
|
||
|
camera.updateProjectionMatrix();
|
||
|
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
|
||
|
}
|
||
|
|
||
|
function animate() {
|
||
|
|
||
|
controls.update();
|
||
|
|
||
|
if ( params.enabled === true ) {
|
||
|
|
||
|
postProcessing.render();
|
||
|
|
||
|
} else {
|
||
|
|
||
|
renderer.render( scene, camera );
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|