代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<title>Verge3D WebGL 2 - Multisampled Renderbuffers</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">
<style>
body {
background-color: #fff;
color: #222;
}
a {
color: #08f;
}
#container {
position: absolute;
top: 70px;
width: 100%;
bottom: 0px;
}
</style>
</head>
<body>
<div id="info">
<a href="https://www.soft8soft.com/verge3d" target="_blank" rel="noopener">Verge3D</a> - Multisampled Renderbuffers<br />
Left: WebGLRenderTarget, Right: WebGLMultisampleRenderTarget.
</div>
<div id="container">
</div>
<script type="module">
import * as v3d from '../build/v3d.module.js';
import { EffectComposer } from './jsm/postprocessing/EffectComposer.js';
import { RenderPass } from './jsm/postprocessing/RenderPass.js';
import { ShaderPass } from './jsm/postprocessing/ShaderPass.js';
import { CopyShader } from './jsm/shaders/CopyShader.js';
import { WEBGL } from './jsm/WebGL.js';
if (WEBGL.isWebGL2Available() === false) {
document.body.appendChild(WEBGL.getWebGL2ErrorMessage());
}
let camera, renderer, clock, group, container;
let composer1, composer2;
init();
animate();
function init() {
container = document.getElementById('container');
camera = new v3d.PerspectiveCamera(45, container.offsetWidth / container.offsetHeight, 1, 2000);
camera.position.z = 500;
const scene = new v3d.Scene();
scene.background = new v3d.Color(0xffffff);
scene.fog = new v3d.Fog(0xcccccc, 100, 1500);
clock = new v3d.Clock();
//
const hemiLight = new v3d.HemisphereLight(0xffffff, 0x222222, 1.5);
hemiLight.position.set(1, 1, 1);
scene.add(hemiLight);
//
group = new v3d.Group();
const geometry = new v3d.SphereBufferGeometry(10, 64, 40);
const material = new v3d.MeshLambertMaterial({ color: 0xee0808 });
const material2 = new v3d.MeshBasicMaterial({ color: 0xffffff, wireframe: true });
for (let i = 0; i < 10; i++) {
const mesh = new v3d.Mesh(geometry, material);
mesh.position.x = Math.random() * 600 - 300;
mesh.position.y = Math.random() * 600 - 300;
mesh.position.z = Math.random() * 600 - 300;
mesh.rotation.x = Math.random();
mesh.rotation.z = Math.random();
mesh.scale.setScalar(Math.random() * 5 + 5);
group.add(mesh);
const mesh2 = new v3d.Mesh(geometry, material2);
mesh2.position.copy(mesh.position);
mesh2.rotation.copy(mesh.rotation);
mesh2.scale.copy(mesh.scale);
group.add(mesh2);
}
scene.add(group);
//
renderer = new v3d.WebGLRenderer();
renderer.autoClear = false;
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(container.offsetWidth, container.offsetHeight);
container.appendChild(renderer.domElement);
//
const parameters = {
format: v3d.RGBFormat
};
const size = renderer.getDrawingBufferSize(new v3d.Vector2());
const renderTarget = new v3d.WebGLMultisampleRenderTarget(size.width, size.height, parameters);
const renderPass = new RenderPass(scene, camera);
const copyPass = new ShaderPass(CopyShader);
//
composer1 = new EffectComposer(renderer);
composer1.addPass(renderPass);
composer1.addPass(copyPass);
//
composer2 = new EffectComposer(renderer, renderTarget);
composer2.addPass(renderPass);
composer2.addPass(copyPass);
//
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = container.offsetWidth / container.offsetHeight;
camera.updateProjectionMatrix();
renderer.setSize(container.offsetWidth, container.offsetHeight);
composer1.setSize(container.offsetWidth, container.offsetHeight);
composer2.setSize(container.offsetWidth, container.offsetHeight);
}
function animate() {
requestAnimationFrame(animate);
const halfWidth = container.offsetWidth / 2;
group.rotation.y += clock.getDelta() * 0.1;
renderer.setScissorTest(true);
renderer.setScissor(0, 0, halfWidth - 1, container.offsetHeight);
composer1.render();
renderer.setScissor(halfWidth, 0, halfWidth, container.offsetHeight);
composer2.render();
renderer.setScissorTest(false);
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。