Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
13
Question by flexrails · Dec 02, 2009 at 12:50 PM · shadergraphicsskyboxcrossfade

how to fade in/out a scene?

how do i fade in a scene from a black screen to a skybox? later i want to crossfade the first skybox to a second skybox. finally i want to fadeout the second skybox to a white screen. how do i do that? thanks, flexrails

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 GluedBrain · Sep 22, 2014 at 09:42 AM 0
Share

In case anyone wants to achieve this using the new Unity GUI check out the link below

Add Fade Between Scenes

7 Replies

· Add your reply
  • Sort: 
avatar image
17
Best Answer

Answer by duck · Dec 02, 2009 at 01:03 PM

You'd do the fading to white/black placing a single-colored texture across your screen, and changing the alpha value of it over time so that it fades in, or fades out.

There are a number of different ways of placing this texture on-screen, you could:

  • Use the older method of GUITexture GameObjects from the menu (GameObject -> Create Other -> GUI Texture)
  • Place a plane in front of your camera, or render one using a 2nd camera in your scene
  • Use the newer GUI scripting system to draw the texture

The code you'd use for the 3rd option above might look something like this. You'd start the alphaFadeValue at 1, and the "/ 5" is so the fade lasts 5 seconds.

alphaFadeValue -= Mathf.Clamp01(Time.deltaTime / 5);

GUI.color = new Color(0, 0, 0, alphaFadeValue); GUI.DrawTexture( new Rect(0, 0, Screen.width, Screen.height ), blackTexture );

Comment
Add comment · Show 3 · 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 Pangaea · Jun 24, 2013 at 01:43 PM 0
Share

I keet getting the error $$anonymous$$ identifier 'alphaFadeValue'/ 'black texture'

avatar image brandonsbarber · Jun 24, 2013 at 02:25 PM 0
Share

Pangaea, you cannot copy this verbatim. You need to define instance variables in your classes for these values. For instance, you would instantiate alphaFadeValue as 1 and also create a Texture object in your class called blackTexture. Once you create these, it should work out for you.

avatar image Iggyglass · Feb 04, 2016 at 01:33 AM 0
Share

This is actually fading in...

avatar image
1
Best Answer

Answer by duck · Dec 02, 2009 at 01:04 PM

To fade between two different sets of skybox textures, there's a shader on the Wiki designed to do exactly this, here:

http://wiki.unity3d.com/index.php/SkyboxBlended

Comment
Add comment · Show 4 · 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 flexrails · Dec 02, 2009 at 01:30 PM 0
Share

it says that it requires $$anonymous$$imum hardware. how would i do 2 skyboxes without that $$anonymous$$imum hardware?

avatar image duck ♦♦ · Dec 02, 2009 at 01:59 PM 0
Share

I think these are pretty low-spec hardware requirements. It says "GeForce 3". According to Wikipedia, the GeForce 3 series were introduced in 2001, and were superceded in 2002 by the GeForce 4 series. If you really needed to achieve this on very old hardware, you would probably need to create your own skybox system, where you draw the skybox twice, once with the first skybox texture, then again with the 2nd texture using an alpha-blended shader. You would probably want to use an additional camera in your scene dedicated to this task, so that it gets drawn behind everything else.

avatar image numeric1338 · Mar 16, 2018 at 11:41 PM 0
Share

Link broken "File not found"

avatar image Bunny83 numeric1338 · Mar 17, 2018 at 02:12 AM 0
Share

I've fixed the link

avatar image
3

Answer by Miriam · Jan 16, 2010 at 09:07 PM

I've just been working on the same thing.

