Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Skydome for unity3D 3.x

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

  1. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179


    Cause of the many request i get here is a new Github project for my skydomescript.
    I fixed the script for 3.x, but there could be some errors, im planning to rework some stuff when i have some time.

    https://github.com/Pixelstudio/Skydome

    If you use it, or modify it to make it better pls let me know!

    for the lazy people heres the download : Skydome 2.0
    RENAME the download to .unitypackage!!!!
     
    Kieran Chandler likes this.
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Thanks, I'll give it a try!
     
  3. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    This is awesome, but could be get some (brief) updated documentation for it? There seems to be changes from the last version such as needing a Sky Dome Camera, etc, and I'm not sure what the script is expecting for these new settings.

    edit: figured it out now, I think:

    * skydome camera isn't required or used
    * separate skydome controller isn't required - attach controller script to the mesh itself?
     
    Last edited: Dec 13, 2010
  4. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    Loving this script/shader combo now that I've spend some more time with it and have worked out most of the issues I was having. It looks great, performs well, and is easy to understand. I've extended it slightly to switch on a static "moon" light at night, got the fog colour changing to match the light colour (I'm working on setting it to the horizon colour...) to provide some "atmospherics" to the world, and stopped the aScattering shader itself from being affected by fog to prevent the sky being washed out. It's looking pretty good, for an hour or two of messing about!

    I've got a question, though: I'd like to have the Sun transform/light orbit the center of the skydome so that at a time of 12.00 it is directly overhead. The reason for this is I'd like to use the Sun Shafts image effect, which needs to track a Transform to work correctly. Although the direction of the sunlight in the skydome package is correct, the transform itself seems to be orbiting the origin (0,0,0). I'm guessing that I need to play with the Dome Radius, Longitude, and Latitude options or add an offset to the Sun transform, but I can't seem to get it working correctly.

    Any ideas?
     
  5. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    yeah adjust the radius of the sun to match your size of skydome. ill adjust this in a later release so that all goed automatic :) love to see what you have made tho, perhpas you can make a webbuild. if you need room to upload just let me know!

    Cheers
     
  6. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    Hmm, I did try adjusting the radius to (roughly) match the skydome, but that didn't seem to help. I've scaled up the mesh so that it just surrounds a 4096x4096 terrain, so I set the radius to 2048 and it still rotates in a circle off the edge of the terrain somewhere. I also tried 4096 for the radius, in case you meant diameter. I'll take a proper look through your code when I get time and see if I can figure out what I'm doing wrong, but for now the trigonometry and Rayleigh Scattering maths scare the crap out of me.

    What I've done for now is added an extra script to the scene that gets the forward vector of the directional light, multiplies it by 4096, inverts it, then uses that vector to place an empty GameObject at the "real" sun position in the scene relative to (2048,0,2048). This is updated twice per second, and I plug this gameobject into the "Sun Shafts" image effect. I also had to create a second camera to render the skydome to be able to use the Depth Texture feature of this effect, otherwise the shafts shine through the terrain and other objects.

    I'll see if I can make an example scene or something once I've added a few more things. Next up is changing the fog to match the sky instead of the light colour. It's a shame we don't have support for fog gradients (or even height fog) in Unity, just ghetto 90's distance fog. It would be nice to be able to shade the fog depending on the sun angle, either from yellow->blue or just two shades of blue.

    I've also been trying to match a light cookie to the cloud texture to simulate cloud shadows on the ground, but so far that's been looking terrible when the sun is near the horizon as the cookie texture distorts.
     
  7. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Wow these scripts + shader are pretty awesome. Just what I have been waiting/looking for!

    I am not sure if the "clouds" are really doing it for me though. Considering everything else in this script/shader combo is very physically realistic, I don't think the alpha-clouds really do the whole thing justice. Some kind of volumetric/particle clouds might be preferable, although much slower.

    All in all an excellent addition to Unity!
     
  8. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    The cloud texture provided with this is low res and has some nasty JPEG artifacts. Replace it with a better texture (maybe 1024x1024, if that'll work?) and play with the cloud height, and it should look better. You could also combine it with one of the existing particle cloud packages, I suppose.

    edit: the star texture doesn't work for me...
     
    Last edited: Dec 14, 2010
  9. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    indeed the cloud texture is very basic and roughly made! this can be improved allot.
    Hope to add some 3D clouds if i have the time... :)
     
  10. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Again I just want to preface my comment with my kudos to you for making this and making it available. I have one more critique.

    The colors seem a little "washed out" at times. I have been looking at the algorithms and note that you say "results agree with graph" which presumably is referring to a graph in a physics textbook or something. While this is great, I am afraid at times the results don't agree with reality, the light that we actually perceive in the sky. For example, at dawn and dusk the sky looks a little too brown, and I have failed to get the sorts of vivid blues and purples that I regularly see in the sky...

    I am not calling into question the accuracy of the formulas, just their performance on screen. It's not as if these colours are impossible to achieve on a computer monitor or in a game... we can easily have them in skybox form... I think that there needs to be some "post-processing" adjustment to make the colours more realistic and vivid. I will test out some stuff and let you know.

    Cheers
     
  11. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    there are a couple of things:

    - you can adjust some settings to adjust the colors, such as the Rayleigh and Mie coeficients or turbidity settings,
    - perhaps i need to look at RGB-HSV conversion thingies and/or gamma correction..

    - julian day calculation from current time need to be implementd (i have the formula)
     
  12. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    hmmm cant get it to work... does it need pro?

    Maybe post a webplayer?
     
  13. stefmen

    stefmen

    Joined:
    Apr 14, 2009
    Posts:
    784
    yes a webplayer please ?
     
  14. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,884
    it's easy to get working, just rather putting the conrol script on a n empty GO, put it on the sphere mesh.
     
  15. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Yeah I was able to get better performance after messing with the coefficients a bit, but still the colors are a bit desaturated...

    I whipped up a RGB-HSV method in C#... It "works" but then I realized that this HSV adjustment needs to happen in the shader after the In-scattering step here:

    OUT.color.rgb=L*g_vSunColor*SunColorIntensity;

    So something like

    OUT.color.rgb = Saturate(L*g_vSunColor*SunColorIntensity, 0.4);

    I'll try porting my HSV thing over to shaderlab... my first experiment shaders... I'll post anything here if it works.
     
    Last edited: Dec 17, 2010
  16. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    Love to see what you are making :)
     
  17. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Okay so here I found some fast RGB-HSV and HSV-RGB conversion methods...

    Code (csharp):
    1.  
    2. float3 RGBtoHSV(in float3 RGB)
    3.         {
    4.             float3 HSV = float3(0,0,0);
    5.    
    6.             HSV.z = max(RGB.r, max(RGB.g, RGB.b));
    7.             float M = min(RGB.r, min(RGB.g, RGB.b));
    8.             float C = HSV.z - M;
    9.        
    10.             if (C != 0)
    11.             {
    12.                 HSV.y = C / HSV.z;
    13.                 float3 Delta = (HSV.z - RGB) / C;
    14.                 Delta.rgb -= Delta.brg;
    15.                 Delta.rg += float2(2,4);
    16.                 if (RGB.r >= HSV.z)
    17.                     HSV.x = Delta.b;
    18.                 else if (RGB.g >= HSV.z)
    19.                     HSV.x = Delta.r;
    20.                 else
    21.                     HSV.x = Delta.g;
    22.                 HSV.x = frac(HSV.x / 6);
    23.             }
    24.             return HSV;
    25.         }
    26.  
    27.         float3 Hue(float H)
    28.         {
    29.             float R = abs(H * 6 - 3) - 1;
    30.             float G = 2 - abs(H * 6 - 2);
    31.             float B = 2 - abs(H * 6 - 4);
    32.             return saturate(float3(R,G,B));
    33.         }
    34.  
    35.         float3 HSVtoRGB(float3 HSV)
    36.         {
    37.             return ((Hue(HSV.x) - 1) * HSV.y + 1) * HSV.z;
    38.         }
    39.  
    40.         float3 Saturate(float3 rgb, float h, float s, float b) {
    41.             float3 hsv = RGBtoHSV(rgb);
    42.             hsv.x = fmod(hsv.x+h,360);
    43.             hsv.y = clamp(hsv.y*s,0,1);
    44.             hsv.z = clamp(hsv.z*b,0,1);
    45.             return (HSVtoRGB(hsv));
    46.         }
    47.  
    and then try something like this:

    OUT.color.rgb=Saturate(L*g_vSunColor*SunColorIntensity,0,2,1.25);

    Which doubles the saturation and increased the brightness 25%. Multiplier values work much better than additive for the saturation adjustment... although you might want to play around with that. It DOES make the sky more vivid, but you end up with a different problem, a green halo around the sun at sunset/sunrise... something which we don't (as humans) perceive. Nor does this color-correction ever produce those purple skies I have been hoping for.

    It turns out that this might have something to do with the way our eye perceives color... I am reading up more on it and maybe I'll post some more info later...
     
  18. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Ok so I have taken the liberty to add the color-correction code to the shader. Here are some comparisons.




    I may have gone overboard a little with the color but I wanted to make the difference noticeable. Two things are happening here.

    1. The color is being modified like the curves tool in Photoshop through a custom color ramp texture. Explanation here under "Curves"
    2. The RGB color is converted to HSB allowing you to adjust the saturation and brightness from the editor.

    The first one turned out to have the most significant impact. Without the color ramp, you end with weird green hues when you up the saturation. Here is a screenshot of the curves from photoshop:

     
  19. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Would it be possible to repack this as a package? I'd love to give it a spin with the new colors.
     
  20. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Here's the package with the color-correction stuff in the mix.

    View attachment $SkydomeColorCorrection.unitypackage

    Let me know how it works for you. If you want to make your own color ramp you can take the "default curve.png" file into Photoshop (or Gimp) and apply your own color correction to it. Save it as a new file and use it as your "curveTexture" in the material.

    To make "vivid curve.png" I just took a bunch of screenshots of the sky without any adjustments and then messed around with the curves tool in photoshop until I had the desired colors. You can save the curve in photoshop and apply it to your color ramp. The details are laid out here: http://http.developer.nvidia.com/GPUGems/gpugems_ch22.html

    I don't know if the shader will work on all platforms now because it uses the tex2D() method which means I had to use SM3.0... (I'm not too sure as this is the first time I've ever done anything with shaders).

    The weird thing is that other SM3.0 shaders don't work on this computer... I would like to here how it works for others. The tex2D() call is not totally necessary as you could just store the color-corrected values in a lookup table, populated in C# and passed to shader only when you alter the curveTexture.
     
  21. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Got it. Will test it tomorrow, thanks!
     
  22. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Oh I almost forgot:

    Make sure the texture you use as curveTexture is set to "clamp" or else you will get some weird results when the sun dips below the horizon.

    Thanks again to PixelStudio for this awesome script/shader. Now all we need is astronomically accurate lunar cycles ;)
     
  23. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    @PixelStudio Antitheory - Gave the packages a try on my Macbook Pro. Works perfectly and I love the colors! I'll give it a spin on my windows machine tomorrow, but just couldn't wait to give it a try. Thank you both very much!
     
  24. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    can you guys post a webplayer for us unity basic users?
     
  25. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Hey no problem. The thanks should really go to PixelStudio, I'm just a nitpicker. Usually game designers go overboard with color saturation but I felt this was the one case where we needed more of it. It's strange that the physically accurate models PixelStudio used to compute the vertex colors weren't cutting it.

    Anyhow I have another thing you might like. change this line 198 in the shader to...
    Code (csharp):
    1.  
    2. color+= tint*cloud_color.a*(intensity)*float4(Saturate(g_vSunColor,0,1.5,1,0,0),1);
    3.  
    Now you have nice orangey-purple clouds at sunset :) You'll probably want to turn the "tint" up a bit in the inspector.

    Oh, and make sure you check "Generate Alpha from Greyscale" for whatever clouds texture you are using. I wasn't getting any stars until I checked this off. As soon as I looked at the code for the clouds it became pretty obvious.

    Its not a complete cloud lighting solution, because really the clouds should be darker "on top"... But seeing as how they are a flat texture they don't really have a "top".

    I am using Unity Basic and it works fine here. Have you tried the package?
     
    Last edited: Dec 18, 2010
  26. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Oh I just realized that "saturate" is a built-in function in Cg. I guess I shouldn't have named my method "Saturate"... bad practice
     
  27. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    hmmm.... It did not seam very organized... I could not find out how to get it to work I guess..
     
  28. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    You need to drag the camera light to the respective slots in the inspector. Basically follow the error messages that appear when you launch it. Easy-peasy.
     
  29. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    I am able to get everything into unity and see it and it works perfectly fine, however the sun does not rotate or orbit at all.. Is there something I need to setup to make it do this?? I have all of the objects setup int eh skydome script, and have the radius set correctly, but it still won't rotate for some reason.. Is there something that I am forgetting to do??? Any help would be great, Thanks! :)
     
  30. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    There must be a typo because that throws a bunch of errors. Line 198 is this one: "color+=(g_vSunColor.z+tint)*cloud_color.z*(intensity)*cloud_color;"

    I'm running it on Unity Pro and so far only on my Mac. Haven't had a chance to test it on my PC yet.
     
  31. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Yeah there is a typo sorry... somehow a space got thrown in the middle of the variable g_vSunColor. Here is the correct line:

    Code (csharp):
    1.  
    2. color+= tint*cloud_color.a*(intensity)*float4(Saturate(g_vSunColor,0,1.5,1,0,0),1);
    3.  
     
  32. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Are you getting any errors? Most likely you have forgotten to set the Skydome parameter in the Sun inspector. Check your Sun gameobject and make sure you have it setup. You will also want to set the "Dome radius" variable in there too, set it to (you guessed it) the radius of the skydome.

    BTW:
    The sun doesn't automatically rotate, but you can set the position based on the time, calendar date, and longitude/latitude. You could write a fairly simple script that increments the "time" if you want the sun to animate. Additionally you could keep the position geographically accurate if you change the longitude/latitude variables as you move around.... however you would have to be moving pretty damn fast (useful for a flying game, for example).
     
  33. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    That fixed it, thanks!
     
  34. houndie

    houndie

    Joined:
    Nov 25, 2010
    Posts:
    146
    Beautiful work .. thanks so much for this!!
     
  35. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    Great work people,

    Love the better color controls! special thanks to Antitheory!
    i adjusted the script and put the sun stuff inside the skydome class, think i like it better this way.

    think tomorrow i add stuff to caculate a right julian day.

    All the stuff is here: https://github.com/Pixelstudio


    post screenshot and settings if you have a nice setup!

    i also was trying to implement other clouds, with a particle system and billboards to simulate them....
     
  36. Antigollos

    Antigollos

    Joined:
    Nov 29, 2009
    Posts:
    117
    Great Stuff!!! No doubt! But the online storage looks a bit messy xD
    would you please make a new updated package? so i don't need to download the asset folder with all the files in it spearatly, cause the inclued package is from 13. dez., which is compared to the asset folder outdated.

    xD BIG THNX!!!

    Skydome is an absolutly nesessary feature unity was missing!!!
     
  37. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    can you make a tutorial for us noobs? I can't get it to look right in unity :(
     
  38. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    Wellll, you'll need all the stuff inside the skydome folder exclusive the old shader.

    Then just create a sphere, put the shader on it and put the script on it.
    Apply settings and press play....
     
  39. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067

    a little short ;)

    I made all the cameras lights and other objects needed and still got some errors and it did not look right.

    Could you maybe include in the unity package a scene with all the variables set right?

    thanks
     
  40. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    Here is a unity package with a few changes to it that I made.

    Changes:

    -Made the Star Texture Work
    -Added a separate script to control a basic Time Cycle

    I'm still new to Unity and still learning the scripting so my Time Cycle script may be inefficient and / or have bugs and I'm not sure how accurate it is (it lets you input how long you want a game day to last in real minutes, and I'm not sure how accurate my equation for this is...). Here is the link:

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

    Edit: Oops, just realized that I left some unnecessary stuff in the package. I'll re-package it and re-upload it real quick..

    Edit 2: Okay, package re-uploaded.

    Edit 3: There is one problem however, and I'm not sure how to fix it.. The problem is that once the sun sets, the color of the light remains the red-orange color that it was when the sun set, even after the sun is completely gone.. This means that on tall mountains and such, there is still an orange glow even after the sun has gone down.. I'm not sure how to fix this, but if someone more knowledgeable could take a look at it, that would be awesome!

    ~~Tofugames
     
    Last edited: Dec 29, 2010
  41. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    Any update on a package with the skyDome set up in it?

    thanks!
     
  42. renton_u3d

    renton_u3d

    Joined:
    Oct 26, 2010
    Posts:
    9
    Is there any project that this skydome-system already built in ?
     
  43. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    i have used this in projects ofc :)
     
  44. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,884
    When i use this, I look up, and the skydome looks really dark at the top, not like real sky... need a way to change this. Also, any way to make the sunrise/set last longer?
     
  45. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    I am uploading an example project right now. It should be done in about an hour, at which point I'll update this post with a link. I am not sure about making sunrise/set longer. Maybe send pixelstudio a pm?

    EDIT: Well that didn't take nearly as long as I thought it would. Here is the example:

    ~~About 33 mb compressed, and about 60 uncompressed.

    http://dl.dropbox.com/u/16295628/Skydome Example.zip

    ~~Tofugames
     
    Last edited: Jan 8, 2011
  46. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,884
    Cool, but any reason why the sky has a purple tint to it?
     
  47. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    To fix that go into the skydome object, open the material at the bottom, and change the curve to the default curve instead of the one that it currently is set to. If you don't have the default curve, download: http://dl.dropbox.com/u/16295628/default curve.png
     
  48. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067

    Thanks for the package tufogames. It looks sort of the way it did before, Thats why I was wondering if I was doing something wrong.

    Here is a pic of what it looks like on my computer... I have a macbook from mid 2009. And am using unity 3 basic.


     
  49. Tofugames

    Tofugames

    Joined:
    Nov 29, 2010
    Posts:
    37
    @3dDude That's strange.. I think there are a few problems int the shader that make it only work on windows possibly.. I know when I originally opened it, it told me that there were some mac only and windows only script endings (or something like that) so I'm not really sure what that could be.. Sorry. :( If you know about shader editing, maybe you could see if you could fix it? I don't know anything about shader editing and am only just learning C# (I know a lot of C++, so it's not too difficult because they are fairly similar) so I don't think I can fix anything. :( You could also try running it on a windows machine if you have one handy. Note to everyone else reading this topic: I did NOT create this, it was made by pixelstudio and I only changed a few things and re-uploaded it so that anyone who wanted my changes could use them. Also, here is a slightly updated version which fixes the problem I talked about earlier (the red glow after the sun setting).

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

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067

    Well ok thats to bad.. But its not your fault.

    Maybe you could post some pictures so I could see what I am missing ;) ?
     
unityunity