leezer3 / OpenBVE

OpenBVE- A free train simulator
http://www.openbve-project.net
278 stars 52 forks source link

[Possible bug] Brightness is affected by world light #89

Open marcriera opened 8 years ago

marcriera commented 8 years ago

While developing a route with dark ambient and directional lights, I have discovered what looks like an unintended effect related to lights.

The commands .AmbientLight and .DirectionalLight affect how the world polygons are illuminated. Their behaviour is the same for BVE4/5 and OpenBVE. However, BVE4/5 and OpenBVE handle cab brightness differently. While BVE4/5 cabs are not affected by the world light (and thus it is possible to have a bright cab with a 0,0,0 ambient light), OpenBVE applies the world light to the cab too. In a route with a 0,0,0 ambient light, this makes the cab always dark (even if the brightness is set to 255). Exterior views are affected too, as they are linked to the cab.

I guess this may be a side effect of exterior views. They look natural when affected by the world light, but back when the feature was added probably nobody thought that they were linked to cabs (most routes are outdoors and daytime and the effect becomes invisible). Odakyufan had problems with this too in the nighttime routes of Chashinai Railway, and tricked OpenBVE by calculating brightness values according to the ambient light (more details here: [http://web.archive.org/web/20111128233147/http://odakyufan.zxq.net/tips.html#tunnelsandcabbrightness] ). Obviously this is not the ideal solution, as this only hides the side effect in a very limited way.

The solution would be to have cabs and exterior views affected by the world light, but override it a similar way to how SetEmissiveColor color works. At 255 the cab/exterior would not be affected at all by the world light, and at 0 the cab/exterior would be fully affected.

leezer3 commented 8 years ago

It's rather more a limitation with the way that cabs are handled, and from that the renderer in general.

As you're probably aware, openBVE uses the less conventional method of moving the world each frame, rather than moving the camera within the world, and periodically loading a new world tile. As such, you'll find that the cab itself is nothing more than an object within the world, and is effected by the lighting conditions prevalent within the world.

In order to do what you're suggesting, I think we'd require something a little more like this: Using two framebuffers, render the scenery in one, and the cab faces in the other. Store both the images and the depth masks as textures in memory. Render the final scene by combining the two images.

That's a reasonably standard technique, but probably requires redoing a whole bunch of the engine.....