|
25 | 25 | <script type="module">
|
26 | 26 |
|
27 | 27 | import * as THREE from 'three';
|
28 |
| - import { color, linearDepth, viewportLinearDepth, viewportSharedTexture, textureBicubic, viewportMipTexture, screenUV, checker, uv, modelScale } from 'three/tsl'; |
| 28 | + import { color, positionWorld, linearDepth, viewportLinearDepth, viewportSharedTexture, screenUV, hue, time, checker, uv, modelScale } from 'three/tsl'; |
| 29 | + import { hashBlur } from 'three/addons/tsl/display/hashBlur.js'; |
29 | 30 |
|
30 | 31 | import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
31 | 32 |
|
|
44 | 45 | camera.position.set( 3, 2, 3 );
|
45 | 46 |
|
46 | 47 | scene = new THREE.Scene();
|
47 |
| - scene.background = new THREE.Color( 0x777777 ); |
| 48 | + scene.backgroundNode = hue( screenUV.y.mix( color( 0x66bbff ), color( 0x4466ff ) ), time.mul( 0.1 ) ); |
48 | 49 | camera.lookAt( 0, 1, 0 );
|
49 | 50 |
|
50 | 51 | clock = new THREE.Clock();
|
51 | 52 |
|
52 |
| - const light = new THREE.PointLight( 0xffffff, 50 ); |
53 |
| - camera.add( light ); |
54 |
| - scene.add( camera ); |
55 |
| - |
56 |
| - const ambient = new THREE.AmbientLight( 0x4466ff, 1 ); |
| 53 | + const ambient = new THREE.AmbientLight( 0xffffff, 2 ); |
57 | 54 | scene.add( ambient );
|
58 | 55 |
|
59 | 56 | // model
|
|
79 | 76 | const depthDistance = viewportLinearDepth.distance( linearDepth() );
|
80 | 77 |
|
81 | 78 | const depthAlphaNode = depthDistance.oneMinus().smoothstep( .90, 2 ).mul( 10 ).saturate();
|
82 |
| - const depthBlurred = textureBicubic( viewportMipTexture(), depthDistance.smoothstep( 0, .6 ).mul( 40 * 5 ).clamp( 0, 5 ) ); |
| 79 | + const depthBlurred = hashBlur( viewportSharedTexture(), depthDistance.smoothstep( 0, .6 ).mul( 40 ).clamp().mul( .1 ) ); |
83 | 80 |
|
84 | 81 | const blurredBlur = new THREE.MeshBasicNodeMaterial();
|
85 |
| - blurredBlur.backdropNode = depthBlurred.add( depthAlphaNode.mix( color( 0x0066ff ), 0 ) ); |
| 82 | + blurredBlur.backdropNode = depthBlurred.add( depthAlphaNode.mix( color( 0x003399 ).mul( .3 ), 0 ) ); |
86 | 83 | blurredBlur.transparent = true;
|
87 | 84 | blurredBlur.side = THREE.DoubleSide;
|
88 | 85 |
|
89 |
| - const volumeMaterial = new THREE.MeshBasicNodeMaterial(); |
90 |
| - volumeMaterial.colorNode = color( 0x0066ff ); |
91 |
| - volumeMaterial.backdropNode = viewportSharedTexture(); |
92 |
| - volumeMaterial.backdropAlphaNode = depthAlphaNode; |
93 |
| - volumeMaterial.transparent = true; |
94 |
| - volumeMaterial.side = THREE.DoubleSide; |
95 |
| - |
96 | 86 | const depthMaterial = new THREE.MeshBasicNodeMaterial();
|
97 | 87 | depthMaterial.backdropNode = depthAlphaNode;
|
98 | 88 | depthMaterial.transparent = true;
|
99 | 89 | depthMaterial.side = THREE.DoubleSide;
|
100 | 90 |
|
101 |
| - const bicubicMaterial = new THREE.MeshBasicNodeMaterial(); |
102 |
| - bicubicMaterial.backdropNode = textureBicubic( viewportMipTexture(), 5 ); // @TODO: Move to alpha value [ 0, 1 ] |
103 |
| - bicubicMaterial.backdropAlphaNode = checker( uv().mul( 3 ).mul( modelScale.xy ) ); |
104 |
| - bicubicMaterial.opacityNode = bicubicMaterial.backdropAlphaNode; |
105 |
| - bicubicMaterial.transparent = true; |
106 |
| - bicubicMaterial.side = THREE.DoubleSide; |
| 91 | + const checkerMaterial = new THREE.MeshBasicNodeMaterial(); |
| 92 | + checkerMaterial.backdropNode = hashBlur( viewportSharedTexture(), .05 ); |
| 93 | + checkerMaterial.backdropAlphaNode = checker( uv().mul( 3 ).mul( modelScale.xy ) ); |
| 94 | + checkerMaterial.opacityNode = checkerMaterial.backdropAlphaNode; |
| 95 | + checkerMaterial.transparent = true; |
| 96 | + checkerMaterial.side = THREE.DoubleSide; |
107 | 97 |
|
108 | 98 | const pixelMaterial = new THREE.MeshBasicNodeMaterial();
|
109 | 99 | pixelMaterial.backdropNode = viewportSharedTexture( screenUV.mul( 100 ).floor().div( 100 ) );
|
110 | 100 | pixelMaterial.transparent = true;
|
111 | 101 |
|
112 | 102 | // box / floor
|
113 | 103 |
|
114 |
| - const box = new THREE.Mesh( new THREE.BoxGeometry( 2, 2, 2 ), volumeMaterial ); |
| 104 | + const box = new THREE.Mesh( new THREE.BoxGeometry( 2, 2, 2 ), blurredBlur ); |
115 | 105 | box.position.set( 0, 1, 0 );
|
| 106 | + box.renderOrder = 1; |
116 | 107 | scene.add( box );
|
117 | 108 |
|
118 |
| - const floor = new THREE.Mesh( new THREE.BoxGeometry( 1.99, .01, 1.99 ), new THREE.MeshBasicNodeMaterial( { color: 0x333333 } ) ); |
| 109 | + const floor = new THREE.Mesh( new THREE.BoxGeometry( 5, .01, 5 ), new THREE.MeshBasicNodeMaterial( { |
| 110 | + color: 0xff6600, |
| 111 | + opacityNode: positionWorld.xz.distance( 0 ).oneMinus().clamp(), |
| 112 | + transparent: true, |
| 113 | + depthWrite: false |
| 114 | + } ) ); |
119 | 115 | floor.position.set( 0, 0, 0 );
|
120 | 116 | scene.add( floor );
|
121 | 117 |
|
|
125 | 121 | renderer.setPixelRatio( window.devicePixelRatio );
|
126 | 122 | renderer.setSize( window.innerWidth, window.innerHeight );
|
127 | 123 | renderer.setAnimationLoop( animate );
|
128 |
| - renderer.toneMapping = THREE.LinearToneMapping; |
129 |
| - renderer.toneMappingExposure = 0.2; |
| 124 | + renderer.toneMapping = THREE.NeutralToneMapping; |
| 125 | + renderer.toneMappingExposure = .9; |
130 | 126 | document.body.appendChild( renderer.domElement );
|
131 | 127 |
|
132 | 128 | const controls = new OrbitControls( camera, renderer.domElement );
|
|
139 | 135 |
|
140 | 136 | const materials = {
|
141 | 137 | 'blurred': blurredBlur,
|
142 |
| - 'volume': volumeMaterial, |
143 | 138 | 'depth': depthMaterial,
|
144 |
| - 'bicubic': bicubicMaterial, |
| 139 | + 'checker': checkerMaterial, |
145 | 140 | 'pixel': pixelMaterial
|
146 | 141 | };
|
147 | 142 |
|
|
0 commit comments