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
0
Question by hashtagswagboard · Dec 21, 2018 at 04:36 PM · shaderrenderingskybox

Gradien Skyboxes problem

Hi, I'm creating a simple game where I would like to have a gradient background with shifting colors and so I have done, and it works in the beginning. But After a while it looks really bad, the colors aren't correct, there's no blend and the colors get "stuck". Does somebody now why? I have tried both skybox, plane and different shaders.

This is my color controller: [code=CSharp]using System.Collections; using System.Collections.Generic; using UnityEngine;

public class GradientController : MonoBehaviour {

 private Material gradientShader = null;

 private Color currentColor0 = Color.white;
 private Color currentColor1 = Color.white;
 private Color targetColor0 = Color.white;
 private Color targetColor1 = Color.black;

 private readonly string COLOR_ONE = "_Color1";
 private readonly string COLOR_TWO = "_Color2";

 private readonly float LERP_SPEED = 0.5f;

 private readonly float COLOR_INCREMENT = 0.01f;

 private void Start()
 {
     gradientShader = RenderSettings.skybox;

     currentColor0 = RandomColor();
     currentColor1 = RandomColor();
     targetColor0 = RandomColor();
     targetColor1 = RandomColor();
     gradientShader.SetColor(COLOR_ONE, currentColor0);
     gradientShader.SetColor(COLOR_TWO, currentColor1);
 }

 void Update ()
 {
     currentColor0 = Color.Lerp(currentColor0, targetColor0, Time.deltaTime * LERP_SPEED);
     currentColor1 = Color.Lerp(currentColor1, targetColor1, Time.deltaTime * LERP_SPEED);

     gradientShader.SetColor(COLOR_ONE, currentColor0);
     gradientShader.SetColor(COLOR_TWO, currentColor1);

     targetColor0 = ShiftColor(targetColor0);
     targetColor1 = ShiftColor(targetColor1);
 }  

 private Color RandomColor()
 {
     return new Color(
         Random.Range(0.1f, 0.9f),
         Random.Range(0.1f, 0.9f),
         Random.Range(0.1f, 0.9f)
     );
 }

 private Color ShiftColor(Color start)
 {
     float minIncrement;
     float maxIncrement;
     float value;

     float[] colors = new float[]{ start.r, start.g, start.b };
     for (int i = 0; i < colors.Length; i++)
     {
         value = colors[i];
         minIncrement = value > COLOR_INCREMENT ? -COLOR_INCREMENT : 0;
         maxIncrement = value < 1 - COLOR_INCREMENT ? COLOR_INCREMENT : 1;
         value += Random.value <= 0.5f ? minIncrement : maxIncrement;
         colors[i] = value;
     }

     start.r = colors[0];
     start.g = colors[1];
     start.b = colors[2];

     return start;
 }

} [/code]

And in the beginning it looks like this: (Correct) https://imgur.com/fL0sSwl then like this: https://imgur.com/chaZcKP

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 hexagonius · Dec 22, 2018 at 07:36 AM 0
Share

i did not come up with the reason, but I came up with a code improvement, maybe it helps to better see the problem:

 private Color ShiftColor(Color start)
  {
      for (int i = 0; i < start.Length - 1; i++)
      {
          start[i] += $$anonymous$$athf.Clamp01((Random.value <= 0.5f ? 1 : -1) * COLOR_INCRE$$anonymous$$ENT);
      }
      return start;
  }

one reasons this might happen:
- colors at their limits might be too extreme. test the gradient for its max and $$anonymous$$ acceptable values

0 Replies

· Add your reply
  • Sort: 

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

165 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

Related Questions

Skybox rendered over sprites in reflection 0 Answers

Skybox reflections stopped working. 0 Answers

Oculus rendeing bug 0 Answers

Skybox blending 2 Answers

Represent Land 3D Area End 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