|
5 | 5 | SphericalHarmonics3, |
6 | 6 | Vector3, |
7 | 7 | SRGBColorSpace, |
8 | | - NoColorSpace |
| 8 | + NoColorSpace, |
| 9 | + HalfFloatType, |
| 10 | + DataUtils |
9 | 11 | } from 'three'; |
10 | 12 |
|
11 | 13 | class LightProbeGenerator { |
@@ -140,18 +142,50 @@ class LightProbeGenerator { |
140 | 142 | const sh = new SphericalHarmonics3(); |
141 | 143 | const shCoefficients = sh.coefficients; |
142 | 144 |
|
| 145 | + const dataType = cubeRenderTarget.texture.type; |
| 146 | + |
143 | 147 | for ( let faceIndex = 0; faceIndex < 6; faceIndex ++ ) { |
144 | 148 |
|
145 | 149 | const imageWidth = cubeRenderTarget.width; // assumed to be square |
146 | | - const data = new Uint8Array( imageWidth * imageWidth * 4 ); |
| 150 | + |
| 151 | + let data; |
| 152 | + |
| 153 | + if ( dataType === HalfFloatType ) { |
| 154 | + |
| 155 | + data = new Uint16Array( imageWidth * imageWidth * 4 ); |
| 156 | + |
| 157 | + } else { |
| 158 | + |
| 159 | + // assuming UnsignedByteType |
| 160 | + |
| 161 | + data = new Uint8Array( imageWidth * imageWidth * 4 ); |
| 162 | + |
| 163 | + } |
| 164 | + |
147 | 165 | renderer.readRenderTargetPixels( cubeRenderTarget, 0, 0, imageWidth, imageWidth, data, faceIndex ); |
148 | 166 |
|
149 | 167 | const pixelSize = 2 / imageWidth; |
150 | 168 |
|
151 | 169 | for ( let i = 0, il = data.length; i < il; i += 4 ) { // RGBA assumed |
152 | 170 |
|
| 171 | + let r, g, b; |
| 172 | + |
| 173 | + if ( dataType === HalfFloatType ) { |
| 174 | + |
| 175 | + r = DataUtils.fromHalfFloat( data[ i ] ); |
| 176 | + g = DataUtils.fromHalfFloat( data[ i + 1 ] ); |
| 177 | + b = DataUtils.fromHalfFloat( data[ i + 2 ] ); |
| 178 | + |
| 179 | + } else { |
| 180 | + |
| 181 | + r = data[ i ] / 255; |
| 182 | + g = data[ i + 1 ] / 255; |
| 183 | + b = data[ i + 2 ] / 255; |
| 184 | + |
| 185 | + } |
| 186 | + |
153 | 187 | // pixel color |
154 | | - color.setRGB( data[ i ] / 255, data[ i + 1 ] / 255, data[ i + 2 ] / 255 ); |
| 188 | + color.setRGB( r, g, b ); |
155 | 189 |
|
156 | 190 | // convert to linear color space |
157 | 191 | convertColorToLinear( color, cubeRenderTarget.texture.colorSpace ); |
|
0 commit comments