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 $$anonymous$$ · May 07, 2015 at 03:03 PM · cameracolorbackground

HSV to RGB

I am trying to have the camera background color cycle over time by changing the Hue value each frame. I found a script for HSVToRGB but it isn't quite working as the background just shows up black no matter what values i put in.

 #pragma strict
 var cam : Camera;
 var Hcol : float;
 var Scol : float;
 var Vcol : float;
 
 function Start () 
 {
     
 }
 
 function FixedUpdate () 
 {
     
     cam.backgroundColor = HSVtoRGB(Hcol,Scol,Vcol);
 }
 
 function HSVtoRGB(h : float, s : float, v : float) 
 {
     h=h%1;
     s=s%1;
     v=v%1;
     var r : float;
     var g : float;
     var b : float;
     var i : float;
     var f : float;
     var p : float;
     var q : float;
     var t : float; 
     i = Mathf.Floor(h * 6);
     f = h * 6 - i;
     p = v * (1 - s);
     q = v * (1 - f * s);
     t = v * (1 - (1 - f) * s);
     switch (i % 6) 
     {
     case 0: r = v; g = t; b = p; break;
     case 1: r = q; g = v; b = p; break;
     case 2: r = p; g = v; b = t; break;
     case 3: r = p; g = q; b = v; break;
     case 4: r = t; g = p; b = v; break;
     case 5: r = v; g = p; b = q; break;
     }
     return Color(r,g,b); 
 }

No errors appear when i run the game, the values for Hue, Saturation, and Value just all go to zero making the background black. I would like Hue to be zero but saturation to be 150 and value to be 90.

Thank you for any help

Comment
Add comment · Show 4
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 maccabbe · May 07, 2015 at 04:22 PM 0
Share

It appears that HSVtoRGB expects an 0

avatar image Owen-Reynolds · May 07, 2015 at 04:35 PM 1
Share

Are you using 0-1 for h s and v? If you read through the code, that's what it seems to want. Note how various cases just copy h, s and/or v directly into rgb (which are 0-1 in Unity.)

(And the first three lines are nonsense. They seem to be "fixing" non-0-1 values in a really bad way. I'd just delete them.)

avatar image $$anonymous$$ · May 07, 2015 at 05:08 PM 0
Share

Ok i will try that thanks

avatar image $$anonymous$$ · May 07, 2015 at 05:22 PM 0
Share

I got rid of those lines and changed the values i was using then i set it up so hue would increase over time and it works great thanks for the help

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by greggman · May 07, 2015 at 07:07 PM

I'd say the first 3 lines should be

 h=h >= 0 ? h % 1 : 1 - (-h % 1);
 s=Mathf.Max(0, Mathf.Min(1, s));
 v=Mathf.Max(0, Mathf.Max(1,v));

These lines let you safely adjust h, s, and v without worrying about them going out of range. Kind of like Mathf.sin doesn't go out of range.

Otherwise my guess is the switch isn't happy using a float?

Try changing i to an int

  var i : int;
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

20 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

Related Questions

Change the background color attribute of a camera in C#? 2 Answers

How can I create a gradient color background for my game, without using skybox? 2 Answers

A way to set a custom camera.viewport background color? 1 Answer

Randomly Transition Camera Background Color? 2 Answers

How to randomly chenge camerabackground color every 5 seconds? 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