|
28 | 28 | <script type="module"> |
29 | 29 |
|
30 | 30 | import * as THREE from 'three/webgpu'; |
31 | | - import { pass, mrt, output, normalView, diffuseColor, velocity, add, vec3, vec4 } from 'three/tsl'; |
| 31 | + import { pass, mrt, output, normalView, diffuseColor, velocity, add, vec3, vec4, directionToColor, colorToDirection, sample } from 'three/tsl'; |
32 | 32 | import { ssgi } from 'three/addons/tsl/display/SSGINode.js'; |
33 | 33 | import { traa } from 'three/addons/tsl/display/TRAANode.js'; |
34 | 34 |
|
|
79 | 79 | scenePass.setMRT( mrt( { |
80 | 80 | output: output, |
81 | 81 | diffuseColor: diffuseColor, |
82 | | - normal: normalView, |
| 82 | + normal: directionToColor( normalView ), |
83 | 83 | velocity: velocity |
84 | 84 | } ) ); |
85 | 85 |
|
|
89 | 89 | const scenePassNormal = scenePass.getTextureNode( 'normal' ); |
90 | 90 | const scenePassVelocity = scenePass.getTextureNode( 'velocity' ); |
91 | 91 |
|
| 92 | + // bandwidth optimization |
| 93 | + |
| 94 | + const diffuseTexture = scenePass.getTexture( 'diffuseColor' ); |
| 95 | + diffuseTexture.type = THREE.UnsignedByteType; |
| 96 | + |
| 97 | + const normalTexture = scenePass.getTexture( 'normal' ); |
| 98 | + normalTexture.type = THREE.UnsignedByteType; |
| 99 | + |
| 100 | + const sceneNormal = sample( ( uv ) => { |
| 101 | + |
| 102 | + return colorToDirection( scenePassNormal.sample( uv ) ); |
| 103 | + |
| 104 | + } ); |
| 105 | + |
92 | 106 | // gi |
93 | 107 |
|
94 | | - const giPass = ssgi( scenePassColor, scenePassDepth, scenePassNormal, camera ); |
| 108 | + const giPass = ssgi( scenePassColor, scenePassDepth, sceneNormal, camera ); |
95 | 109 | giPass.sliceCount.value = 2; |
96 | 110 | giPass.stepCount.value = 8; |
97 | 111 |
|
|
100 | 114 | const gi = giPass.rgb; |
101 | 115 | const ao = giPass.a; |
102 | 116 |
|
103 | | - const compositePass = vec4( add ( scenePassColor.rgb.mul( ao ), ( scenePassDiffuse.rgb.mul( gi ) ) ), scenePassColor.a ); |
| 117 | + const compositePass = vec4( add( scenePassColor.rgb.mul( ao ), ( scenePassDiffuse.rgb.mul( gi ) ) ), scenePassColor.a ); |
104 | 118 |
|
105 | 119 | // traa |
106 | 120 |
|
|
133 | 147 |
|
134 | 148 | const gui = new GUI(); |
135 | 149 | gui.title( 'SSGI settings' ); |
136 | | - let outputDropdown = gui.add( params, 'output', types ); |
137 | | - outputDropdown.onChange( value => { |
138 | | - |
| 150 | + gui.add( params, 'output', types ).onChange( updatePostprocessing ); |
| 151 | + gui.add( giPass.sliceCount, 'value', 1, 4 ).step( 1 ).name( 'slice count' ); |
| 152 | + gui.add( giPass.stepCount, 'value', 1, 32 ).step( 1 ).name( 'step count' ); |
| 153 | + gui.add( giPass.radius, 'value', 1, 25 ).name( 'radius' ); |
| 154 | + gui.add( giPass.expFactor, 'value', 1, 3 ).name( 'exp factor' ); |
| 155 | + gui.add( giPass.thickness, 'value', 0.01, 10 ).name( 'thickness' ); |
| 156 | + gui.add( giPass.backfaceLighting, 'value', 0, 1 ).name( 'backface lighting' ); |
| 157 | + gui.add( giPass.aoIntensity, 'value', 0, 4 ).name( 'AO intenstiy' ); |
| 158 | + gui.add( giPass.giIntensity, 'value', 0, 100 ).name( 'GI intenstiy' ); |
| 159 | + gui.add( giPass.useLinearThickness, 'value' ).name( 'use linear thickness' ); |
| 160 | + gui.add( giPass.useScreenSpaceSampling, 'value' ).name( 'screen-space sampling' ); |
| 161 | + gui.add( giPass, 'useTemporalFiltering' ).name( 'temporal filtering' ).onChange( updatePostprocessing ); |
| 162 | + |
| 163 | + function updatePostprocessing( value ) { |
| 164 | + |
139 | 165 | if ( value === 1 ) { |
140 | 166 |
|
141 | 167 | postProcessing.outputNode = vec4( vec3( ao ), 1 ); |
|
156 | 182 |
|
157 | 183 | postProcessing.needsUpdate = true; |
158 | 184 |
|
159 | | - } ); |
160 | | - gui.add( giPass.sliceCount, 'value', 1, 4 ).step( 1 ).name( 'slice count' ); |
161 | | - gui.add( giPass.stepCount, 'value', 1, 32 ).step( 1 ).name( 'step count' ); |
162 | | - gui.add( giPass.radius, 'value', 1, 25 ).name( 'radius' ); |
163 | | - gui.add( giPass.expFactor, 'value', 1, 3 ).name( 'exp factor' ); |
164 | | - gui.add( giPass.thickness, 'value', 0.01, 10 ).name( 'thickness' ); |
165 | | - gui.add( giPass.backfaceLighting, 'value', 0, 1 ).name( 'backface lighting' ); |
166 | | - gui.add( giPass.aoIntensity, 'value', 0, 4 ).name( 'AO intenstiy' ); |
167 | | - gui.add( giPass.giIntensity, 'value', 0, 100 ).name( 'GI intenstiy' ); |
168 | | - gui.add( giPass.useLinearThickness, 'value' ).name( 'use linear thickness' ); |
169 | | - gui.add( giPass.useScreenSpaceSampling, 'value' ).name( 'screen-space sampling' ); |
170 | | - gui.add( giPass, 'useTemporalFiltering' ).name( 'temporal filtering' ).onChange( outputDropdown._onChange ); |
| 185 | + |
| 186 | + } |
| 187 | + |
| 188 | + |
171 | 189 | } |
172 | 190 |
|
173 | 191 | function onWindowResize() { |
|
0 commit comments