123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>threejs webgl - materials</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <style>
- body {
- color: #fff;
- font-family:Monospace;
- font-size:13px;
- text-align:center;
- background-color: #000;
- background-image:url("../examples/textures/roughness_map.jpg");
- margin: 0px;
- overflow: hidden;
- }
- #info {
- position: absolute;
- top: 0px; width: 100%;
- padding: 5px;
- }
- </style>
- </head>
- <body>
- <div id="container"></div>
- <div id="info"><a href="http://threejs.org" target="_blank">threejs</a> - PMREM Generator by Prashant Sharma and <a href="http://clara.io/" target="_blank">Ben Houston</a>.</div>
- <script src="../build/three.min.js"></script>
- <script src="../examples/js/controls/OrbitControls.js"></script>
- <script src="../src/loaders/BinaryTextureLoader.js"></script>
- <script src="../examples/js/loaders/RGBELoader.js"></script>
- <script src="../examples/js/loaders/HDRCubeMapLoader.js"></script>
- <script src="../examples/js/Detector.js"></script>
- <script src="../examples/js/libs/stats.min.js"></script>
- <script src="../examples/js/Half.js"></script>
- <script src="../examples/js/Encodings.js"></script>
- <script src="../examples/js/pmrem/PMREMGenerator.js"></script>
- <script src="../examples/js/pmrem/PMREM_CubeUVPacker.js"></script>
- <script src="../examples/js/libs/dat.gui.min.js"></script>
- <script src="../examples/js/postprocessing/EffectComposer.js"></script>
- <script src="../examples/js/postprocessing/RenderPass.js"></script>
- <script src="../examples/js/postprocessing/MaskPass.js"></script>
- <script src="../examples/js/postprocessing/ShaderPass.js"></script>
- <script src="../examples/js/shaders/CopyShader.js"></script>
- <script src="../examples/js/shaders/FXAAShader.js"></script>
- <script src="../examples/js/postprocessing/BloomPass.js"></script>
- <script src="../examples/js/shaders/ConvolutionShader.js"></script>
- <script>
- if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
- var container, stats;
- var params = {
- projection: 'normal',
- roughnessFactor: 0,
- background: true,
- };
- var camera, scene, renderer, controls, objects = [];
- var hdrCubeMap;
- var composer;
- var particleLight;
- var standardMaterial;
- var torusGeometry = new THREE.TorusGeometry( 15, 6, 16, 100 );
- //var torusGeometry = new THREE.SphereGeometry( 15, 32, 32 );
- var loader = new THREE.FontLoader();
- loader.load( '../examples/fonts/gentilis_regular.typeface.js', function ( font ) {
- init( font );
- animate();
- } );
- function init( font ) {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 2000 );
- camera.position.set( 0.0, 40, 40 * 3.5 );
- scene = new THREE.Scene();
- // Materials
- var hdrpath = "../examples/textures/cube/hdrPisa/";
- var hdrformat = '.hdr';
- var hdrurls = [
- hdrpath + 'px' + hdrformat, hdrpath + 'nx' + hdrformat,
- hdrpath + 'py' + hdrformat, hdrpath + 'ny' + hdrformat,
- hdrpath + 'pz' + hdrformat, hdrpath + 'nz' + hdrformat
- ];
- var hdrCubeMap = new THREE.HDRCubeMapLoader().load( THREE.HalfFloatType, hdrurls, function ( hdrCubeMap ) {
- var pmremGenerator = new THREE.PMREMGenerator( hdrCubeMap );
- pmremGenerator.update(renderer);
- var pmremCubeUVPacker = new THREE.PMREM_CubeUVPacker(pmremGenerator.cubeLods);
- pmremCubeUVPacker.update(renderer);
- var roughnessTexture = THREE.ImageUtils.loadTexture( "../examples/textures/roughness_map.jpg" );
- roughnessTexture.wrapS = THREE.RepeatWrapping;
- roughnessTexture.wrapT = THREE.RepeatWrapping;
- roughnessTexture.repeat.set( 3, 3 );
- var diffuseColor = new THREE.Color( 1, 1.0, 1.0 ).multiplyScalar( 1 - 0.08 );
- standardMaterial = new THREE.MeshStandardMaterial( { map: null, bumpMap: null, roughnessMap: null, bumpScale: 1.0, color: diffuseColor, metalness: 1.0, roughness: 0.5, shading: THREE.SmoothShading, envMap: pmremCubeUVPacker.CubeUVRenderTarget } )
- var torusMesh1 = new THREE.Mesh( torusGeometry, standardMaterial );
- torusMesh1.position.x = 0.0;
- scene.add( torusMesh1 );
- } );
- particleLight = new THREE.Mesh( new THREE.SphereBufferGeometry( 4, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0xffffff } ) );
- // Lights
- scene.add( new THREE.AmbientLight( 0x222222 ) );
- var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
- directionalLight.position.set( 1, 1, 1 ).normalize();
- //scene.add( directionalLight );
- var pointLight = new THREE.PointLight( 0xffffff, 2, 800 );
- particleLight.add( pointLight );
- var spotLight = new THREE.SpotLight( 0xffffff );
- spotLight.position.set( 10, 100, 10 );
- spotLight.angle = Math.PI/10;
- scene.add( spotLight );
- var spotLightHelper = new THREE.SpotLightHelper( spotLight );
- scene.add( spotLightHelper );
- renderer = new THREE.WebGLRenderer( { alpha:true, antialias: false } );
- renderer.setClearColor( 0x0a0a0a, 0 );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.sortObjects = true;
- container.appendChild( renderer.domElement );
- renderer.gammaInput = true;
- renderer.gammaOutput = true;
- var renderScene = new THREE.RenderPass(scene, camera);
- composer = new THREE.EffectComposer(renderer);
- composer.setSize(window.innerWidth, window.innerHeight);
- composer.addPass(renderScene);
- bloomPass = new THREE.BloomPass(1.0, 9, 0.25, 1024);
- composer.addPass(bloomPass);
- //
- effectFXAA = new THREE.ShaderPass(THREE.FXAAShader);
- effectFXAA.uniforms['resolution'].value.set(1 / (window.innerWidth), 1 / (window.innerHeight));
- effectFXAA.renderToScreen = true;
- composer.addPass(effectFXAA);
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.top = '0px';
- container.appendChild( stats.domElement );
- controls = new THREE.OrbitControls( camera );
- controls.target.set( 0, 0, 0 );
- controls.update();
- window.addEventListener( 'resize', onWindowResize, false );
- var gui = new dat.GUI();
- //gui.add( params, 'projection', { 'From cam to mesh': 'camera', 'Normal to mesh': 'normal' } );
- gui.add( params, 'roughnessFactor', 0, 1 );
- gui.add( params, 'background' );
- gui.open();
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- if(standardMaterial !== undefined)
- standardMaterial.roughness = params.roughnessFactor;
- var body = document.getElementsByTagName("BODY")[0];
- if(params.background)
- body.style.backgroundImage = "url('../examples/textures/roughness_map.jpg')";
- else
- body.style.backgroundImage = "none";
- var timer = Date.now() * 0.00025;
- //camera.position.x = Math.cos( timer ) * 800;
- //camera.position.z = Math.sin( timer ) * 800;
- camera.lookAt( scene.position );
- for ( var i = 0, l = objects.length; i < l; i ++ ) {
- var object = objects[ i ];
- object.rotation.y += 0.005;
- }
- particleLight.position.x = Math.sin( timer * 7 ) * 100;
- particleLight.position.y = Math.cos( timer * 5 ) * 100;
- particleLight.position.z = Math.cos( timer * 3 ) * 100;
- //renderer.render( scene, camera );
- composer.render();
- }
- </script>
- </body>
- </html>
|