An object in my scene has a material that’s showing a texture never supplied to it - it’s showing a texture from a separate, unrelated object/material.
I render the scene to a cube render target, then assign:
const obj = new Mesh(geo, material);
material.map = rt.texture
material.needsUpdate = true
I captured a similar effect in this test below:
You can see that the displayed texture is updating at a fixed rate as expected, but as the camera zooms, the texture on the cube randomly switches to something else. Why is this happening?
https://codesandbox.io/p/sandbox/pensive-moon-r8fm9c
Are you using .onBeforeRender anywhere ? It looks like it’s happening due to frustum culling or smth.
See if setting . frustumCalled=false on all meshed makes the problem stop . If so.. perhaps some bounding boxes aren’t set up right.
Before rendering I do:
// cube-camera-utils.js
camera.getWorldPosition(cameraWorldPos);
cubeCamera.position.copy(cameraWorldPos);
cubeCamera.update(renderer, scene);
Otherwise, it’s pretty straightforward, and .frustumCulled = false
on the meshes doesn’t change anything. It does seem to depend on the camera’s view frustum near plane. If I increase the near value, I can trigger the effect from a farther away zoom.
I also found out if I comment out const SkyController =
(which adds the sort of background cube that we’re inside of, with the plants on the faces) - if I comment that out, now at the same zoom, I get blinking instead of just a texture swap.
Assigning the map to the render target texture:
material.map = rt.texture
results in
WebGL: INVALID_OPERATION: bindTexture: textures can not be used with multiple targets
, although it still displays, as the videos above show.
Setting material.envMap = rt.texture
instead, produces no error and I cannot cause the issue to manifest at all.
Why does using map cause an error though? And how does it just put a random texture on the cube…
This example is really convoluted and it has an effect composer as well, which renders to a lot of targets. The issue is definitely triggered by this sphere not rendering, but i cant even find in which file it is to see whats going on. If you do as @manthrax suggests, it should at least still be rendering that object.
1 Like
Can you screenshot what you’re seeing?
There are three objects.
(1) a sphere rendering as expected in front of the camera
(2) a large cube acting like a “room” that the camera is inside of (it has a plant image on each inner face)
(3) a cube above the sphere which is displaying the render target, we can call the RT cube.
index.js
- adds the sphere to the scene
sky-ctrl.js
- adds the “room” cube to the scene
cube-camera-utils.js
- adds the RT cube to the scene, and updates the texture via cubeCamera.update()