Skip to content

Commit b18485f

Browse files
committed
PMREMGenerator now appropriately flips cube textures from WebGLRenderTargetCube. Fixes #15301
1 parent a332158 commit b18485f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/js/pmrem/PMREMGenerator.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ THREE.PMREMGenerator = function ( sourceTexture, samplesPerLevel, resolution ) {
1717
this.resolution = ( resolution !== undefined ) ? resolution : 256; // NODE: 256 is currently hard coded in the glsl code for performance reasons
1818
this.samplesPerLevel = ( samplesPerLevel !== undefined ) ? samplesPerLevel : 16;
1919

20-
var monotonicEncoding = ( sourceTexture.encoding === THREE.LinearEncoding ) ||
21-
( sourceTexture.encoding === THREE.GammaEncoding ) || ( sourceTexture.encoding === THREE.sRGBEncoding );
20+
var monotonicEncoding = ( this.sourceTexture.encoding === THREE.LinearEncoding ) ||
21+
( this.sourceTexture.encoding === THREE.GammaEncoding ) || ( this.sourceTexture.encoding === THREE.sRGBEncoding );
2222

2323
this.sourceTexture.minFilter = ( monotonicEncoding ) ? THREE.LinearFilter : THREE.NearestFilter;
2424
this.sourceTexture.magFilter = ( monotonicEncoding ) ? THREE.LinearFilter : THREE.NearestFilter;
@@ -84,6 +84,7 @@ THREE.PMREMGenerator.prototype = {
8484
update: function ( renderer ) {
8585

8686
this.shader.uniforms[ 'envMap' ].value = this.sourceTexture;
87+
this.shader.uniforms[ 'tFlip' ].value = ( this.sourceTexture.isCubeTexture ) ? 1 : -1;
8788
this.shader.envMap = this.sourceTexture;
8889

8990
var gammaInput = renderer.gammaInput;
@@ -151,6 +152,7 @@ THREE.PMREMGenerator.prototype = {
151152
"envMap": { value: null },
152153
"queryScale": { value: new THREE.Vector3( 1, 1, 1 ) },
153154
"testColor": { value: new THREE.Vector3( 1, 1, 1 ) },
155+
"tFlip": { value: -1 },
154156
},
155157

156158
vertexShader:
@@ -169,6 +171,7 @@ THREE.PMREMGenerator.prototype = {
169171
uniform float mapSize;\n\
170172
uniform vec3 testColor;\n\
171173
uniform vec3 queryScale;\n\
174+
uniform int tFlip;\n\
172175
\n\
173176
float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\
174177
float a = ggxRoughness + 0.0001;\n\
@@ -239,6 +242,7 @@ THREE.PMREMGenerator.prototype = {
239242
} else {\n\
240243
sampleDirection = vec3(-uv.x, -uv.y, -1.0);\n\
241244
}\n\
245+
sampleDirection.x *= float(tFlip);\n\
242246
mat3 vecSpace = matrixFromVector(normalize(sampleDirection * queryScale));\n\
243247
vec3 rgbColor = vec3(0.0);\n\
244248
const int NumSamples = SAMPLES_PER_LEVEL;\n\
@@ -251,8 +255,9 @@ THREE.PMREMGenerator.prototype = {
251255
vect = ImportanceSampleGGX(vec2(float(i) / float(NumSamples), r), vecSpace, roughness);\n\
252256
float dotProd = dot(vect, normalize(sampleDirection));\n\
253257
weight += dotProd;\n\
254-
vec3 color = envMapTexelToLinear(textureCube(envMap,vect)).rgb;\n\
255-
rgbColor.rgb += color;\n\
258+
vec4 color = textureCube(envMap, vect.xyz);\n\
259+
vec3 mapped = envMapTexelToLinear(color).rgb;\n\
260+
rgbColor.rgb += mapped;\n\
256261
}\n\
257262
rgbColor /= float(NumSamples);\n\
258263
//rgbColor = testColorMap( roughness ).rgb;\n\

0 commit comments

Comments
 (0)