代码拉取完成,页面将自动刷新
<html lang="en">
<head>
<title>WebGPU RTT</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://www.soft8soft.com/verge3d" target="_blank" rel="noopener">Verge3D</a> WebGPU - RTT<br/>(Chrome Canary with flag: --enable-unsafe-webgpu)
</div>
<script type="module">
import * as v3d from '../build/v3d.module.js';
import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
import WebGPUTextureRenderer from './jsm/renderers/webgpu/WebGPUTextureRenderer.js';
import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
let camera, scene, renderer;
let cameraFX, sceneFX, textureRenderer;
let box;
const dpr = window.devicePixelRatio;
init().then(animate).catch(error);
async function init() {
if (WebGPU.isAvailable() === false) {
document.body.appendChild(WebGPU.getErrorMessage());
throw 'No WebGPU support';
}
camera = new v3d.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 10);
camera.position.z = 4;
scene = new v3d.Scene();
scene.background = new v3d.Color(0x222222);
// textured mesh
const loader = new v3d.TextureLoader();
const texture = loader.load('./textures/uv_grid_opengl.jpg');
const geometryBox = new v3d.BoxBufferGeometry();
const materialBox = new v3d.MeshBasicMaterial({ map: texture });
box = new v3d.Mesh(geometryBox, materialBox);
scene.add(box);
//
renderer = new WebGPURenderer();
renderer.setPixelRatio(dpr);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
textureRenderer = new WebGPUTextureRenderer(renderer);
textureRenderer.setSize(window.innerWidth * dpr, window.innerHeight * dpr);
window.addEventListener('resize', onWindowResize, false);
// FX
cameraFX = new v3d.OrthographicCamera(- 1, 1, 1, - 1, 0, 1);
sceneFX = new v3d.Scene();
const geometryFX = new v3d.PlaneBufferGeometry(2, 2);
// @TODO Until NodeMaterial is available just copy the beauty pass to screen
const materialFX = new v3d.MeshBasicMaterial({ map: textureRenderer.getTexture() });
const quad = new v3d.Mesh(geometryFX, materialFX);
sceneFX.add(quad);
//
return renderer.init();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
textureRenderer.setSize(window.innerWidth * dpr, window.innerHeight * dpr);
}
function animate() {
requestAnimationFrame(animate);
box.rotation.x += 0.01;
box.rotation.y += 0.02;
textureRenderer.render(scene, camera);
renderer.render(sceneFX, cameraFX);
}
function error(error) {
console.error(error);
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。