How to use Lookup Table for Renders

How to use Lookup Table for Renders

What is Lookup Table for Renders?

Lookup tables (LUTs) are an excellent technique for optimizing the evaluation of functions that are expensive to compute and inexpensive to cache. By pre-computing the evaluation of a function over a domain of common inputs, expensive runtime operations can be replaced with inexpensive table lookups. If the table lookups can be performed faster than computing the results from scratch (or if the function is repeatedly queried at the same input), then the use of a lookup table will yield significant performance gains.

A Lookup Table (LUT) can be used to achieve color correction using a Post Process Volume. Instead of using three one-dimensional (1D) lookup tables, a single three-dimensional (3D) Lookup Table is used. This offers more sophisticated color transformation, which can be used for something like desaturation.

How to use Lookup Table for Renders

Implementation of Lookup Table for Renders

Most modern GPUs offer hardware-accelerated trilinear, 3D texture lookups (the interpolation unit was originally necessary for mipmapped, 2D texture lookups)

First, we load our high-resolution image into a standard 2D texture. Next, we load our 3D color correction mapping as a 3D texture, being careful to enable trilinear filtering.

At runtime, we transform our input image by sampling the color in the normal fashion and then by performing a dependent texture lookup into the 3D texture (using the result of the 2D texture lookup as the 3D texture’s input indices). The output of the 3D texture is our final, color-transformed result.

Shader Analysis

The most common question is probably “Why are the scale and offset factors necessary?” The answer relates to the coordinate system that the texture-mapping hardware uses to sample from our LUT. Specifically, the hardware texture-sampling algorithms sample (by default) from one extreme of the data set to the other. Though this is entirely reasonable when texturing image data, it is not appropriate for sampling numerical data sets, because it introduces nonlinearities near the texture’s edges.

Shader Optimization

This code has obvious acceleration opportunities. First, as the scale and offset factors are constant across the image, they can be computed once and passed in as constants. (Or even better, they can be directly compiled into the fragment shader.) Second, it is good practice to use the smallest LUT that meets your needs (but no smaller). For “primary grading” color corrections, where one only modifies the color of the primaries (RGB) and secondaries (CMY), a 2x2x2 table will suffice! Finally, for consumer-grade applications, an integer texture format may suffice (of course, still with trilinear interpolation enabled). But be aware that 8 bits is not sufficient to prevent banding in LUT color transforms.

System Integration

  1. Generate (and cache) the 3D lattice as a 2D image, preferably in the same byte order as the GPU will expect in step 3.
  2. Apply arbitrary color correction to this lattice image (using a standard color-correction pipeline), treating the 3D lattice image as a proxy for the final color correction you wish to apply.
  3. Load both the high-resolution image and the 3D texture to the GPU.
  4. Draw source imagery using the fragment shader in Listing 24-1.

Hope this Blog helped you.

For more SketchUp tutorials you can check out https://sketchupguru.com/blog/

You can also check more tutorial videos for sketchup on our YouTube Channel,

https://www.youtube.com/c/SketchupGuru

To know about the Top Online 3D Rendering Courses for 2022 click,

Leave a Reply

Your email address will not be published. Required fields are marked *

Udemy logo transparent
Serious about taking your rendering and modelling skills to the next level?
Sign up for The Complete Sketchup & Vray Course for Interior Design!