Minimizing cross-talk between main and embedded rendering?

@donmccurdy So, I still have not figured out a solution or a workaround for this. I’ve tried the various things you suggested with no luck.

From what I can tell, it appears to be a problem with the lighting and my custom terrain shader. Here are the details:

  • The terrain shader is based on the standard material shader, except that the color is determined by an algorithm rather than by a texture or constant color. The shader does lighting calculations by including the lights_physical_fragment, lights_fragment_begin and lights_fragment_end shader chunks. It doesn’t do anything special with lighting.
  • Only the terrain shader appears to be affected by the bug. The standard material shaders appear to work OK.
  • I’ve been using this shader for over 2 years and never noticed this problem until I started trying to do off-screen renders of the character portrait.
  • The exact symptoms are as follows: if I try and re-use the same WebGLRenderer instance for both scenes, then immediately after I render a character portrait, then the very next call to render the main scene uses the lighting setup from the portrait scene. A subsequent call to render() the main scene fixes the problem.
  • The above is only true if both scenes have the same number of lights. If the number of lights is different, then the renderer simply throws an exception when attempting to render the main scene.
  • When I attempt to isolate the problem by giving the portraits their own dedicated instance of WebGLRenderer, the problem gets worse: rendering the portraits affects the main scene as before, but the main scene no longer fixes itself on subsequent renders. Instead, the problem with the lights persists.

My guess is that somehow my custom shader is not initializing the light state, that somehow I’m getting a stale lighting state from the previous render. However, I have no idea what would cause this, normally when writing custom shaders you don’t do anything special to get lighting as long as you inherit from ShaderMaterial which sets all that stuff up automatically.