[Renderer Workbench] Lighting

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
howetuft
Posts: 20
Joined: Tue Sep 10, 2019 8:16 pm

Re: [Renderer Workbench] Lighting

Postby howetuft » Tue Dec 03, 2019 4:28 pm

Good idea!

So the targets for the lighting effort could be:
- Point Lights (PL)
- Area Lights (AL)
- Image-Based Lighting (IBL)
- Hosek-Wilkie Skylight (HWS)
- A tri-point lighting functionality, based on PL and AL (priority 2)
- Plus a Camera Object (CAM), to meet a need expressed here: https://forum.freecadweb.org/viewtopic.php?f=10&t=40839

I should post soon first PRs for Point Lights and go through other points, but any help is welcome! @nocturnial: yes, your help would be especially precious with HWS (what I just know about the sun is that it should be somewhere above my head during the day...), let me know how you see things.

A point about design: my idea would be to develop all lighting stuff above (PL, AL, IBL, HWS, and even CAM) as objects we could insert freely into rendering projects (and which renderers modules should then convert to renderer-specific formats), with the following characteristics:
- objects would not be render-dependent: e.g. we could have the same HWS or the same CAM used for a Luxcore project and a Blender project
- in a given project, we could have several instances of the same class. It is obvious for PL and AL, but I think we should also consider the possibility, in the same project, to have several HWS, several CAMs etc. that the user could activate/deactivate for a given rendering.
--> Any comments appreciated!
User avatar
Kunda1
Posts: 6223
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Renderer Workbench] Lighting

Postby Kunda1 » Wed Dec 04, 2019 5:36 pm

Very exciting discussion here. These various functionalities integrated will further evolve this powerful workbench. Thank you
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
howetuft
Posts: 20
Joined: Tue Sep 10, 2019 8:16 pm

Re: [Renderer Workbench] Lighting

Postby howetuft » Sat Dec 07, 2019 11:50 am

I finally posted a first PR, which allows a user to add Point Lights in a scene rendering. https://github.com/FreeCAD/FreeCAD-render/pull/18
For the moment, the export only works for Pov-Ray, but I will extend it to other rendering engines in the future.

Usage:
1°) Add a Point Light to the FreeCAD scene with the Arch Texture Workbench. Adjust color, position etc.
2°) Create a view of the Light Point in your rendering project (which must be a POV-Ray project, for the moment), with the Render Workbench
3°) Render!

To illustrate the concept, I made two examples below, in a before/after manner.

Example 1: a simple sphere
First, the scene with the standard lighting template:
PovrayProject92xk7y4_withoutPL.png
PovrayProject92xk7y4_withoutPL.png (33.48 KiB) Viewed 449 times
And the same after adding a point light on the right above the camera :
PovrayProject92xk7y4_withPL.png
PovrayProject92xk7y4_withPL.png (41.61 KiB) Viewed 449 times
One can see the following consequences:
  • The object is more lit, which increases the contrast with the background and creates some kind of focus on it.
  • There is specular reflection on the sphere, and a cast shadow behind, which can improve the realism of the rendering.
Example 2: a more complex scene...
I borrowed the model from Yorik, thanks to him.

Standard lighting template:
PovrayProject10jb6w0p_withoutPL.png
PovrayProject10jb6w0p_withoutPL.png (150.94 KiB) Viewed 449 times
The same with an added point light in the right and above the camera :
PovrayProject10jb6w0p_withPL.png
PovrayProject10jb6w0p_withPL.png (169.05 KiB) Viewed 449 times
Again, one can see more light on the object, resulting in more contrast between object and background, and also shadows cast behind.

PL are very useful for direct lighting, however they cast very sharp shadows: that's why I think we'll also need area lights (which are much softer...) in the toolbox...
User avatar
furti
Posts: 331
Joined: Mon Nov 27, 2017 5:27 pm

Re: [Renderer Workbench] Lighting

Postby furti » Sat Dec 07, 2019 7:02 pm

Nice. This looks pretty cool already.
howetuft wrote:
Sat Dec 07, 2019 11:50 am
PL are very useful for direct lighting, however they cast very sharp shadows: that's why I think we'll also need area lights (which are much softer...) in the toolbox...
There is the directional light in the Arch Texture workbench. This should be a good fit for architectural projects.
adrianinsaval
Posts: 101
Joined: Thu Apr 05, 2018 5:15 pm

