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.
earthquake_3d_viewer_front/three/examples/webgpu_procedural_texture.html

112 lines
2.9 KiB
HTML

<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/webgpu": "../build/three.webgpu.js",
"three/tsl": "../build/three.tsl.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>