1 Star 0 Fork 0

ing10010/verge3d-code-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webgl2_multisampled_renderbuffers.html 4.84 KB
一键复制 编辑 原始数据 按行查看 历史
<!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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/ing/verge3d-code-examples.git
git@gitee.com:ing/verge3d-code-examples.git
ing
verge3d-code-examples
verge3d-code-examples
master

搜索帮助