Following a few examples, I was trying to use PMREMGenerator that seems to produce better results for lightprobing stuff.
On latest THREE release seems that CubeCamera and PMREM produce wrong results for envmap associated with a mesh (…or I’m using them the wrong way)
The mesh used in this test and its normals are correct.
Relevant code:
pmremGenerator = new THREE.PMREMGenerator(renderer);
pmremGenerator.compileCubemapShader();
CCtarget = new THREE.WebGLCubeRenderTarget( 128, {
format: THREE.RGBEFormat,
generateMipmaps: true,
minFilter: THREE.LinearMipmapLinearFilter,
encoding: THREE.sRGBEncoding
});
CC = new THREE.CubeCamera( this._near, this._far, CCtarget );
CC.position.copy( probeLocation ); // green dot location
CC.update( renderer, scene );
envtex = pmremGenerator.fromCubemap(CCtarget.texture).texture; // the envmap associated w/ mesh
The issues seems that final enmap looks in the correct location but “mirrored” - as you can see in the screenshot (green and blue reflections are wrong). Green dot represents the CubeCamera location.
On the other hand, pmremGenerator.fromScene produces correct results, although the capture is preformed in the origin, and it seems I have no control on shot location.
What could be the issue? I’m trying literally everything (including flipping final envtex, but no change)
This is another (simpler) test with just a PBR sphere, two quads and a panoramic content (bigger textured sphere) that confirms pmremGenerator.fromCubemap(CCtarget.texture).texture returns a wrong (mirrored) envmap assigned to the mesh
I tried a lot of things, including mirroring the CubeCamera (CC.scale.x = -1), but indeed it does not work.
The only (ugly) workaround so far is mirroring the entire scene along x-axis before the CC.update( renderer, scene ), while properly transforming CubeCamera location.
Anyone has encountered something similar?
Is there a cleaner solution to mirror or fix the returned envmap from PMREMs ?
Not yet unfortunately.
I’m using the hack of mirroring the scene along x-axis before the CubeCamera update. I suppose it is something (maybe simple) to fix in the GLSL shader(s) but I dont know exactly where
I tried but looks like pmremGenerator.fromScene voids any transform (e.g. scene.position.set(…) ) and captures from the absolute origin regardless.
I confirm this issue persists also in r136
EDIT
regarding fromScene(), I possibly found the reason by trial-error: it requires a render call after transform and before fromScene call. So my solution at the moment looks something like this:
scene.position.set(-probeLocation.x, -probeLocation.y, -probeLocation.z ); // translate to match probe location
render();
envtex = pmremGenerator.fromScene(scene, 0, this._near, this._far).texture;
scene.position.set(0,0,0); // reset
The mirroring issue using fromCubemap() instead, still persists with latest release.
I also experience some weird behavior regarding envmaps, since r131 and the changes it brought to StandardMaterial (which I may post separately later)…
@Mugen87 Can you confirm whether what the OP talks about is indeed a bug?
I think this actually make sense. My anim loop was calling a routine for capturing 3D scene from all probes: problem is the render call was after that routine, thus after the transform resets. Maybe this could be possibly improved if the pmremGenerator.fromScene() has a direct call (or option) to render before performing the capture.
So the problem is mainly on pmremGenerator.fromCubemap() that still exhibits mirrored capture on x axis (see sphere sample screenshot)