Re: [Renderer Workbench] Lighting

Postby adrianinsaval » Sat Dec 07, 2019 9:28 pm

howetuft wrote:
Sat Dec 07, 2019 11:50 am
PovrayProject10jb6w0p_withPL.png
Sorry for the offtopic but, damn that's an impressive model, cool to see things like this done in FreeCAD
howetuft
Posts: 20
Joined: Tue Sep 10, 2019 8:16 pm

Re: [Renderer Workbench] Lighting

Postby howetuft » Sun Dec 08, 2019 8:42 pm

furti wrote:
Sat Dec 07, 2019 7:02 pm
Nice. This looks pretty cool already.
Thank you!

furti wrote:
Sat Dec 07, 2019 7:02 pm

There is the directional light in the Arch Texture workbench. This should be a good fit for architectural projects.
Sure! Directional lights could also be one of the lighting tools for rendering, they are very convenient to simulate sun. However, directional lights cast sharp shadows, like point lights. So, we'll also need area lights for soft shadows (for tri lighting, for instance).
adrianinsaval wrote:
Sat Dec 07, 2019 9:28 pm
howetuft wrote:
Sat Dec 07, 2019 11:50 am
PovrayProject10jb6w0p_withPL.png
Sorry for the offtopic but, damn that's an impressive model, cool to see things like this done in FreeCAD
Thank you for your support! The author of the model is Yorik, I must insist :D ...
howetuft
Posts: 20
Joined: Tue Sep 10, 2019 8:16 pm

Re: [Renderer Workbench] Lighting

Postby howetuft » Mon Dec 30, 2019 7:39 pm

I eventually found some time to add support for point lights to Luxcore renderer (PR is here: https://github.com/FreeCAD/FreeCAD-render/pull/20)!
Here is a simple scene (the same as previously used for POV):
ball.png
ball.png (59.71 KiB) Viewed 212 times
A few comments:
- To be fully operational, this evolution requires that the PointLight has a RenderingPower property. It is in my pull request #34 to @Furti's Arch Texture (https://github.com/furti/FreeCAD-ArchTextures/pull/34), hope it will be accepted...
- I chose to introduce a new template with no predefined light, which I called 'luxrender_flat.lxs'. Other existing templates contain predefined powerful lighting, like sun or sky, that interfere with pointlights (no way to see a pointlight in full daylight :o ).
- Compared to POV, Lux rendering is notably darker (black background, dark shadow). However, Lux is right: in POV, the template adds an area light just behind the camera and a "skysphere" - very helpful, indeed, but a bit unfair... ;)
- A quite important point: lxs format, the format used by our Lux templates and our Lux exporter, is outdated. Luxcore now uses a new specification called SDL (https://wiki.luxcorerender.org/LuxCore_ ... anual_v2.3). No specification for lxs can be found any more, so it is kind of hard to develop new functionalities (for my code; I made some reverse engineering with luxcoreui importer, here: https://github.com/LuxCoreRender/LuxCor ... /luxparser, but it is quite time-consuming). I think we should add to our roadmap to port our exporter to SDL.
howetuft
Posts: 20
Joined: Tue Sep 10, 2019 8:16 pm

Re: [Renderer Workbench] Lighting

Postby howetuft » Tue Dec 31, 2019 3:13 pm

Studying again POV standard template, I finally added a skysphere to luxrender_standard.lxs template (called a 'constantinfinite' in SDL).

Then I was eventually able to render with Luxcore the 2 scenes I previously built for POV-Ray:
ball2.png
ball2.png (63.8 KiB) Viewed 168 times
lux_building.png
lux_building.png (309.9 KiB) Viewed 168 times
howetuft
Posts: 20
Joined: Tue Sep 10, 2019 8:16 pm

Re: [Renderer Workbench] Lighting

Postby howetuft » Thu Jan 02, 2020 8:42 am

I've completed support for Point Light in Cycles exporter. Here are my 2 scenes rendered with Cycles:

CyclesProject9s6dauj_.png
CyclesProject9s6dauj_.png (70.74 KiB) Viewed 128 times
CyclesProjectu87azg7i.png
CyclesProjectu87azg7i.png (509.6 KiB) Viewed 128 times
Interestingly, there is no automatic smoothing in Cycles, so we can see small triangular sub-faces on the sphere... As a counterpart, details are more precisely rendered with Cycles than with Luxcore, to my point of view.