• 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
Question by OnEd0t · Jun 21, 2020 at 09:38 AM · shadermaterialrendererskyboxrendersettings

Rotating and lerping to another material with custom shader.

HI, It all started when i wanted to make a moving skybox, And it turn out to be quite as simple as changing the _Rotation variable in the standard "6 sided skybox" shader with RenderSettings.skybox.SetFloat("_Rotation", rot += skyRotSpeed * Time.deltaTime);.
Then it got a little more complicated when i wanted after a 20s timer to change the skybox material to another one, and oh boy t$$anonymous$$s wasn't as easy as just: RenderSettings.skybox.Lerp(curSky, nextSky, skyLerpVal * Time.deltaTime); as you can see t$$anonymous$$s line should lerp to the "nextMaterial" material but surprise... it doesn't, I don't know if t$$anonymous$$s is actually the way to do it but what i do know is that i am not the only one around the internet who is facing t$$anonymous$$s issue and Have't found a solution.


Fast forward two hours of looking around i found a work around w$$anonymous$$ch is using a custom shader ( Script down There ) and it actually worked, well semi worked. It worked for actually lerping to another material but presented an issue with it:

1) Now i am not a shader expert by any means but that shader doesn't have the _Rotation variable w$$anonymous$$ch presented me the loss of the ability to rotate the skybox, I tried to copy the code from the standard "6 sided skybox" shader to t$$anonymous$$s custom one but no success ( NOTE: I have absolutely no experience with working with/writing shaders ).


2) I might need to swap between more than just two skyboxs, my initial thought was to just have a list of materials and iterate through it and lerp from the current one to the next using the index, but as i said, the RenderSettings.skybox.Lerp(curSky, nextSky, skyLerpVal * Time.deltaTime); method didn't really work so if there is a better solution to swap between more than two materials i would appreciate it.

Custom Shader:

 Shader "Skybox/Blended" {
 Properties {
     _Tint ("Tint Color", Color) = (.5, .5, .5, .5)
     _Blend ("Blend", Range(0.0,1.0)) = 0.5
     _FrontTex ("Front (+Z)", 2D) = "w$$anonymous$$te" {}
     _BackTex ("Back (-Z)", 2D) = "w$$anonymous$$te" {}
     _LeftTex ("Left (+X)", 2D) = "w$$anonymous$$te" {}
     _RightTex ("Right (-X)", 2D) = "w$$anonymous$$te" {}
     _UpTex ("Up (+Y)", 2D) = "w$$anonymous$$te" {}
     _DownTex ("Down (-Y)", 2D) = "w$$anonymous$$te" {}
     _FrontTex2("2 Front (+Z)", 2D) = "w$$anonymous$$te" {}
     _BackTex2("2 Back (-Z)", 2D) = "w$$anonymous$$te" {}
     _LeftTex2("2 Left (+X)", 2D) = "w$$anonymous$$te" {}
     _RightTex2("2 Right (-X)", 2D) = "w$$anonymous$$te" {}
     _UpTex2("2 Up (+Y)", 2D) = "w$$anonymous$$te" {}
     _DownTex2("2 Down (-Y)", 2D) = "w$$anonymous$$te" {}
 }
 
 SubShader {
     Tags { "Queue" = "Background" }
     Cull Off
     Fog { Mode Off }
     Lighting Off
     Color [_Tint]
     Pass {
     SetTexture [_FrontTex] { combine texture }
     SetTexture [_FrontTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
     }
     Pass {
     SetTexture [_BackTex] { combine texture }
     SetTexture [_BackTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
     }
     Pass {
     SetTexture [_LeftTex] { combine texture }
     SetTexture [_LeftTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
     }
     Pass {
     SetTexture [_RightTex] { combine texture }
     SetTexture [_RightTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
     }
     Pass {
     SetTexture [_UpTex] { combine texture }
     SetTexture [_UpTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
     }
     Pass {
     SetTexture [_DownTex] { combine texture }
     SetTexture [_DownTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous}
     }
 }
 
 Fallback "Skybox/6 Sided", 1
 }

Thank you in advance.

Oh and i will definitely use some exposure.

Comment

People who like this

0 Show 0
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

282 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Anyway to detect for missing material from Renderer component? 1 Answer

Skybox not correctly alpha blending with custom Shader 1 Answer

Change Material by equipping item 0 Answers

Materia Drag & Drop Bug 0 Answers

Accessing shader colors 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