markus-ebke / Blender-Lightsheet

Add-on for Blender3D to create caustics for Cycles and EEVEE
GNU General Public License v3.0
58 stars 3 forks source link
blender blender-addon blender3d cycles eevee python rendering

Lightsheet - Caustics for Cycles and EEVEE

Blender is a free and open source 3D computer graphics software toolset. For rendering images Blender includes a path-tracer called Cycles and a real-time renderer named EEVEE. However both render engines are not suitable for scenes where sharp reflections or refractions create caustics.

Lightsheet is a Blender Add-on for creating fake caustics that can be rendered with Cycles and EEVEE. The caustics are transparent meshes that wrap around objects with a diffuse material and show up like a glowing decal. The Add-on will create caustics before rendering, therefore they will be rendered quickly with EEVEE and provide indirect lighting with Cycles.

Cycles: Spot on Suzanne with caustics Drinking glasses on table with caustics Pool underwater with caustics

EEVEE in 3D-View: Screenshot of Blender with EEVEE in viewport showing spot on Suzanne scene Screenshot of Blender with EEVEE in viewport showing pool underwater scene

Installation

Download link (for Blender 3.2, 3.6 and 4.2): https://github.com/markus-ebke/Blender-Lightsheet/releases/latest

Download the .zip file. In Blender's preferences window go to the Add-ons section, click the dropdown menu in the topright corner and select Install from Disk.... Navigate to the downloaded file and install it.

You can access the Lightsheet tools via a panel in the 3D-View sidebar. Also, progress for long running operators is printed to the terminal window.

Example file: Lightsheet Examples.blend

Thread on blenderartists.org: https://blenderartists.org/t/lightsheet-caustics-for-cycles-and-eevee/1292193

How it works

Imagine a lamp sends out an elastic sheet made of light such that each point on the sheet travels along a ray of light. As the sheet moves through the scene and interacts with surfaces, it deforms due to reflection and refraction. When it finally reaches a diffuse material, it becomes visible to the camera. In places where the lightsheet gets stretched its intensity will be lower, where it gets squeezed together the intensity will be higher and where it's folded on top of itself the intensities add up.

To model such a lightsheet the Add-on creates a mesh assigned to each given light. It traces a ray for each vertex in the mesh, generating new vertices whenever a diffuse object gets hit. These caustic vertices are connected by faces following the topology of the original sheet. The size of the new caustic face compared with the size of the original lightsheet face determines the caustic's brightness.

This technique has been used before: Rendering Realtime Caustics in WebGL.

Drawbacks

EEVEE:

Cycles:

If one of these points is a problem for you, just use LuxCoreRender or YafaRay or appleseed!

Manual

All operators can be reached from the sidebar in the 3D viewport. Note that initial tracing, refinement, cleanup and animation will take some time to complete (several seconds up to a few minutes) and block the user interface. A progress report is printed to the terminal window.

