|
32 | 32 | <script type="module"> |
33 | 33 |
|
34 | 34 | import * as THREE from 'three/webgpu'; |
35 | | - import { pass, mrt, output, normalView, metalness, blendColor, screenUV, color, sample, directionToColor, colorToDirection } from 'three/tsl'; |
| 35 | + import { pass, mrt, output, normalView, metalness, roughness, blendColor, screenUV, color, sample, directionToColor, colorToDirection, vec2 } from 'three/tsl'; |
36 | 36 | import { ssr } from 'three/addons/tsl/display/SSRNode.js'; |
37 | 37 | import { smaa } from 'three/addons/tsl/display/SMAANode.js'; |
38 | 38 |
|
|
75 | 75 |
|
76 | 76 | if ( object.material ) { |
77 | 77 |
|
| 78 | + if ( object.material.name === 'Lense_Casing' ) { |
| 79 | + |
| 80 | + object.material.transparent = true; |
| 81 | + |
| 82 | + } |
| 83 | + |
78 | 84 | // Avoid overdrawing |
79 | 85 | object.material.side = THREE.FrontSide; |
80 | 86 |
|
|
113 | 119 | scenePass.setMRT( mrt( { |
114 | 120 | output: output, |
115 | 121 | normal: directionToColor( normalView ), |
116 | | - metalness: metalness |
| 122 | + metalrough: vec2( metalness, roughness ) |
117 | 123 | } ) ); |
118 | 124 |
|
119 | 125 | const scenePassColor = scenePass.getTextureNode( 'output' ); |
120 | 126 | const scenePassNormal = scenePass.getTextureNode( 'normal' ); |
121 | 127 | const scenePassDepth = scenePass.getTextureNode( 'depth' ); |
122 | | - const scenePassMetalness = scenePass.getTextureNode( 'metalness' ); |
| 128 | + const scenePassMetalRough = scenePass.getTextureNode( 'metalrough' ); |
123 | 129 |
|
124 | 130 | // optimization bandwidth packing the normals and reducing the texture precision if possible |
125 | 131 |
|
126 | | - const metalnessTexture = scenePass.getTexture( 'metalness' ); |
127 | | - metalnessTexture.type = THREE.UnsignedByteType; |
128 | | - |
129 | 132 | const normalTexture = scenePass.getTexture( 'normal' ); |
130 | 133 | normalTexture.type = THREE.UnsignedByteType; |
131 | 134 |
|
| 135 | + const metalRoughTexture = scenePass.getTexture( 'metalrough' ); |
| 136 | + metalRoughTexture.type = THREE.UnsignedByteType; |
| 137 | + |
132 | 138 | const customNormal = sample( ( uv ) => { |
133 | 139 |
|
134 | 140 | return colorToDirection( scenePassNormal.sample( uv ) ); |
135 | 141 |
|
136 | 142 | } ); |
137 | 143 |
|
| 144 | + const customMetalness = sample( ( uv ) => { |
| 145 | + |
| 146 | + return scenePassMetalRough.sample( uv ).r; |
| 147 | + |
| 148 | + } ); |
| 149 | + |
138 | 150 | // |
139 | 151 |
|
140 | | - ssrPass = ssr( scenePassColor, scenePassDepth, customNormal, scenePassMetalness, camera ); |
| 152 | + ssrPass = ssr( scenePassColor, scenePassDepth, customNormal, customMetalness, camera ); |
141 | 153 | ssrPass.resolutionScale = 1.0; |
142 | 154 |
|
143 | 155 | // blend SSR over beauty |
144 | | - |
145 | | - const outputNode = smaa( blendColor( scenePassColor, ssrPass ) ); |
| 156 | + |
| 157 | + const outputNode = smaa( blendColor( scenePassColor, ssrPass.mul( scenePassMetalRough.g.oneMinus() ) ) ); |
146 | 158 |
|
147 | 159 | postProcessing.outputNode = outputNode; |
148 | 160 |
|
|
0 commit comments