One object is corrupting my entire scene.
All textures turn solid black. I found the bad object. The error occurring is dependent on the values in it’s color attribute (u16_norm) AND the normal attribute (f32) on the geometry. Change those values and the error resolves. How can I debug further?
The object has a complex shader, otherwise I’d share. But maybe shader math using normal and color is the cause?
displace.xyz += normal * noise2(2404.0 + ow.xz) * color.g * force;
// Initialization
const renderTarget = new WebGLCubeRenderTarget(dim, { type: HalfFloatType, });
const cubeCamera = new CubeCamera(1, 20000, renderTarget)
scene.environment = renderTarget.texture;
The error is conditional on and occurs exactly when calling:
cubeCamera.position.copy(cameraPosition);
cubeCamera.update(renderer, scene);
Everything is fine when the object is just existing in the scene, until I update the cube camera and then the whole scene goes black. Not sure how to proceed.
The error can be prevented by removing the line from below:
scene.environment = t.texture;
This suggests an error exists in the env map produced by PMREMGenerator.
const cubeRenderTarget = new WebGLCubeRenderTarget(256, {
type: HalfFloatType
});
const pmremGen = new PMREMGenerator(renderer);
// Before each render, do:
loop.beforeRender = () => {
camera.getWorldPosition(cameraWorldPos);
cubeCamera.position.copy(cameraWorldPos);
cubeCamera.update(renderer, scene);
renderer.setRenderTarget(null);
const t = pmremGen.fromCubemap(cubeRenderTarget.texture);
t.texture.needsPMREMUpdate = false;
scene.environment = t.texture;
}
This sounds super familiar… I might have heard someone having the same problem this week…
CubeCamera does renders via 6 separate camera renders. Sometimes we have in our code, meshes or objects with custom shaders, that don’t interact well w the cubecamera… and cause it to render black to the entire map… and if the envmap of your scene is black… but idk. The fact that you’ve isolated it to one of your objects, reminds me of that scenario… Also by default the cubeCamera is at 0,0,0, and sometimes stray objects or instnaces can end up at 0,0,0, and screw up the cameras view…
Any progress ?
Yea, previously I noticed in my replacement for <project_vertex>
, if I remove this line, it prevents the issue:
displace.xyz += normal * noise(...) * color.g;
Not a great solution because I need to displace the vertices still. But I just figured out that displace value was being used incorrectly. It was used to modify mvPosition
. Instead it should be modifying transformed
. Now there is no issue occurring with everything turns black.
Something downstream in the shader after <project_vertex>
must have been using the mvPosition
value. Visually, everything looks fine in both cases, but rendering with cube camera and then everything turning black says something must have been wrong with the first code.