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 /
avatar image
2
Question by willmolter · Aug 22, 2019 at 03:01 AM · texturesemissionhdr

Encode to EXR changes colors

I've been trying to create some emission textures with a tool I made. I need to be able to store emission that has HDR to take advantage of a bloom effect I'm using, so I discovered Unity's builtin ImageConversion.EncodeToEXR. The problem is, when I then apply one of these saved textures to a material as its emission map, the colors are brighter, and in such a way that changing the emission color property of the material cannot return it to the correct colors.

.

Loading the saved texture back in to a Texture2D manually and then applying that to a material maintains the changes; so saving it again compounds the brightness, as below:

.

emission on spheres; original on the right.

.

.

The original texture is on the right. I've simplified to gray so you can see the brightening effect. The thing is that when I generate the texture into a Texture2D (formats RGBA32, RGBAFloat, RGBAHalf have all worked) and then put that in using Material.SetTexture("_EmissionMap, texture); I can achieve the colors I want. I would think there is some format or way to save my image that would maintain that. Is EXR just only meant for lightmaps, and foolish to use for anything else? Can Unity support higher bit-depth PNG instead? Or is there some special texture import setting I'm missing? Any insight you can provide would be appreciated.

.

Saving code:

 byte[] bytes = ImageConversion.EncodeToEXR((Texture2D)texture, Texture2D.EXRFlags.CompressZIP);
 //I've tried uncompressed as well.
 System.IO.File.WriteAllBytes(path + ".exr", bytes);

.

Loading code:

 Texture2D testTex = Resources.Load<Texture2D>(filename);
 Color[] colors = testTex.GetPixels();
 ((Texture2D)texture).SetPixels(colors);
 ((Texture2D)texture).Apply();
 //texture is an instance variable

.

Texture Import Settings alt text

exrchanges.png (268.9 kB)
exrsettings.png (29.2 kB)
Comment
Add comment · Show 1
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 JacobK · Jul 08, 2020 at 07:09 PM 0
Share

No solution here (and I can't seem to leave a comment), but I'm having the same problem in 2019.4 :(

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by HotkangChen · Sep 05, 2019 at 05:55 AM

I have same question in 2018.3.

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
0

Answer by JacobK · Jul 08, 2020 at 07:39 PM

Okay - I'm having the same problem in 2019.4, found a solution, but it's nasty!

Seems like it's a gamma<>linear space issue? This won't be particularly fast, and your textures will need to be marked for reading, so this might not work in runtime, but it sounds like you're writing an editor tool so this'll probably work

So... before you export the texture - loop over every pixel, convert them from gamma to linear, set and apply them back

 // Loop over each pixel, convert them to linear space, apply them back
 for (int y = 0; y < problem_texture.height; y++) {
     for (int x = 0; x < problem_texture.width; x++) {
         
         Color c = problem_texture.GetPixel(x, y);
         problem_texture.SetPixel(x,y,c.linear);
     }
 }
 problem_texture.Apply(true);
 byte[] exrBytes = problem_texture.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);
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

110 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

Related Questions

Using a sequence of frames as a material emissive map. 0 Answers

A way to combine two textures in HDRP and output one new texture? 1 Answer

HDRP Emissive Color Change during Runtime 1 Answer

Bloom/HDR glow effect not working on sm-t210r 0 Answers

Anyone have shader that supports two UV channels? 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