Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by FredZvt81 · Dec 04, 2015 at 06:36 PM · shadercolorhdrstandard

Using the standard shader, how to get the current emission brigthness in code?

I know that I can create a HDR color by multiplying a base color by the brightness factor like that:

 float brightnessFactor = 3f;
 Color hdrColor = Color.red * brightnessFactor;

And, then, set this HDR color as emission in the standard shader like that:

 material.SetColor("_EmissionColor", hdrColor);

But, if I get the emission color from the shader, how can I know the brightness value that was used to create the HDR color?

 var hdrEmissionColor = material.GetColor("_EmissionColor");
 var baseEmissionColor = ???

What I really want to know is how to get, by code, the brightness set on the HDR color dialog box in the editor.

alt text

hdrvalue.png (41.3 kB)
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

Answer by JonathanCzeck · Dec 06, 2015 at 06:00 AM

There isn't an extra brightness value in the color, it's just UI sugar.

The brightness will be the highest value between R, G, and B. To get the base color, divide each color component by that highest value.

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 FredZvt81 · Dec 06, 2015 at 06:00 PM 0
Share

Hey, Jonathan!

Thanks for the insight. I created a small test script to test your explanation but I found it to be almost right. The problem with your solution is that by picking the highest component and dividing all of them by that one we normalize the HDR color back to a non-HDR state but the normalized color can differ from the original color if the original color brightness is less than 1.

Hard to explain in words, here it is an example:

 An example that work:
 Original Color: (0.0, 0.5, 1.0)  // Original color brightness is 1 (one of the components must be equal to one)
 Brightness: 6.35 // Any value greater that 1 to generate an HDR color.
 Resulting HDR Color: (0.0, 3.175, 6.350) // Original Color * Brightness
 Biggest Component: 6.350
 Restored Color: (0.0, 0.5, 0.1) // Resulting HDR Color / Biggest Component

 An example that doesn't work:
 Original Color: (1.161, 0.422, 0.684) // Original color brightness is 0.684
 Brightness: 6.35 // Any value greater that 1 to generate an HDR color.
 Resulting HDR Color: (1.022, 2.682, 4.342) // Original Color * Brightness
 Biggest Component: 4.342
 Restored Color: (0.235, 0.618, 1) // Resulting HDR Color / Biggest Component

Here, take the script that I created to test this. The problem became easy to see when you set the brightness value to something greater that 1 and play with the original color:

 [ExecuteInEdit$$anonymous$$ode]
 public class ColorTest : $$anonymous$$onoBehaviour
 {
     [ColorUsage(true, true, 0, 8f, 0.125f, 3f)]
     public Color originalColor = new Color(0.1f, 0.2f, 0.3f, 1f);
     public float brightness = 3;

     [Header("Calculated (don't change manually):")]
     [ColorUsage(true, true, 0, 8f, 0.125f, 3f)]
     public Color multipliedColor;
     public float biggestValue;
     [ColorUsage(true, true, 0, 8f, 0.125f, 3f)]
     public Color restoredColor;
 
     void Update()
     {
         multipliedColor = originalColor * brightness;

         biggestValue = multipliedColor.r;
         if (multipliedColor.g > biggestValue) biggestValue = multipliedColor.g;
         if (multipliedColor.b > biggestValue) biggestValue = multipliedColor.b;

         if (biggestValue > 1f)
         {
             restoredColor =
                 new Color(
                     multipliedColor.r / biggestValue,
                     multipliedColor.g / biggestValue,
                     multipliedColor.b / biggestValue
                     );
         }
         else
         {
             restoredColor = multipliedColor;
         }

         Debug.Log("---");
         Debug.LogFormat("originalColor: {0}", originalColor);
         Debug.LogFormat("hdrColor: {0}", multipliedColor);
         Debug.LogFormat("biggestValue: {0}", biggestValue);
         Debug.LogFormat("restoredColor: {0}", restoredColor);
     }
 }
avatar image
0

Answer by Kayos · Jun 02, 2016 at 04:44 PM

"Color finalValue=Color.White*someValue; // someValue adjust the scale of emission"

I just tested this, simply multiplying the colour by someValue will increase the emission value.

Source: http://forum.unity3d.com/threads/standard-shader-emission-value.280153/

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

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

40 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

Related Questions

A public list of color in shader. 0 Answers

Critical issue with glitching standard shaders 1 Answer

Line Renderer displays black while using the Standard Shader on PC 0 Answers

Sprites/Cutout Shader ? 0 Answers

unity standard shader broken android 0 Answers


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