|
@@ -1,248 +1,244 @@
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>three.js webgl - materials - clearcoat</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 - materials - clearcoat
|
|
|
+ </div>
|
|
|
|
|
|
-<head>
|
|
|
- <title>three.js webgl - materials - clearcoat</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>
|
|
|
+ <script type="module">
|
|
|
|
|
|
-<body>
|
|
|
- <div id="info">
|
|
|
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - materials - clearcoat
|
|
|
- </div>
|
|
|
+ import * as THREE from '../build/three.module.js';
|
|
|
|
|
|
- <script type="module">
|
|
|
+ import Stats from './jsm/libs/stats.module.js';
|
|
|
|
|
|
- import * as THREE from '../build/three.module.js';
|
|
|
+ import { OrbitControls } from './jsm/controls/OrbitControls.js';
|
|
|
+ import { HDRCubeTextureLoader } from './jsm/loaders/HDRCubeTextureLoader.js';
|
|
|
|
|
|
- import Stats from './jsm/libs/stats.module.js';
|
|
|
+ var container, stats;
|
|
|
|
|
|
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
|
|
|
- import { RGBELoader } from './jsm/loaders/RGBELoader.js';
|
|
|
+ var camera, scene, renderer;
|
|
|
|
|
|
- var container, stats;
|
|
|
+ var particleLight;
|
|
|
+ var group;
|
|
|
|
|
|
- var camera, scene, renderer;
|
|
|
+ init();
|
|
|
+ animate();
|
|
|
|
|
|
- var particleLight;
|
|
|
- var group;
|
|
|
+ function init() {
|
|
|
|
|
|
- init();
|
|
|
- animate();
|
|
|
+ container = document.createElement( 'div' );
|
|
|
+ document.body.appendChild( container );
|
|
|
|
|
|
- function init() {
|
|
|
+ camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
|
|
|
+ camera.position.z = 1000;
|
|
|
|
|
|
- container = document.createElement( 'div' );
|
|
|
- document.body.appendChild( container );
|
|
|
+ scene = new THREE.Scene();
|
|
|
|
|
|
- camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
|
|
|
- camera.position.z = 1000;
|
|
|
+ group = new THREE.Group();
|
|
|
+ scene.add( group );
|
|
|
|
|
|
- scene = new THREE.Scene();
|
|
|
-
|
|
|
- group = new THREE.Group();
|
|
|
- scene.add( group );
|
|
|
-
|
|
|
- new RGBELoader()
|
|
|
+ new HDRCubeTextureLoader()
|
|
|
.setDataType( THREE.UnsignedByteType )
|
|
|
- .setPath( 'textures/equirectangular/' )
|
|
|
- .load( 'pedestrian_overpass_1k.hdr', function ( hdrEquirect ) {
|
|
|
-
|
|
|
- var hdrCubeRenderTarget = pmremGenerator.fromEquirectangular( hdrEquirect );
|
|
|
- hdrEquirect.dispose();
|
|
|
- pmremGenerator.dispose();
|
|
|
-
|
|
|
- var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
|
|
|
-
|
|
|
- var textureLoader = new THREE.TextureLoader();
|
|
|
-
|
|
|
- var diffuse = textureLoader.load( "textures/carbon/Carbon.png" );
|
|
|
- diffuse.encoding = THREE.sRGBEncoding;
|
|
|
- diffuse.wrapS = THREE.RepeatWrapping;
|
|
|
- diffuse.wrapT = THREE.RepeatWrapping;
|
|
|
- diffuse.repeat.x = 10;
|
|
|
- diffuse.repeat.y = 10;
|
|
|
-
|
|
|
- var normalMap = textureLoader.load( "textures/carbon/Carbon_Normal.png" );
|
|
|
- normalMap.wrapS = THREE.RepeatWrapping;
|
|
|
- normalMap.wrapT = THREE.RepeatWrapping;
|
|
|
-
|
|
|
- var normalMap2 = textureLoader.load( "textures/water/Water_1_M_Normal.jpg" );
|
|
|
-
|
|
|
- var normalMap3 = textureLoader.load( "textures/flakes.png" );
|
|
|
- normalMap3.wrapS = THREE.RepeatWrapping;
|
|
|
- normalMap3.wrapT = THREE.RepeatWrapping;
|
|
|
- normalMap3.repeat.x = 10;
|
|
|
- normalMap3.repeat.y = 10;
|
|
|
- normalMap3.anisotropy = 16;
|
|
|
-
|
|
|
- var normalMap4 = textureLoader.load( "textures/golfball.jpg" );
|
|
|
-
|
|
|
- var clearcoatNormaMap = textureLoader.load( "textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png" );
|
|
|
-
|
|
|
- // car paint
|
|
|
-
|
|
|
- var material = new THREE.MeshPhysicalMaterial( {
|
|
|
- clearcoat: 1.0,
|
|
|
- clearcoatRoughness: 0.1,
|
|
|
- metalness: 0.9,
|
|
|
- roughness: 0.5,
|
|
|
- color: 0x0000ff,
|
|
|
- envMap: hdrCubeRenderTarget.texture,
|
|
|
- normalMap: normalMap3,
|
|
|
- normalScale: new THREE.Vector2( 0.1, 0.1 )
|
|
|
- } );
|
|
|
-
|
|
|
- var mesh = new THREE.Mesh( geometry, material );
|
|
|
- mesh.position.x = - 100;
|
|
|
- mesh.position.y = 100;
|
|
|
- group.add( mesh );
|
|
|
-
|
|
|
- // fibers
|
|
|
-
|
|
|
- var material = new THREE.MeshPhysicalMaterial( {
|
|
|
- clearcoat: 1.0,
|
|
|
- clearcoatRoughness: 0.1,
|
|
|
- envMap: hdrCubeRenderTarget.texture,
|
|
|
- map: diffuse,
|
|
|
- normalMap: normalMap
|
|
|
- } );
|
|
|
- var mesh = new THREE.Mesh( geometry, material );
|
|
|
- mesh.position.x = 100;
|
|
|
- mesh.position.y = 100;
|
|
|
- group.add( mesh );
|
|
|
-
|
|
|
- // golf
|
|
|
-
|
|
|
- var material = new THREE.MeshPhysicalMaterial( {
|
|
|
- metalness: 0.0,
|
|
|
- roughness: 0.1,
|
|
|
- clearcoat: 1.0,
|
|
|
- normalMap: normalMap4,
|
|
|
- envMap: hdrCubeRenderTarget.texture,
|
|
|
- clearcoatNormalMap: clearcoatNormaMap,
|
|
|
- clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
|
|
|
- } );
|
|
|
- var mesh = new THREE.Mesh( geometry, material );
|
|
|
- mesh.position.x = - 100;
|
|
|
- mesh.position.y = - 100;
|
|
|
- group.add( mesh );
|
|
|
-
|
|
|
- // clearcoat + normalmap
|
|
|
-
|
|
|
- var material = new THREE.MeshPhysicalMaterial( {
|
|
|
- clearcoat: 1.0,
|
|
|
- metalness: 1.0,
|
|
|
- color: 0xff0000,
|
|
|
- envMap: hdrCubeRenderTarget.texture,
|
|
|
- normalMap: normalMap2,
|
|
|
- normalScale: new THREE.Vector2( 0.15, 0.15 ),
|
|
|
- clearcoatNormalMap: clearcoatNormaMap,
|
|
|
- clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
|
|
|
- } );
|
|
|
- var mesh = new THREE.Mesh( geometry, material );
|
|
|
- mesh.position.x = 100;
|
|
|
- mesh.position.y = - 100;
|
|
|
- group.add( mesh );
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- scene.background = hdrCubeRenderTarget.texture;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ .setPath( 'textures/cube/pisaHDR/' )
|
|
|
+ .load( [ 'px.hdr', 'nx.hdr', 'py.hdr', 'ny.hdr', 'pz.hdr', 'nz.hdr' ],
|
|
|
+ function ( hdrCubeMap ) {
|
|
|
+
|
|
|
+ var hdrCubeRenderTarget = pmremGenerator.fromCubemap( hdrCubeMap );
|
|
|
+ hdrCubeMap.dispose();
|
|
|
+ pmremGenerator.dispose();
|
|
|
+
|
|
|
+ var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
|
|
|
+
|
|
|
+ var textureLoader = new THREE.TextureLoader();
|
|
|
+
|
|
|
+ var diffuse = textureLoader.load( "textures/carbon/Carbon.png" );
|
|
|
+ diffuse.encoding = THREE.sRGBEncoding;
|
|
|
+ diffuse.wrapS = THREE.RepeatWrapping;
|
|
|
+ diffuse.wrapT = THREE.RepeatWrapping;
|
|
|
+ diffuse.repeat.x = 10;
|
|
|
+ diffuse.repeat.y = 10;
|
|
|
+
|
|
|
+ var normalMap = textureLoader.load( "textures/carbon/Carbon_Normal.png" );
|
|
|
+ normalMap.wrapS = THREE.RepeatWrapping;
|
|
|
+ normalMap.wrapT = THREE.RepeatWrapping;
|
|
|
+
|
|
|
+ var normalMap2 = textureLoader.load( "textures/water/Water_1_M_Normal.jpg" );
|
|
|
+
|
|
|
+ var normalMap3 = textureLoader.load( "textures/flakes.png" );
|
|
|
+ normalMap3.wrapS = THREE.RepeatWrapping;
|
|
|
+ normalMap3.wrapT = THREE.RepeatWrapping;
|
|
|
+ normalMap3.repeat.x = 10;
|
|
|
+ normalMap3.repeat.y = 10;
|
|
|
+ normalMap3.anisotropy = 16;
|
|
|
+
|
|
|
+ var normalMap4 = textureLoader.load( "textures/golfball.jpg" );
|
|
|
+
|
|
|
+ var clearcoatNormaMap = textureLoader.load( "textures/pbr/Scratched_gold/Scratched_gold_01_1K_Normal.png" );
|
|
|
+
|
|
|
+ // car paint
|
|
|
+
|
|
|
+ var material = new THREE.MeshPhysicalMaterial( {
|
|
|
+ clearcoat: 1.0,
|
|
|
+ clearcoatRoughness: 0.1,
|
|
|
+ metalness: 0.9,
|
|
|
+ roughness: 0.5,
|
|
|
+ color: 0x0000ff,
|
|
|
+ normalMap: normalMap3,
|
|
|
+ normalScale: new THREE.Vector2( 0.15, 0.15 )
|
|
|
+ } );
|
|
|
+
|
|
|
+ var mesh = new THREE.Mesh( geometry, material );
|
|
|
+ mesh.position.x = - 100;
|
|
|
+ mesh.position.y = 100;
|
|
|
+ group.add( mesh );
|
|
|
+
|
|
|
+ // fibers
|
|
|
+
|
|
|
+ var material = new THREE.MeshPhysicalMaterial( {
|
|
|
+ roughness: 0.5,
|
|
|
+ clearcoat: 1.0,
|
|
|
+ clearcoatRoughness: 0.1,
|
|
|
+ map: diffuse,
|
|
|
+ normalMap: normalMap
|
|
|
+ } );
|
|
|
+ var mesh = new THREE.Mesh( geometry, material );
|
|
|
+ mesh.position.x = 100;
|
|
|
+ mesh.position.y = 100;
|
|
|
+ group.add( mesh );
|
|
|
+
|
|
|
+ // golf
|
|
|
+
|
|
|
+ var material = new THREE.MeshPhysicalMaterial( {
|
|
|
+ metalness: 0.0,
|
|
|
+ roughness: 0.1,
|
|
|
+ clearcoat: 1.0,
|
|
|
+ normalMap: normalMap4,
|
|
|
+ clearcoatNormalMap: clearcoatNormaMap,
|
|
|
+ clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
|
|
|
+ } );
|
|
|
+ var mesh = new THREE.Mesh( geometry, material );
|
|
|
+ mesh.position.x = - 100;
|
|
|
+ mesh.position.y = - 100;
|
|
|
+ group.add( mesh );
|
|
|
+
|
|
|
+ // clearcoat + normalmap
|
|
|
+
|
|
|
+ var material = new THREE.MeshPhysicalMaterial( {
|
|
|
+ clearcoat: 1.0,
|
|
|
+ metalness: 1.0,
|
|
|
+ color: 0xff0000,
|
|
|
+ normalMap: normalMap2,
|
|
|
+ normalScale: new THREE.Vector2( 0.15, 0.15 ),
|
|
|
+ clearcoatNormalMap: clearcoatNormaMap,
|
|
|
+ clearcoatNormalScale: new THREE.Vector2( 2.0, 2.0 )
|
|
|
+ } );
|
|
|
+ var mesh = new THREE.Mesh( geometry, material );
|
|
|
+ mesh.position.x = 100;
|
|
|
+ mesh.position.y = - 100;
|
|
|
+ group.add( mesh );
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ scene.background = hdrCubeRenderTarget.texture;
|
|
|
+ scene.environment = hdrCubeRenderTarget.texture;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ // LIGHTS
|
|
|
+
|
|
|
+ particleLight = new THREE.Mesh(
|
|
|
+ new THREE.SphereBufferGeometry( 4, 8, 8 ),
|
|
|
+ new THREE.MeshBasicMaterial( { color: 0xffffff } )
|
|
|
);
|
|
|
+ scene.add( particleLight );
|
|
|
|
|
|
- // LIGHTS
|
|
|
+ particleLight.add( new THREE.PointLight( 0xffffff, 1 ) );
|
|
|
|
|
|
- particleLight = new THREE.Mesh(
|
|
|
- new THREE.SphereBufferGeometry( 4, 8, 8 ),
|
|
|
- new THREE.MeshBasicMaterial( { color: 0xffffff } )
|
|
|
- );
|
|
|
- scene.add( particleLight );
|
|
|
+ renderer = new THREE.WebGLRenderer();
|
|
|
+ renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ container.appendChild( renderer.domElement );
|
|
|
|
|
|
- particleLight.add( new THREE.PointLight( 0xffffff, 1 ) );
|
|
|
+ //
|
|
|
|
|
|
- renderer = new THREE.WebGLRenderer();
|
|
|
- renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
- renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
- container.appendChild( renderer.domElement );
|
|
|
+ renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
|
+ renderer.toneMappingExposure = 1;
|
|
|
|
|
|
- //
|
|
|
+ //
|
|
|
|
|
|
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
|
- renderer.toneMappingExposure = 1;
|
|
|
+ renderer.outputEncoding = THREE.sRGBEncoding;
|
|
|
|
|
|
- //
|
|
|
+ //
|
|
|
|
|
|
- renderer.outputEncoding = THREE.sRGBEncoding;
|
|
|
+ var pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
|
+ pmremGenerator.compileEquirectangularShader();
|
|
|
|
|
|
- //
|
|
|
+ //
|
|
|
|
|
|
- var pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
|
- pmremGenerator.compileEquirectangularShader();
|
|
|
+ stats = new Stats();
|
|
|
+ container.appendChild( stats.dom );
|
|
|
|
|
|
- //
|
|
|
+ // EVENTS
|
|
|
|
|
|
- stats = new Stats();
|
|
|
- container.appendChild( stats.dom );
|
|
|
+ new OrbitControls( camera, renderer.domElement );
|
|
|
|
|
|
- // EVENTS
|
|
|
+ window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
|
|
- var controls = new OrbitControls( camera, renderer.domElement );
|
|
|
+ }
|
|
|
|
|
|
- window.addEventListener( 'resize', onWindowResize, false );
|
|
|
+ //
|
|
|
|
|
|
- }
|
|
|
+ function onWindowResize() {
|
|
|
|
|
|
- //
|
|
|
+ var width = window.innerWidth;
|
|
|
+ var height = window.innerHeight;
|
|
|
|
|
|
- function onWindowResize() {
|
|
|
+ camera.aspect = width / height;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
|
|
|
- var width = window.innerWidth;
|
|
|
- var height = window.innerHeight;
|
|
|
+ renderer.setSize( width, height );
|
|
|
|
|
|
- camera.aspect = width / height;
|
|
|
- camera.updateProjectionMatrix();
|
|
|
+ }
|
|
|
|
|
|
- renderer.setSize( width, height );
|
|
|
+ //
|
|
|
|
|
|
- }
|
|
|
+ function animate() {
|
|
|
|
|
|
- //
|
|
|
+ requestAnimationFrame( animate );
|
|
|
|
|
|
- function animate() {
|
|
|
+ render();
|
|
|
|
|
|
- requestAnimationFrame( animate );
|
|
|
+ stats.update();
|
|
|
|
|
|
- render();
|
|
|
+ }
|
|
|
|
|
|
- stats.update();
|
|
|
+ function render() {
|
|
|
|
|
|
- }
|
|
|
+ var timer = Date.now() * 0.00025;
|
|
|
|
|
|
- function render() {
|
|
|
+ particleLight.position.x = Math.sin( timer * 7 ) * 300;
|
|
|
+ particleLight.position.y = Math.cos( timer * 5 ) * 400;
|
|
|
+ particleLight.position.z = Math.cos( timer * 3 ) * 300;
|
|
|
|
|
|
- var timer = Date.now() * 0.00025;
|
|
|
+ for ( var i = 0; i < group.children.length; i ++ ) {
|
|
|
|
|
|
- particleLight.position.x = Math.sin( timer * 7 ) * 300;
|
|
|
- particleLight.position.y = Math.cos( timer * 5 ) * 400;
|
|
|
- particleLight.position.z = Math.cos( timer * 3 ) * 300;
|
|
|
+ var child = group.children[ i ];
|
|
|
+ child.rotation.y += 0.005;
|
|
|
|
|
|
- for ( var i = 0; i < group.children.length; i ++ ) {
|
|
|
+ }
|
|
|
|
|
|
- var child = group.children[ i ];
|
|
|
- child.rotation.y += 0.005;
|
|
|
+ renderer.render( scene, camera );
|
|
|
|
|
|
}
|
|
|
|
|
|
- renderer.render( scene, camera );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- </script>
|
|
|
-</body>
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
</html>
|