Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LUTImageLoader. #26880

Merged
merged 13 commits into from
Oct 11, 2023
Merged

Add LUTImageLoader. #26880

merged 13 commits into from
Oct 11, 2023

Conversation

NikLever
Copy link
Contributor

@NikLever NikLever commented Oct 1, 2023

Related issue: #XXXX

Description

I was surprised to find that I couldn't load a LUT directly from an image in png or jpg format. So I added LUTImageLoader and an example with 3 LUT image files. The LUT files can have blocks placed horizontally or vertically. It is assumed that the block size defines the number of blocks. By default the image is flipped in the y, but this can be passed to the constructor.

@github-actions
Copy link

github-actions bot commented Oct 1, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
649.1 kB (160.9 kB) 649.1 kB (160.9 kB) +0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
442.4 kB (107 kB) 442.4 kB (107 kB) +0 B

@NikLever NikLever changed the title NiksFeatures LUTImageLoader and example Oct 1, 2023
package.json Outdated Show resolved Hide resolved
@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 2, 2023

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 2, 2023

Instead of having a new example, could you integrate LUTImageLoader into webgl_postprocessing_3dlut (next to LUTCubeLoader)?

@NikLever
Copy link
Contributor Author

NikLever commented Oct 3, 2023

Added to the existing example

@Mugen87 Mugen87 requested a review from gkjohnson October 3, 2023 07:56
Code style improvements.
@Mugen87 Mugen87 changed the title LUTImageLoader and example Add LUTImageLoader. Oct 3, 2023
Mugen87
Mugen87 previously approved these changes Oct 4, 2023
Copy link
Collaborator

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments - but a couple other questions first:

  • Are these kinds of png LUT files easily found in the wild? How can a user generate them?
  • Where did the example PNG LUTs in the PR come from?

Thanks!

examples/jsm/loaders/LUTImageLoader.js Outdated Show resolved Hide resolved
examples/jsm/loaders/LUTImageLoader.js Outdated Show resolved Hide resolved
examples/jsm/loaders/LUTImageLoader.js Show resolved Hide resolved
@NikLever
Copy link
Contributor Author

NikLever commented Oct 7, 2023

Are these kinds of png LUT files easily found in the wild?

They regularly appear in the Unity pipeline https://www.youtube.com/watch?v=TQkI5XZ7pfE

How can a user generate them?

Using Photoshop

Where did the example PNG LUTs in the PR come from?

I created them based on this tutorial https://www.patreon.com/posts/lut-in-unity-urp-44252330

@NikLever
Copy link
Contributor Author

NikLever commented Oct 7, 2023

Here's another link from a Unity perspective https://youtu.be/JWufZtMPSPI?si=-GylurIPDsH4yUea&t=152

@gkjohnson
Copy link
Collaborator

How can a user generate them?

Using Photoshop
...
I created them based on this tutorial https://www.patreon.com/posts/lut-in-unity-urp-44252330

I'm unable see the post. Can you roughly explain the process? Is it different than the Unreal LUT generation referenced below?

They regularly appear in the Unity pipeline https://www.youtube.com/watch?v=TQkI5XZ7pfE

For Unity it looks like this is only supported via "Amplify Color" for handling LUTs and not baked into the engine, right? The fact that green is swapped vertically also strikes me as odd. Though it looks like Unreal also supports using lut strips. The Unreal LUT documentation and available neutral LUT strip is here.

Here's another link from a Unity perspective https://youtu.be/JWufZtMPSPI?si=-GylurIPDsH4yUea&t=152

Sorry to keep digging, I don't have Amplify LUT so I'm trying to understand this - but in the video linked the green channel is not flipped. At what point does it get flipped? I guess I'm partially feeling like flipY should not default to true.

@gkjohnson
Copy link
Collaborator

gkjohnson commented Oct 9, 2023

Also I just recalled that we have a page on LUTs which includes a neutral LUT generator here (which has green increasing from top down like Unreals strips):

https://threejs.org/manual/?q=lut#en/post-processing-3dlut

@NikLever
Copy link
Contributor Author