I've adapted the wiki shader mentioned above so that it can be used on older machines. It's very similar to the original - I just manged to get rid of one 'set texture' so it can be used on all but the oldest machines (the only Unity emulation mode that doesn't support it is 'dinosaur'). Older machines will show the first skybox only.

Shader "Custom/Skybox" {

Properties { _Tint ("Tint Color", Color) = (.5, .5, .5, .5) _FrontTex ("Front (+Z)", 2D) = "white" {} _BackTex ("Back (-Z)", 2D) = "white" {} _LeftTex ("Left (+X)", 2D) = "white" {} _RightTex ("Right (-X)", 2D) = "white" {} _UpTex ("Up (+Y)", 2D) = "white" {} _DownTex ("Down (-Y)", 2D) = "white" {} _FrontTex2("2 Front (+Z)", 2D) = "white" {} _BackTex2("2 Back (-Z)", 2D) = "white" {} _LeftTex2("2 Left (+X)", 2D) = "white" {} _RightTex2("2 Right (-X)", 2D) = "white" {} _UpTex2("2 Up (+Y)", 2D) = "white" {} _DownTex2("2 Down (-Y)", 2D) = "white" {} _Color ("Fade (use alpha)", Color) = (1,1,1,1) }

SubShader { Tags { "Queue" = "Background" } Cull Off ZWrite On ZTest Always Fog { Mode Off } Lighting Off
Color [_Tint] Pass { SetTexture [_FrontTex] { combine texture } SetTexture[_FrontTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_BackTex] { combine texture } SetTexture[_BackTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_LeftTex] { combine texture } SetTexture[_LeftTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_RightTex] { combine texture } SetTexture[_RightTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_UpTex] { combine texture } SetTexture[_UpTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_DownTex] { combine texture } SetTexture[_DownTex2] { constantColor [_Color] combine texture lerp (constant) previous } } }

Fallback "RenderFX/Skybox", 1 }

To animate between one texture and the next:

private var thisMaterial : Material; private var fadeSpeed : float = 0.4;

function Start (){ thisMaterial = RenderSettings.skybox; thisMaterial.color.a = 0.0; }

function Update () { thisMaterial.color.a += (fadeSpeed * Time.deltaTime); thisMaterial.color.a = Mathf.Clamp(thisMaterial.color.a, 0.0, 1.0); }

To fade from the second skybox to the first skybox start with thisMaterial.color.a=1.0; and use -= instead of +=

To change what you are fading to and from simply change the material variables. Eg, to fade from black to the second skybox texture:

public var blackTexture : Texture2D;

function Start (){ thisMaterial = RenderSettings.skybox; thisMaterial.color.a = 0.0;

 thisMaterial.SetTexture("_FrontTex", blackTexture);
 thisMaterial.SetTexture("_BackTex", blackTexture);
 thisMaterial.SetTexture("_LeftTex", blackTexture);
 thisMaterial.SetTexture("_RightTex", blackTexture);
 thisMaterial.SetTexture("_UpTex", blackTexture);
 thisMaterial.SetTexture("_DownTex", blackTexture);

} function Update () { thisMaterial.color.a += (fadeSpeed * Time.deltaTime); thisMaterial.color.a = Mathf.Clamp(thisMaterial.color.a, 0.0, 1.0); }

To fade between different skyboxes set the different textures like we did above, but this time with your skybox textures, not a single black texture. For the second set of textures use

thisMaterial.SetTexture("_FrontTex2", textureVariable);
etc

Comment
Add comment · Show 1 · 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 fireDude67 · Nov 03, 2010 at 10:19 PM 0
Share

how sad that none of our newer answers get the attention they deserve... :)

avatar image
0

Answer by Azound · Dec 02, 2009 at 04:55 PM

to crossfade between two skyboxes, you could create two skyboxes, one slightly bigger than the other so that it encompasses the other. Then you could fade the inner one's alpha to make it fade in or out.

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 walta · Feb 18, 2010 at 03:15 PM

This way works for me:

alphaFadeValue -= Mathf.Clamp01(Time.deltaTime / 5);
GUI.color = new Color(alphaFadeValue, alphaFadeValue, alphaFadeValue, alphaFadeValue);
GUI.DrawTexture( new Rect(0, 0, Screen.width, Screen.height ), blackTexture );

Comment
Add comment · Show 1 · 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 PaulTurowski · Nov 02, 2011 at 08:36 AM 0
Share

Thanks for the solution, Duck. Just wanted to add that $$anonymous$$athf.Clamp01 should be outside of the incrementing/decrementing or else alphaFadeValue will exceed the range of 0-1:


alphaFadeValue = $$anonymous$$athf.Clamp01(alphaFadeValue - (Time.deltaTime / fadeTime));

  • 1
  • 2
  • ›

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

10 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

Related Questions

Alpha channel support for Skybox/Cubemap shader 0 Answers

(Shader Graph) Output resolution/ setting resolution of the main preview window 0 Answers

How can I disable masked object shadow with DepthMask shader 1 Answer

Scripts not updating the material's shader properties 1 Answer

PBR Standard Shader not Working Project Wide in Unity 5.3 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