You need to setup your scene beforehand, it should contain at least a lamp (sun, spot or point light), a reflective/refractive object (with a material that has zero roughness) and a diffuse object (where the caustics will show up). And if you render with Cycles, you should disable reflective and refractive caustics in the light paths settings.

  1. Create lightsheet for lamp

    Screenshot of Create Lightsheet operator panel

    Select the lamp and click the Create Lightsheets button. If you have small or detailed reflective/refractive objects you should increase the resolution. For point lights the lightsheet completely surounds it, for spots the lightsheet only fills the light cone. For sun lights you need to scale and move the lightsheet such that it "shadows" the reflective/refractive objects.

  2. Trace lightsheet to get caustics

    Screenshot of Trace Lightsheets operator panel

    Select the newly created lightsheet objects and click the Trace Lightsheets button, the max bounces setting works similar to the light bounces setting in Cycles. Note that the number of possible caustic paths increases exponentially with the number of bounces. Each path that contains at least one reflection/refraction will give a caustic object. After tracing has finished there should be several new objects in the scene that are part the the caustic collection (see the outliner for the complete list). Delete any caustics that you don't want (or that are too dim).

  3. For EEVEE: Adjust caustic material

    Screenshot of caustic textures nodes

    If you want to render with EEVEE, you need to adjust the texture of the caustic material. Copy the diffuse texture from the parent object and connect it instead of the checkerboard node marked in red. If the parent object has no texture, disconnect the node and set the diffuse color in the Mix RGB node.

  4. Refine caustics for more detail

    Screenshot of Refine Caustics operator panel

    Select the caustics that you want to refine and click the Refine Caustics button. A lower error threshold will give better looking caustics at the cost of more computation time and memory. You can repeat this step a few times, increasing the error threshold in each iteration. (Note that, to avoid testing all edges every time the operator is used, only edges that are Marked as Seam will the tested.)

  5. Cleanup and finalize caustics

    Screenshot of Finalize Caustics operator panel

    When you are done with refinement click the Finalize Caustics button with your caustics still selected. Apart from deleting some internal data you can feather the boundary of the caustic and remove faces that are too dim. If you render with Cycles you need to use the Cycles: Fix Overlap Artifacts setting to get rid of some dark spots were the caustics are folded a lot. Note that this will usually take a long time and use a lot of memory. (You can delete faces, e.g. those that are not visible to the camera, to speed up this process and save memory.)

  6. Optional: Animation

    Screenshot of Animated Trace operator panel

    If any of the lamps or reflective/refractive/diffuse objects are animated (change location or rotation), you also need to animate the caustics. Select the finalized caustics that you want to animate and use the Animated Trace operator. The settings of the existing caustics serve as a reference for all other frames. Note that this will create large files because new caustic objects will be created for every frame.

    Pool scene with animated water in EEVEE

Hidden Features

More Pictures!

Contributing

Contributions are always welcome and greatly appreciated. Here is how you can help:

For development I suggest you follow these steps:

  1. Fork this project (via the button on the Github page) and clone it locally:

    $ git clone git@github.com:<your_name_here>/Blender-Lightsheet.git
  2. Install pre-commit and automatically install the git hook scripts with

    $ pip install pre-commit
    $ cd Blender-Lightsheet/
    $ pre-commit install

    This will run some checks before every commit and also take care of basic formatting via isort and autopep8.

  3. Optional: You may use a linter like pylint or flake8, but I found them cumbersome since Blender's python modules are not easy to access from outside Blender. You can install fake-bpy-module to help with code completion, but the linters always gave me lots or errors. Anyways, I left a .pylintrc and a .flake8-file in the repository, just in case.

  4. I suggest you create a branch for local development, e.g. like this:

    $ git checkout -b <name-of-your-feature>
  5. You can add Blender files and images to show off new features or interesting use cases. Please put them in the Blender-Lightsheet/example/ folder.

    • When saving Blender files use the Compress File option, also don't include the computed caustics as they make the files very big.
    • For images I noticed that the JPEG-option with quality 98% gives good results and smaller files than PNG.
    • For animations I used GIF because I failed embedding looping MP4 videos in this README. I created them with ImageMagick (and I had to change some of the settings in ImageMagick's policy.xml to get it working):
      $ convert -fuzz 5% -delay 4 -loop 0 render/*.png -scale 640x360 -layers OptimizePlus -layers OptimizeTransparency animation640x360.gif

      Did you know that you can preview markdown with grip? While modifying README.md you can preview the changes in your browser:

      $ grip -b
  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Description of your changes"
    $ git push origin <name-of-your-feature>

    With the commit messages I tried to follow How to Write a Git Commit Message.

  7. Submit a pull request through the GitHub website and I will have a look.

Changelog

v1.4.1 (2024-08-30)

v1.4 (2024-05-01)

v1.3 (2023-12-13)

v1.2 (2022-09-03)

v1.1 (2022-05-26)

v1.0 (2021-03-17)