https://github.com/mos9527/blenderimagelut
Real-time Color Grading with Image LUTs in Blender Compositor
https://github.com/mos9527/blenderimagelut
blender color-grading lut
Last synced: 4 months ago
JSON representation
Real-time Color Grading with Image LUTs in Blender Compositor
- Host: GitHub
- URL: https://github.com/mos9527/blenderimagelut
- Owner: mos9527
- Created: 2025-02-02T08:58:39.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-02-10T03:32:45.000Z (8 months ago)
- Last Synced: 2025-02-10T04:26:02.680Z (8 months ago)
- Topics: blender, color-grading, lut
- Language: Python
- Homepage:
- Size: 243 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
BlenderImageLUT
---
Real time image-based color grading in Blender's compositor.
# WARNING
Only LDR sRGB LUTs are supported. There is NO correctness guarantee for this implementation and is currently *NOT* color correct. Use at your own risk.# Usage
## Loading the Nodes
- [Download `BlenderImageLut.blend`](https://github.com/mos9527/blender-image-lut/raw/refs/heads/main/BlenderImageLUT.blend)
- In your Blender project, Go to `File > Append...`- Open the downloaded `.blend` file and go to `NodeTree`, where you can find the node **`BlenderImageLUT`**. Click `Append`
- In the `Compositor` tab, enable `Use Nodes` and search for `BlenderImageLUT` with F3, add it to your node tree
## Loading the LUT image
- Add an `Image` node with F3 and then load the LUT image of your choice **and setup the `LUT Dimension` ($D$) properly**.
- **ATTENTION:** Please refer to the [Notes](#notes) section for what kind of LUT image you should be using.
- Ensure your image transform is linear. Again, **read the [Notes](#notes) section** for more information.
- Connect the nodes. Your final node setup should look like this:- To view the result, you can enable the compositor under the `Viewport Shading` tab and set the compositor option to `Always` as shown below
# Notes
## LUT Dimension
Your 3D LUT transform should be a **2D Image** of pixel dimension $(D^2,D)$, where $$D$$ is the **uniform size in pixel of your LUT**The 3D texture should be swizzled onto the 2D plane like this:
```
Numbers indicate the index of the Z-slice
┌───────┬───────┬───────┬─────┐
│ │ │ │ │
│ 1 │ 2 │ 3 │ ..n │
│ │ │ │ │
└───────┴───────┴───────┴─────┘
```
For example, here's a *netural* one with $D=16$, Generated by [lutgen.py](https://github.com/mos9527/BlenderImageLUT/blob/main/lutgen.py)
The $R,G,B$ channels should advance in value in the UV (pixel) direction shown in the following diagrams:
- $R$ channel- $G$ channel
- $B$ channel
## Colorspace (with sRGB LUTs)
LUTs **MUST** **contain mapping from Linear (pixel coords) to Linear (colors)** since Blender's compositor uses linear colorspace at all times[With PNG in sRGB colorspace, the transfer function is simply a power function with gamma 2.2](http://www.libpng.org/pub/png/spec/1.2/png-1.2-pdg.html#C.Anc-color). The following node setup converts the transformed (sRGB->Linear) colors back to sRGB (encoded, linear in UV) colors
Another setup like this also works, which skips color conversions and uses the sample as is
## Transposing LUTs of different dimensions
(todo)# How it works
By implementing Bilinear Filtering and 3D texture sampling from scratch with Compositor Nodes and performs LERPed color look-up in runtime.Generally there will be 8 texture lookups for each pixel - which is expensive. Use this node setup sparingly or only at render-time!
# References
- Real Time Rendering 4th Edition
- https://github.com/mos9527/sssekai_blender_io
- https://docs.blender.org/manual/en/latest/render/color_management.html