Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Friedemann_A · Jul 21, 2020 at 09:46 AM · shadershaderspost processingpostprocess

Can you process a color with postprocessing stack's color grading?

Hello :)

Is there an easy way to get the return color from the Post Processing v.2 Color Grading effect, given a source color? I'd like to color grade a bunch of objects that have vertex colors by using the Post Processing Stack Color Grading and then "bake" the results into the vertex colors so I can turn of post processing and still have the colors look like when they were "graded".

I'd be happy to google my way to the final result but need some pointers on where to get started. Doesn't need to be a very performant solution as I'd be doing this in editor only.

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Friedemann_A · Jul 22, 2020 at 09:35 AM

Found a somewhat dirty workaround, but for what I want to achieve, it gets the job done. I thought I'd share it here in case anyone stumbles across the same problem in the future.

To get the color graded result from an original color, I get the camera to which the color grading is applied (Camera.main in this case), set the original color as its background color and cull all layers so the camera renders only the background color with Post Processing on it. For this to work it's super important that Color Grading is the only active Post Processing Effect when this method is executed.

I have the camera render into a RenderTexture from which I read back into a helper texture. The helper texture is needed because from what I understand, you can't directly read the color of a pixel from a RenderTexture. The color of the helper texture is now the original color + color grading.

Here's the code in case anyone wants to reference it:

     private Color ApplyColorGradingFromPostFX(Color originalColor)
     {
         // For this to work, the color grading post processing you want to "bake" needs
         // to be the only active post processing effect on the main camera. 
 
         // This entire method is a bit of a dirty workaround but it gets the job done. 
         // It's important, that the Color Grading is the ONLY active post processing effect
         // when this method is executed, otherwise effects like vignette or grain will 
         // interfere with the background color of the camera and generate faulty results.
 
         const int Res = 1;
         Texture2D helperTexture = new Texture2D(Res, Res);
 
         // Store current active RenderTexture
         RenderTexture lastActiveRT = RenderTexture.active;
 
         // Get the main camera
         Camera renderCamera = Camera.main;
 
         // Store original camerasSettings
         Color originalBackgroundColor = renderCamera.backgroundColor;
         CameraClearFlags originalClearFlags = renderCamera.clearFlags;
         int originalCullingMask = renderCamera.cullingMask;
 
         // Set camera up for rendering the original color 
         // as background color and cull everything else
         renderCamera.backgroundColor = originalColor;
         renderCamera.clearFlags = CameraClearFlags.Color;
         renderCamera.cullingMask = 0;
         // I don't think this is really necessary, right now the code works 
         // if you delete it, but I'm leaving it in for future proofing
         RenderTexture.active = renderCamera.targetTexture;
 
         // Render and copy a pixel from the corner of the screen 
         // into our helper texture, so we can read it's color value
         renderCamera.Render();
         helperTexture.ReadPixels(new Rect(0, 0, Res, Res), 0, 0, false);
         helperTexture.Apply();
 
         // Read the modified color from the helper texture
         Color returnColor = helperTexture.GetPixel(0, 0);
 
         // Restore original camera settings
         renderCamera.backgroundColor = originalBackgroundColor;
         renderCamera.clearFlags = originalClearFlags;
         renderCamera.cullingMask = originalCullingMask;
 
         // Restore last active RenderTexture
         RenderTexture.active = lastActiveRT;
 
         return returnColor;
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Zoedingl · Jul 21, 2020 at 02:37 PM

Just have a look at Brackeys' video on youtube about Post proccesing in Unity. Everything is explained there.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Friedemann_A · Jul 22, 2020 at 09:01 AM 0
Share

Thanks, I'll check it out!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

208 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom postprocess white in build 0 Answers

How do you use a shader file once written? 1 Answer

HLSL Post Process Shader Fixing UV/Texcoord 1 Answer

How to properly use RTHandles in HDRP for post effects 0 Answers

Why doesn't this shader work when using it with as a custom effect on the post processing stack 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges