|
33 | 33 | import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
34 | 34 | import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; |
35 | 35 |
|
36 | | - import { pass, normalPass, uniform, pixelation } from 'three/tsl'; |
| 36 | + import { pass, normalPass, uniform, pixelation, pixelationPass } from 'three/tsl'; |
37 | 37 |
|
38 | 38 | let camera, scene, renderer, composer, crystalMesh, clock; |
39 | 39 | let gui, params; |
|
68 | 68 | function addBox( boxSideLength, x, z, rotation ) { |
69 | 69 |
|
70 | 70 | const mesh = new THREE.Mesh( new THREE.BoxGeometry( boxSideLength, boxSideLength, boxSideLength ), boxMaterial ); |
71 | | - mesh.castShadow = true; |
72 | | - mesh.receiveShadow = true; |
| 71 | + mesh.castShadow = false; |
| 72 | + mesh.receiveShadow = false; |
73 | 73 | mesh.rotation.y = rotation; |
74 | 74 | mesh.position.y = boxSideLength / 2; |
75 | 75 | mesh.position.set( x, boxSideLength / 2 + .0001, z ); |
|
101 | 101 | specular: 0xffffff |
102 | 102 | } ) |
103 | 103 | ); |
104 | | - crystalMesh.receiveShadow = true; |
105 | | - crystalMesh.castShadow = true; |
| 104 | + crystalMesh.receiveShadow = false; |
| 105 | + crystalMesh.castShadow = false; |
106 | 106 | scene.add( crystalMesh ); |
107 | 107 |
|
108 | 108 | // lights |
|
111 | 111 |
|
112 | 112 | const directionalLight = new THREE.DirectionalLight( 0xfffecd, 1.5 ); |
113 | 113 | directionalLight.position.set( 100, 100, 100 ); |
114 | | - directionalLight.castShadow = true; |
| 114 | + directionalLight.castShadow = false; |
115 | 115 | directionalLight.shadow.mapSize.set( 2048, 2048 ); |
116 | 116 | scene.add( directionalLight ); |
117 | 117 |
|
|
120 | 120 | const target = spotLight.target; |
121 | 121 | scene.add( target ); |
122 | 122 | target.position.set( 0, 0, 0 ); |
123 | | - spotLight.castShadow = true; |
| 123 | + spotLight.castShadow = false; |
124 | 124 | scene.add( spotLight ); |
125 | 125 |
|
126 | | - renderer = new THREE.WebGPURenderer(); |
| 126 | + renderer = new THREE.WebGPURenderer({ antialias: false }); |
127 | 127 | renderer.shadowMap.enabled = true; |
128 | 128 | //renderer.setPixelRatio( window.devicePixelRatio ); |
129 | 129 | renderer.setSize( window.innerWidth, window.innerHeight ); |
130 | 130 | renderer.setAnimationLoop( animate ); |
131 | 131 | document.body.appendChild( renderer.domElement ); |
132 | 132 |
|
133 | 133 | const effectController = { |
134 | | - pixelSize: 14, |
| 134 | + pixelSize: uniform(14), |
135 | 135 | normalEdgeStrength: uniform(0.3), |
136 | 136 | depthEdgeStrength: uniform(0.4) |
137 | 137 | } |
138 | 138 |
|
139 | 139 | composer = new THREE.PostProcessing( renderer ); |
140 | 140 |
|
141 | | - const scenePass = normalPass( scene, camera ); |
142 | | - const scenePassColor = scenePass.getTextureNode(); |
143 | | - const scenePassDepth = scenePass.getTextureDepthNode(); |
144 | | - const scenePassNormal = scenePass.getTextureNormalNode(); |
145 | | - const pixelationPass = scenePassColor.pixelation( scenePassDepth, scenePassNormal, 4, effectController.normalEdgeStrength, effectController.depthEdgeStrength); |
146 | | - composer.outputNode = pixelationPass; |
| 141 | + const scenePass = pixelationPass( scene, camera, effectController.pixelSize, effectController.normalEdgeStrength, effectController.depthEdgeStrength ); |
| 142 | + composer.outputNode = scenePass; |
147 | 143 | window.addEventListener( 'resize', onWindowResize ); |
148 | 144 |
|
149 | 145 | const controls = new OrbitControls( camera, renderer.domElement ); |
|
152 | 148 | // gui |
153 | 149 |
|
154 | 150 | gui = new GUI(); |
155 | | - gui.add( pixelationPass.pixelSizeNode, 'value', 0, 14, 1).name( 'Pixel Size' ); |
| 151 | + gui.add( effectController.pixelSize, 'value', 0, 14, 1).name( 'Pixel Size' ); |
156 | 152 | gui.add( effectController.normalEdgeStrength, 'value', 0, 2, 0.05 ).name( 'Normal Edge Strength' ); |
157 | 153 | gui.add( effectController.depthEdgeStrength, 'value', 0, 1, 0.05 ).name( 'Depth Edge Strength' ); |
158 | 154 |
|
|
0 commit comments