You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
2.9 KiB
124 lines
2.9 KiB
2 years ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>three.js webgl - materials - HDR texture loader</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> - webgl HDR (RGBE) texture loader example<br/>
|
||
|
Image courtesy of <a href="http://www.pauldebevec.com/Research/HDR/" target="_blank" rel="noopener">Paul Debevec</a>.
|
||
|
</div>
|
||
|
|
||
|
<!-- Import maps polyfill -->
|
||
|
<!-- Remove this when import maps will be widely supported -->
|
||
|
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
|
||
|
|
||
|
<script type="importmap">
|
||
|
{
|
||
|
"imports": {
|
||
|
"three": "../build/three.module.js",
|
||
|
"three/addons/": "./jsm/"
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<script type="module">
|
||
|
|
||
|
import * as THREE from 'three';
|
||
|
|
||
|
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
||
|
|
||
|
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
|
||
|
|
||
|
const params = {
|
||
|
exposure: 2.0
|
||
|
};
|
||
|
|
||
|
let renderer, scene, camera;
|
||
|
|
||
|
init();
|
||
|
|
||
|
function init() {
|
||
|
|
||
|
renderer = new THREE.WebGLRenderer();
|
||
|
renderer.setPixelRatio( window.devicePixelRatio );
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
document.body.appendChild( renderer.domElement );
|
||
|
|
||
|
renderer.toneMapping = THREE.ReinhardToneMapping;
|
||
|
renderer.toneMappingExposure = params.exposure;
|
||
|
|
||
|
renderer.outputEncoding = THREE.sRGBEncoding;
|
||
|
|
||
|
scene = new THREE.Scene();
|
||
|
|
||
|
const aspect = window.innerWidth / window.innerHeight;
|
||
|
|
||
|
camera = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 0, 1 );
|
||
|
|
||
|
new RGBELoader()
|
||
|
.load( 'textures/memorial.hdr', function ( texture, textureData ) {
|
||
|
|
||
|
//console.log( textureData );
|
||
|
//console.log( texture );
|
||
|
|
||
|
const material = new THREE.MeshBasicMaterial( { map: texture } );
|
||
|
|
||
|
const quad = new THREE.PlaneGeometry( 1.5 * textureData.width / textureData.height, 1.5 );
|
||
|
|
||
|
const mesh = new THREE.Mesh( quad, material );
|
||
|
|
||
|
scene.add( mesh );
|
||
|
|
||
|
render();
|
||
|
|
||
|
} );
|
||
|
|
||
|
//
|
||
|
|
||
|
const gui = new GUI();
|
||
|
|
||
|
gui.add( params, 'exposure', 0, 4, 0.01 ).onChange( render );
|
||
|
gui.open();
|
||
|
|
||
|
//
|
||
|
|
||
|
window.addEventListener( 'resize', onWindowResize );
|
||
|
|
||
|
}
|
||
|
|
||
|
function onWindowResize() {
|
||
|
|
||
|
const aspect = window.innerWidth / window.innerHeight;
|
||
|
|
||
|
const frustumHeight = camera.top - camera.bottom;
|
||
|
|
||
|
camera.left = - frustumHeight * aspect / 2;
|
||
|
camera.right = frustumHeight * aspect / 2;
|
||
|
|
||
|
camera.updateProjectionMatrix();
|
||
|
|
||
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
||
|
|
||
|
render();
|
||
|
|
||
|
}
|
||
|
|
||
|
//
|
||
|
|
||
|
function render() {
|
||
|
|
||
|
renderer.toneMappingExposure = params.exposure;
|
||
|
|
||
|
renderer.render( scene, camera );
|
||
|
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|