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
1
Question by Zergling103 · Aug 18, 2012 at 12:39 AM · texturelinear

How do I create a Texture2D via script that bypasses sRGB sampling?

Hi there,

I need help on creating a Texture2D with a script that bypasses sRGB sampling.

Specifically, the texture is created using Texture2D(), is filled with software drawing functions, and is used to render GUI.

This is a problem with an asset I purchased from the asset store called uWebKit. Apparently it does not support the Linear color model. In Gamma, it appears normal, but in Linear (the space we are using) it appears very dark.

The Unity scripting manual briefly explains that it is possible to create a Texture2D in either Linear or Gamma space, but does not go into any detail as to how you can do this, or at least does not give any obvious explanation:

Documentation on Texture2D.Texture2D()

The texture will be width by height size, with a given format, with mipmaps or without and in either the linear or sRGB color space.

If anyone can help me with this problem, it'd be strongly appreaciated and very helpful. Many thanks in advance for taking the time to help.

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
6
Best Answer

Answer by manutoo · Sep 14, 2012 at 08:54 AM

The documentation is incomplete, they forgot to write the (optional) last parameter, you can see it in the Metadata :

public Texture2D(int width, int height, TextureFormat format, bool mipmap, bool linear);

Comment
Add comment · Show 6 · 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 eheimburg · May 16, 2014 at 08:43 PM 1
Share

Thought I'd chime in with a note -- a better name for the variable would be "bypassSRGBColorSpace", like the corresponding checkbox in the texture import GUI. The "linear" boolean doesn't magically make your texture use linear color space if you're using gamma -- it bypasses processing if linear is turned on. The name is unhelpful.

avatar image manutoo · Apr 28, 2015 at 04:05 PM 0
Share

@eheimburg, linear means the texture contains linear colors, so I think it's correctly named.

avatar image Japa · Jul 10, 2015 at 07:16 AM 1
Share

It's not. linear would imply that it would convert the texture when you are in gamma color space, but this is not the case.

avatar image eheimburg · Jul 10, 2015 at 07:53 AM 1
Share

No it isn't, but it's perfectly reasonable to assume that linear means it would make the image use linear colors. Hence the need for a useful variable name.

avatar image Marco-Sperling · Aug 09, 2015 at 08:00 PM 1
Share

Agreed. Na$$anonymous$$g should match texture importer inspector. Else you're left with guesswork.

Show more comments
avatar image
0

Answer by SantiagoMartin · Sep 29, 2017 at 05:15 PM

@manutoo @Zergling103

Hi, I'm dealing with the same problem. I create a Texture2D with bool linear=true to bypass sRGB compensation before entering the shader. My texture, a cosine gray scale function, is set to a shader that applies a gamma correction, col = pow(col, 1/_gamma); - I have my own reasons to do this, I'm working with optometrists in a research project -. The result should be the same no matter if I'm in Gamma Color Space or in Linear Color Space, as far as I know. But it is not. You can see here three results for gamma = 1.72, the firsts two in Linear Color Space (with bool linear true and false) and the third in Gamma Color Space (the results is independent of bool linear value) (this looks right for me). Any suggestion? Thanks

Color space LINEAR - Texture2D bool linear = true (left) and false (right) alt text

Color space GAMMA - Texture2D bool linear = true or false (same result) alt text


colorspacelinear-texture2d-linear-and-srbg.png (12.3 kB)
colorspacegamma-texture2dlinearorsrgb.png (5.7 kB)
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

11 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How would I implement this game mechanic? 0 Answers

Trying to view paper object on button press GUI Texture 3 Answers

How to gradient-wise fill a bitmap programmatically 1 Answer

Setting Scroll View Width GUILayout 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