123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <html lang="en">
- <head>
- <title>three.js webgpu - procedural texture</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 - procedural texture
- </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 { checker, uv, uniform, convertToTexture } from 'three/tsl';
- import { gaussianBlur } from 'three/addons/tsl/display/GaussianBlurNode.js';
- import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
- let camera, scene, renderer;
- init();
- render();
- function init() {
- const aspect = window.innerWidth / window.innerHeight;
- camera = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 0, 2 );
- camera.position.z = 1;
- scene = new THREE.Scene();
- // procedural to texture
- const uvScale = uniform( 4 );
- const blurAmount = uniform( .5 );
- const procedural = checker( uv().mul( uvScale ) );
- const proceduralToTexture = convertToTexture( procedural, 512, 512 ); // ( node, width, height )
- const colorNode = gaussianBlur( proceduralToTexture, blurAmount, 10 );
- // extra
- //proceduralToTexture.autoUpdate = false; // update just once
- //proceduralToTexture.textureNeedsUpdate = true; // manually update
- // scene
- const material = new THREE.MeshBasicNodeMaterial();
- material.colorNode = colorNode;
- const plane = new THREE.Mesh( new THREE.PlaneGeometry( 1, 1 ), material );
- scene.add( plane );
- // renderer
- renderer = new THREE.WebGPURenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.setAnimationLoop( render );
- document.body.appendChild( renderer.domElement );
- window.addEventListener( 'resize', onWindowResize );
- // gui
- const gui = new GUI();
- gui.add( uvScale, 'value', 1, 10 ).name( 'uv scale ( before rtt )' );
- gui.add( blurAmount, 'value', 0, 2 ).name( 'blur amount ( after rtt )' );
- gui.add( proceduralToTexture, 'autoUpdate' ).name( 'auto update' );
- }
- function onWindowResize() {
- renderer.setSize( window.innerWidth, window.innerHeight );
- const aspect = window.innerWidth / window.innerHeight;
- const frustumHeight = camera.top - camera.bottom;
- camera.left = - frustumHeight * aspect / 2;
- camera.right = frustumHeight * aspect / 2;
- camera.updateProjectionMatrix();
- }
- function render() {
- renderer.renderAsync( scene, camera );
- }
- </script>
- </body>
- </html>
|