google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.82k stars 1.89k forks source link

Support multiple directional lights during shading #1182

Open griffin2000 opened 5 years ago

griffin2000 commented 5 years ago

On the WebGL build (version f5b47dc95e3e5efb09f52c31d628618326f1f51e) I've noticed it's not possible to add a Directional and Sun light to the same scene.

We you do try to do so, the first directional/sun light that is added to the scene is overwritten by the second one. E.g. this code results in only a very dim sun light, no directional light. The results are the same if two directional lights are added (but not if a directional light and a point light are added, in which case the both render correctly):

      const light0 = Filament.EntityManager.get().create();
      Filament.LightManager.Builder(Filament.LightManager$Type.DIRECTIONAL)
        .color([0,1,0])
        .intensity(115000)
        .direction([0.0, 0.0, -1.0])
        .build(engine, light0);

        scene.addEntity(light0);

      const light1 = Filament.EntityManager.get().create();
      Filament.LightManager.Builder(Filament.LightManager$Type.SUN)
        .color([1,1,0])
        .intensity(10)
        .direction([0.0, 0.0, -1.0])
        .build(engine, light1);

        scene.addEntity(light1);

I've attached a version of tutorial_redball.js that shows the issue.

griffin2000 commented 5 years ago

redball.zip

romainguy commented 5 years ago

This is a current limitation of the engine, mostly for performance and size reasons: we only support 1 directional light (that includes sun light) at a time. The engine picks the one with the strongest intensity. What is your use case for 2 directional lights?

griffin2000 commented 5 years ago

Ah OK. We have a client-facing API that supports multiple directional lights.

griffin2000 commented 5 years ago

Though actually I do think it's a bug even with that restriction. In the example above it's the very dim light that gets used, not very bright one (so the render comes out black)

griffin2000 commented 5 years ago

Added a bug about the incorrect light choice: https://github.com/google/filament/issues/1183