Search Unity

Skydome for unity3D 3.x

Discussion in 'Made With Unity' started by Pixelstudio_nl, Dec 13, 2010.

  1. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    Last edited: Jan 9, 2011
  2. stephnx

    stephnx

    Joined:
    Mar 18, 2009
    Posts:
    7
    Can you connect the cloud density variable to the script?
     
  3. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067

    Awwww man, Thats really cool! :(

    Is there a setting to make the sunset last longer? It seemed a bit unnatural when the sunset lasted 1 second. ;)
     
  4. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    As of now there is not and I am not really sure how to make it longer... Though I am trying to figure it out. :)
     
  5. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thanks Tofugames
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I was wondering that myself.
     
  7. DSpawn

    DSpawn

    Joined:
    Jan 11, 2011
    Posts:
    1
    I love this but I have one problem with some shadows that appear from nowhere... and I'm sure that has something to do with Skydome...
    Any idea ?
     
  8. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    you just need to adjust your time increment so it is smaller as you approach sunrise/sunset.

    One mathematical way I can imagine doing it would be something like this

    Code (csharp):
    1.  
    2. effectiveTimeIncrement = originalTimeIncrement -  Mathf.Pow(Mathf.Clamp01((1 - minTimeIncrement - (Math.Abs(sun.y)/domeHeight)),duskDawnEase);
    There might be syntax errors.. it might not even work but you can play around with it. All you are doing is find the distance of the sun from the horizon and slowing time as you get closer to it. The property duskDawnEase controls the steepness of the easing curve.
     
  9. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    I don't think thats what he was talking about... I think he wants the sky to turn orange sooner...
     
  10. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Sooner as in when the sun is higher in the sky? I dunno... try adjusting the Mie scattering coefficient.
     
  11. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    Sorry I think I misunderstood you, yes thats what he meant I think.
     
  12. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    I'm kind of confused now.. So having the sun turn orange when it is higher in the sky z9earlier in the day) is what you wanted, right?? Also everyone: Please keep in mind that I did not make this, it was made by Pixelstudio, and I only changed a few minor things and added a small simple time incrementation script. I am very knew to Unity and C# / Java so if anyone else has any ideas as to how these things (cloud density and long sunset / sunrise) please include them in the discussion. :) I am trying to figure out how to implement / fix these things but I'm not sure I know enough C# or enough about Unity to make them yet..
     
  13. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    If you want the sky to turn orange when the sun is higher in the sky you'll just have to mess around with the parameters which are already exposed. The skydome script is calculating the shifting of the wavelength of light as it passes through particles in the sky. Increasing the Mie factor should affect this as Mie scattering is associated with the orange colors at sunset/rise.

    If you want to mess with cloud-related things you have two options, one is changing the default cloud texure (which I highly recommend. Get a picture of clouds and make it tilable and use that). The other thing you can do is mess with the calculations in the shader. I had zero shader experience when I started to make the color-correction part. It's an opportunity to learn about shaders, it's not as complex as you think.

    Here's a link to the shader intrinsic shader functions in HLSL.

    http://msdn.microsoft.com/en-us/library/ff471376(VS.85).aspx
     
  14. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    Update:
    I edited the script and shader a bit to have the sunset and sunrise colorations start earlier and later, respectively. I have been experimenting a lot with procedurally generating 2D clouds, and have gotten clouds generated procedurally using libnoise, but have had little success getting them to look right in the skydome and am going back to the drawing board on ideas for allowing for cloud manipulation.

    Download: http://dl.dropbox.com/u/16295628/SkydomeUpdated.unitypackage

    ~~Tofugames
     
  15. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    hey guys my shader gives some errors...

    :
    Shader error in 'aScattering 2.1': Shader program had errors at line 41


    Shader error in 'aScattering 2.1': Program 'frag', 'color': local variables cannot have semantics (compiling for xbox360) at line 184


    Shader error in 'aScattering 2.1': Program 'vert', 'color': local variables cannot have semantics (compiling for xbox360) at line 184



    what are they caused by?
     
  16. Tashri

    Tashri

    Joined:
    Jan 31, 2011
    Posts:
    3
    Hello,
    I'm new to Unity and been trying to get this to work correctly for me but having a bit of trouble, any help would be great!

    So everything seems to work right except right in front of my Camera there is this big circle of blue (like when there is no skybox). if its means anything i am useing the lastest download from Tofugames in this tread.

    Also there is one setting im not sure what to do with and thats: Cloud prefab, and its want me to use a gameobject? and ideas?

    Heres a Pic with the Skydome camera setting, set to my first person camera. you can see the skydome in the corners


    Now if i make a new camera and set it out of the way(set the Skydome settings to that camera) i see this when looking in the direction of that camera
     
  17. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Looks like you need to change the camera's far clipping.
     
  18. Tashri

    Tashri

    Joined:
    Jan 31, 2011
    Posts:
    3
    not sure what you mean, is that a setting for the camera?
     
  19. Tashri

    Tashri

    Joined:
    Jan 31, 2011
    Posts:
    3
    Ahh thanks! figured that out, thanks!!
     
  20. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Right. Click on the camera and in the Inspector panel look for "Clipping Planes". Then set the "Far" setting to a number higher than the distance from your camera to the dome. That should fix it.
     
  21. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    and what about my problem? :(

    i cant get the errors to fix...
     
  22. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @Robbilie - You're building for Xbox? I'm afraid I haven't a clue how to fix it.
     
  23. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Is it impossible for it to work without 3.0 shaders? Thx :>
     
  24. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Im getting a nasty error, nothng that interfeer with the compiled version but i wanted to know if there is a work around really bothers me having it:

    !IsNormalized (ray.GetDirection ())
    UnityEditor.DockArea:OnGUI()

    Please Martijn youre the only one who can help me!

    I get it randomly while skydome is functioning.

    And please, is it possible to make a simpler skybox that runs under no shaders at all?

    Thx n hugs!
     
    Last edited: Feb 22, 2011
  25. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Um, just noticed- using this, the sun rises in the south and sets in the north- I'm not quite sure that's right somehow. Also, is there supposed to be a sun script in this package, or is it now all in the skydome script?
     
  26. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    @Fishman92: About the sun script: If you downloaded the one that I posted on the top of this page, it has the sun script which is a separate script from the skydome script and is called "SkyTime"
     
  27. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Ok, but any thoughts on why the sun rises and sets in the wrong place?
     
  28. falkonragno

    falkonragno

    Joined:
    May 31, 2010
    Posts:
    29
    Hello everyone, hello pixel, well I have a question I downloaded last SkydomeUpdated and I create a blank project, then I imported the skydome package but when I just import it I saw this three error messages, does any on eknow how to fix it, Im using win 7 x64, unity 3.2f4 last version and Nvidia 480gtx, Last time I used was with Unity 3.0 and I remember it worked, but now I'm not sure was going on, thanks any help in advance...

    Shader error in 'aScattering 2.1': Shader program had errors at line 41

    Shader error in 'aScattering 2.1': Program 'frag', 'color': local variables cannot have semantics (compiling for xbox360) at line 184

    Shader error in 'aScattering 2.1': Program 'vert', 'color': local variables cannot have semantics (compiling for xbox360) at line 184
     
  29. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Why are you trying to compile for xbox 360?
     
  30. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    !IsNormalized (ray.GetDirection ())
    UnityEditor.DockArea:OnGUI()

    Anyone? Am i the only one having those?

    Thx!
     
  31. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    @Fishman92: I'm not really sure about the sun problem.. I look into it and see what I can find but I doubt I'll be able to find a fix.. Hopefully pixelstudio will see this topic and take a look at it. :)

    @Vinicius: I have pretty much no idea what the problem with that is; But if you're not using Unity 3, then that is probably the problem..
     
  32. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Im using Unity 3.2 newest release. So im the only one getting it. Well i use Windows XP, maybe that the problem? What S.O. are you using? Ive commented the code strategicly and i think its on sun phi calculation or something like that.

    Thx for your reply Tofu =)

    Hugs!
     
    Last edited: Feb 26, 2011
  33. falkonragno

    falkonragno

    Joined:
    May 31, 2010
    Posts:
    29

    Hello Just to clarify, I want to build my project for PC and Mac standalone, I create a blank and clean new project and add the package and after that I saw those error messages, my player settings is set to build for windows and mac, rendering path deferred and I dont want to compile for xbox, I think it have something to do about unity 3.2 cause I use skydome before with unity 3.0 and I did the same and it works, I just import the latest skydome package and it works then, the only difference this time is unity 3.2 maybe some else is having the same problem, or maybe is only me? what could be wrong with my unity editor....?.. appreciate any advise..
     
  34. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Have you got unity pro?
    Unity 3 can't do deferred rendering.
     
  35. falkonragno

    falkonragno

    Joined:
    May 31, 2010
    Posts:
    29
    Yes right now what I have is Unity 3.2 pro installed with, I create a new project and then import the skydome package, nothing more, and I have those 3 errors, and I have no intention of compile for xbox 360, I have my player settings to compile for PC standalone, all my other projects work just fine, but right now I want to use skydome latest pack with latest unity and is not working, last time I use skydome dome was with unity 3.0 and I remember it work just fine when I import it to my project.
     
  36. Vinícius Sanctus

    Vinícius Sanctus

    Joined:
    Dec 14, 2009
    Posts:
    282
    Ok Fixed it, apparently it was an editor´s only bug. If you have same bug as i had, just ignore it, and if you dont feel like seeing it on debug anymore just dont play your project under editor with the scene window visible.

    Hugs!
     
  37. eko1892

    eko1892

    Joined:
    Mar 28, 2011
    Posts:
    139
    Hi Guys, That's really great thank you for sharing this, however I do have a problem. I think I have done everything but for some reason my day and night cycle is not working at all. I can see the sun, clouds are moving but no day and night cycle :/ I was wondering may be you guys could tell me what I am doing wrong. Thanks again !

    Properties tab:
    http://www.box.net/shared/1cx7urrxrp

    Game screenshot
    http://www.box.net/shared/srur9pmf1b
     
  38. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    hmmm, have you tried making the day/night cycle longer, as in make day length 4 minutes?
     
  39. eko1892

    eko1892

    Joined:
    Mar 28, 2011
    Posts:
    139
    Hi there, thanks for your message. I have tried to change the time, it was not a time issue:/ Anyway I have replaced the skydome folder in example package with my skydome folder in the game and it suddenly started to work :)
     
  40. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Cool, glad to hear it was solved.
     
  41. eko1892

    eko1892

    Joined:
    Mar 28, 2011
    Posts:
    139
    Thanks alot :)
     
  42. Dover8

    Dover8

    Joined:
    Aug 20, 2010
    Posts:
    94
    Viper code: have you checked the culling distance on your camera?

    I too am using this awesome package, the updated version with the v2.1 shader. The only thing I notice is that changing to cloud density value makes no difference? I would like to be able to vary the density of the clouds for different seasons etc. Does anyone already have a solution for this? Also what is the cloud prefab variable for and what can it be used for?
     
  43. fosion

    fosion

    Joined:
    Jul 20, 2010
    Posts:
    6
    Hello my Friend i have had the same problem and found a simple workaround.
    I´m using Untiy Pro on a MacBook 2010 M9400 GT .Surely there has to be a better way :) I ´m not really sure what the problem is, maybe our shader writers could tell us.

    I think it has todo something with OpenGL / Direct3D Coordinate Systems (Left / Right Handed),
    There is a "white" Area which is depending on the Y- Position of the Camera, by turning the vertex value in the shader. You turn around the "white" Area to the bottom of the Skydome. As i said there has to be a more elegant solution for this :D

    In the Scattering Shader 2.1
    Code (csharp):
    1.  
    2.     vertex_output vert(appdata_base Input) {
    3.             vertex_output OUT;
    4.            
    5.             //mul( iPos, g_mWorld );
    6.             //float3 vPosWorld = Input.vertex;
    7.             float3 vPosWorld = mul(UNITY_MATRIX_MV,Input.vertex);
    8.            
    9.             //float3 ray = vPosWorld - g_vEyePt;
    10.             float3 ray =  ObjSpaceViewDir(Input.vertex * -1); // HERE Simple Workaround
    11.             float far = length(ray);
    12.             ray = normalize(ray);
    13.             float Theta = dot(ray, LightDir);
    14.             float SR =(1.05f-pow(ray.y,0.3f)) * 2000;
    15.             float SM=far*0.05f;
    16.             float3 L=Lin(Theta, SR, SM );
    17.  
    18.             //cloud stuff
    19. ...
    20.  
    Next I´m goind to test if this is a problem with the 3D Model.

    Greetings from Berlin

    Frank
     
  44. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    ^^ Change the cloud tint colour and height. Make the tint a dark grey, it's just the over bright clouds.
     
  45. fosion

    fosion

    Joined:
    Jul 20, 2010
    Posts:
    6
    Hey Master, are you on working on a Mac?
    here some screener ...

    Without modifikation


    With the really dirty fix


    maybe you can tell me what we see here...
    Seams to me that the sky is on the bottom of the Skydome ^^

    Changing tint values or Cloud height really changes nothing except the height of my clouds on the ground of my Skydome, lol
     
  46. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    I was having some issues with the Skydome that I corrected, and wanted to share the changes with anyone that's interested.

    1. The script uses GameObject.Find to grab the SunLight object when it starts, but when SunLight is deactivated it can't find it, so you start to proliferate extra orphan game objects.

    2. LATITUDE and LONGITUDE are public variables, but they aren't actually used in the script beyond the Initialize() stage, so there's no way to adjust lat and lon while the script is running.

    3. The code in the OnEnable and Start functions is identical, so I moved it into the Initialize function.

    If none of this is making sense to you, it's entirely possible that I have an old version of the Skydome script (there are about 8 different versions running around). If so, can someone direct me to the latest version?

    Below are my additions. We also added a night sky to the skybox that is the actual milky way and turns just as the sun does (and changes with lat/lon), so if anyone is interested in that let me know.
    Thanks,
    Julien


    Changed / New Functions:
    Code (csharp):
    1.     void Start () {
    2.         Initialize();
    3.     }
    4.    
    5.     void OnEnable () {
    6.         Initialize();
    7.     }
    8.  
    9.     void OnDisable() {
    10.         DestroyImmediate(sunObj);  
    11.     }
    12.    
    13.     // set up sun and precalculate variables, this has not to be done very frame so we can speed up things.  
    14.     void Initialize() {
    15.         //Check to see if we have a sun linked to our public variable; if not, create one
    16.         if (sunLight == null)
    17.         {
    18.             sunObj = GameObject.Find("SunLight");
    19.             if (sunObj == null)
    20.                 sunObj = new GameObject("SunLight");
    21.             sunLight = sunObj.GetComponent<Light>();
    22.             if (sunLight == null)
    23.                 sunLight = sunObj.AddComponent<Light>();
    24.         }
    25.         else //sunLight is already defined, so we already have a sunObj too
    26.         {
    27.             sunObj = sunLight.gameObject;
    28.             sunObj.active = true;
    29.         }
    30.  
    31.         sunLight.type = LightType.Directional;
    32.         sunLight.flare = sunFlare;
    33.         sunLight.shadows = shadowType;
    34.  
    35.         LATITUDE_RADIANS = Mathf.Deg2Rad * LATITUDE;
    36.         LONGITUDE_RADIANS = Mathf.Deg2Rad * LONGITUDE;
    37.         STD_MERIDIAN = MERIDIAN * 15.0f;
    38.     }
    39.  
    40.     //LAT and LON are public but not used after initialization.  With this function we can change them while the script is running.
    41.     public void changeLatLon(float newLatitude, float newLongitude)
    42.     {
    43.         LATITUDE = newLatitude;
    44.         LONGITUDE = newLongitude;
    45.         LATITUDE_RADIANS = Mathf.Deg2Rad * LATITUDE;
    46.         LONGITUDE_RADIANS = Mathf.Deg2Rad * LONGITUDE;
    47.     }
     
  47. CodeAssembler

    CodeAssembler

    Joined:
    Oct 15, 2011
    Posts:
    33
    Thank you for this code. Im implementing this. I already have most of it working the way I want it but I will keep working a it some more. I'll return and post a link to my current work when I finish it. What I'm looking for right now is to make the skydome a tad "transparent" so I could put some elements outside of it and they can still be seen from inside the skydome. (Think a giant battle shipt in orbit or some close planet, etc..)

    If I do finish it I will post it back with all the mods [and with nice instructions :) ] so I can contribute back!


    Can I have the code that was mentioned about with the Moon stuff on it? I would really like to see it in action!

    - Luis
     
  48. thieum

    thieum

    Joined:
    Apr 8, 2011
    Posts:
    61
    Hi.
    the skydome project is a really great and welcome contribution. I noticed it only few days ago.
    Sounds like there were no further improvements recently, but it really disserve a new and stable package.

    I experienced weird bugs with one of the previous packages.
    On my XP / ATI1400, the shader "2.1" submitted by Antitheory isn't working at all : worse, I can't access the gameobject, and even the editor view could refresh anymore until I delate the gameobject. :°s
    So back on the "2.0" shader, as found in Pixelstudio original release, it makes the job.
    Then the skytime script by Tofugames remains an usefull addition. I wonder about the sun.cs one, I couldn't get what it's doing yet. I guess all the function have been added to the skydomeScript2 then.
    I guess Nooa _Julien is right with his comment above, I would also suggest to comment out the deactivation of sunLight.gameObject in skydomescript2...

    I'm now struggling with a strange behavior. The sun is represented by it's flare, but it disappears long time before sunset (TIME = 17.8) whatever the other settings I tried. I guess it relies on the sunLight.color function that start to decline, but it's such a complex calculation that I couldn't tweak it. MIE and Raleigh function are really too hard edge science for me :°o

    Does anyone have a clue about this disappearing flare?
     
  49. CodeAssembler

    CodeAssembler

    Joined:
    Oct 15, 2011
    Posts:
    33
    Yes, is a nice contribution for sure. I'm really thankful of the original and later coders too. I don't have a clue of what is happening to your scene. I too had better results using the old 2.0 shader. Somehow in the 2.1 shader if you do not lower the skydome enough then the bluish color is so strong that you don't get to see the clouds well when playing... I agree that the Light Object behavior is annoying to say the least. I did gave up and ended editing the default values for the Sun Light Object at the Shader 2.0 level so I don't keep loosing the settings each time.

    I did not choose to comment out the code for the Deactivation... Hum... maybe that has something to do with the Light Object on your code not working as expected at the sunset?

    I'm mostly happy with the results I got so far: http://www.facebook.com/photo.php?v=10150494343488452&set=vb.710998451&type=2&theater

    What I would like to do now is to set some alpha level in the shader. I would like to put some objects beneath it and the only way would be to make it a tad translucent. Lets see if I do manage to edit it successfully.

    - Luis

     
  50. thieum

    thieum

    Joined:
    Apr 8, 2011
    Posts:
    61
    Regarding my question about the disappearing SunFlare, I came up to a temporary conclusion : from a certain pov, the light source is occluded by a collider...
    In skydomeScript2.cs the skydome follows your camera position (so don't worry about scaling it gigantic, together with your camera far clip), but the sunLight doesn't. It stays right in the middle of the universe, rotating around it's axe.
    I wonder about the reason why : rotation could stand for both rotation and revolution, right? But position is computed from many calculations, and I could'nt tweak it without breaking the set up so far... (My scene represents a 20*20km landscape, so I can be far away from the center).

    btw : one should also remove the Cam variable and replace it by "camera.Main" (1 occurrency in the main script), as to be able to switch between different cameras.

    Regarding Luis' wish : you could implement alpha's of your choice in the shader... Look line 121, 122, 126 : different alphas used... But it might be quite challenging to have an object appearing somehow between the background stars and the foreground clouds, depending of what result you're looking for.

    Let us know!