|
25 | 25 | <script type="importmap"> |
26 | 26 | { |
27 | 27 | "imports": { |
28 | | - "three": "../build/three.webgpu.js", |
29 | | - "three/webgpu": "../build/three.webgpu.js", |
30 | | - "three/tsl": "../build/three.tsl.js", |
| 28 | + "three": "../src/three.webgpu.js", |
| 29 | + "three/webgpu": "../src/three.webgpu.js", |
| 30 | + "three/tsl": "../src/three.tsl.js", |
31 | 31 | "three/addons/": "./jsm/" |
32 | 32 | } |
33 | 33 | } |
|
36 | 36 | <script type="module"> |
37 | 37 |
|
38 | 38 | import * as THREE from 'three/webgpu'; |
39 | | - import { pass, color, rangeFogFactor } from 'three/tsl'; |
| 39 | + import { pass, color, rangeFogFactor, context, uv, renderOutput } from 'three/tsl'; |
40 | 40 |
|
41 | 41 | import { HDRLoader } from 'three/addons/loaders/HDRLoader.js'; |
42 | 42 |
|
|
54 | 54 | camera.position.set( - 1.8, 0.6, 2.7 ); |
55 | 55 |
|
56 | 56 | scene = new THREE.Scene(); |
| 57 | + scene.background = new THREE.Color( 0x4080cc ); |
57 | 58 |
|
58 | 59 | renderer = new THREE.WebGPURenderer( { antialias: true } ); |
59 | 60 | renderer.setPixelRatio( window.devicePixelRatio ); |
60 | 61 | renderer.setSize( window.innerWidth, window.innerHeight ); |
61 | 62 | renderer.setAnimationLoop( animate ); |
| 63 | + renderer.outputColorSpace = THREE.LinearSRGBColorSpace; |
62 | 64 | renderer.toneMapping = THREE.NoToneMapping; // apply tone mapping in post processing, instead |
63 | 65 | document.body.appendChild( renderer.domElement ); |
64 | 66 |
|
65 | | - // post processing |
| 67 | + renderer.contextNode = context( { |
66 | 68 |
|
67 | | - // render scene pass |
68 | | - const scenePass = pass( scene, camera ); |
69 | | - const scenePassViewZ = scenePass.getViewZNode(); |
| 69 | + getUV: () => { |
70 | 70 |
|
71 | | - // fog color |
72 | | - const fogColor = color( 0x4080cc ); // in sRGB color space |
| 71 | + return uv(); |
73 | 72 |
|
74 | | - // get fog factor from the scene pass context |
75 | | - // equivalent to: scene.fog = new THREE.Fog( 0x4080cc, 2.7, 4 ); |
76 | | - const fogFactor = rangeFogFactor( 2.7, 4 ).context( { getViewZ: () => scenePassViewZ } ); |
| 73 | + }, |
77 | 74 |
|
78 | | - // tone-mapped scene pass |
79 | | - const scenePassTM = scenePass.toneMapping( THREE.ACESFilmicToneMapping, 1 ); |
| 75 | + getOutput: ( node, { material } ) => { |
80 | 76 |
|
81 | | - // mix fog using fog factor and fog color |
82 | | - const compose = fogFactor.mix( scenePassTM, fogColor ); |
| 77 | + const toneMapping = material.toneMapped ? THREE.NeutralToneMapping : THREE.NoToneMapping; |
| 78 | + const outputColorSpace = THREE.SRGBColorSpace; |
83 | 79 |
|
84 | | - postProcessing = new THREE.PostProcessing( renderer ); |
85 | | - postProcessing.outputColorTransform = true; // no tone mapping will be applied, only the default color space transform |
86 | | - postProcessing.outputNode = compose; |
| 80 | + return renderOutput( node, toneMapping, outputColorSpace ); |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + } ); |
87 | 85 |
|
88 | 86 | // |
89 | 87 |
|
|
130 | 128 |
|
131 | 129 | function animate() { |
132 | 130 |
|
133 | | - postProcessing.render(); |
| 131 | + renderer.render( scene, camera ); |
134 | 132 |
|
135 | 133 | } |
136 | 134 |
|
|
0 commit comments