NikLever commented Oct 9, 2023

How can a user generate them?

Using Photoshop
...
I created them based on this tutorial https://www.patreon.com/posts/lut-in-unity-urp-44252330

I'm unable see the post. Can you roughly explain the process? Is it different than the Unreal LUT generation referenced below?

He applies Photoshop color grading to the NeutralLUT.png

They regularly appear in the Unity pipeline https://www.youtube.com/watch?v=TQkI5XZ7pfE

For Unity it looks like this is only supported via "Amplify Color" for handling LUTs and not baked into the engine, right? The fact that green is swapped vertically also strikes me as odd. Though it looks like Unreal also supports using lut strips. The Unreal LUT documentation and available neutral LUT strip is here.

Here's another link from a Unity perspective https://youtu.be/JWufZtMPSPI?si=-GylurIPDsH4yUea&t=152

Sorry to keep digging, I don't have Amplify LUT so I'm trying to understand this - but in the video linked the green channel is not flipped. At what point does it get flipped? I guess I'm partially feeling like flipY should not default to true.

I just double checked and a neutral affect is created with the NeutralLUT having green at the top
Screenshot 2023-10-09 at 08 11 48

@NikLever
Copy link
Contributor Author

NikLever commented Oct 9, 2023

Also I just recalled that we have a page on LUTs which includes a neutral LUT generator here (which has green increasing from top down like Unreals strips):

https://threejs.org/manual/?q=lut#en/post-processing-3dlut

Looks like Unity uses them green at the top and Unreal green at the bottom. I'm neutral on the default. But do feel we should include the option. If you want the Unreal as the default then should I flip the png images and take the default as flipY = false. Or should I change the application to use the second parameter and not the default? Maybe add a comment about unreal and unity.

This is my first contribution to the library and I'm very impressed with how rigorous the approval process is :-)

@NikLever
Copy link
Contributor Author

NikLever commented Oct 9, 2023

For Unity it looks like this is only supported via "Amplify Color" for handling LUTs and not baked into the engine, right? The fact that green is swapped vertically also strikes me as odd. Though it looks like Unreal also supports using lut strips. The Unreal LUT documentation and available neutral LUT strip is here.

Unity URP has a post-processing filter that you can add to a Volume, Color Look-up. It is described in the e-book I wrote for Unity. https://resources.unity.com/ebooks/the-universal-render-pipeline-cookbook-unity-2022-lts-edition?ungated=true
https://blog.unity.com/engine-platform/12-recipes-for-popular-visual-effects-using-universal-render-pipeline

Screenshot 2023-10-09 at 09 53 46 Green bottom

@gkjohnson
Copy link
Collaborator

I just double checked and a neutral affect is created with the NeutralLUT having green at the top

I believe that Unity expects green increasing bottom to top - I was just trying to reconcile it with the video linked. But I see now that that video is about writing a custom shaders.

should I change the application to use the second parameter and not the default? Maybe add a comment about unreal and unity.

I think given that unreal and the three.js manual uses increasing green from top to bottom and an unofficial Unity uses the reverse means that we should default to non flipped and we can flip the images.

This is my first contribution to the library and I'm very impressed with how rigorous the approval process is :-)

Heh file formats formats and standards like this tend to be a sticking point for me. Thanks for bearing with me. I've been bit by having to support weird non-standard features or ill-defined specifications in the past so I like to try to understand and get it right up front where possible. I think a big project has a responsibility to not contribute to the proliferation of new or non standard formats that users may have the expectation of other engines supporting in the future. To be honest I'm a bit annoyed that both Unity and Unreal use this image format instead of the CUBE or 3DL formats that the rest of the color grading tools seem to use and support... And even worse that they're not consistent.

@Mugen87 Mugen87 dismissed their stale review October 10, 2023 08:55

Further changes requried.

@NikLever
Copy link
Contributor Author

Changed default flipY to false, inverted the lut image strips.

@Mugen87 Mugen87 added this to the r158 milestone Oct 11, 2023
@Mugen87 Mugen87 merged commit c9692eb into mrdoob:dev Oct 11, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants