Skydome for unity3D 3.x

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.

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!!!

1 Like

Thanks, I’ll give it a try!

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?

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?

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 :slight_smile: 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

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.

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!

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…

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… :slight_smile:

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

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)

hmmm cant get it to work… does it need pro?

Maybe post a webplayer?

yes a webplayer please ?

it’s easy to get working, just rather putting the conrol script on a n empty GO, put it on the sphere mesh.

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=Lg_vSunColorSunColorIntensity;

So something like

OUT.color.rgb = Saturate(Lg_vSunColorSunColorIntensity, 0.4);

I’ll try porting my HSV thing over to shaderlab… my first experiment shaders… I’ll post anything here if it works.

Love to see what you are making :slight_smile:

Okay so here I found some fast RGB-HSV and HSV-RGB conversion methods…

float3 RGBtoHSV(in float3 RGB)
		{
			float3 HSV = float3(0,0,0);
	
			HSV.z = max(RGB.r, max(RGB.g, RGB.b));
			float M = min(RGB.r, min(RGB.g, RGB.b));
			float C = HSV.z - M;
		
			if (C != 0)
			{
				HSV.y = C / HSV.z;
				float3 Delta = (HSV.z - RGB) / C;
				Delta.rgb -= Delta.brg;
				Delta.rg += float2(2,4);
				if (RGB.r >= HSV.z)
					HSV.x = Delta.b;
				else if (RGB.g >= HSV.z)
					HSV.x = Delta.r;
				else
					HSV.x = Delta.g;
				HSV.x = frac(HSV.x / 6);
			}
			return HSV;
		}

		float3 Hue(float H)
		{
			float R = abs(H * 6 - 3) - 1;
			float G = 2 - abs(H * 6 - 2);
			float B = 2 - abs(H * 6 - 4);
			return saturate(float3(R,G,B));
		}

		float3 HSVtoRGB(float3 HSV)
		{
			return ((Hue(HSV.x) - 1) * HSV.y + 1) * HSV.z;
		}

		float3 Saturate(float3 rgb, float h, float s, float b) {
			float3 hsv = RGBtoHSV(rgb);
			hsv.x = fmod(hsv.x+h,360);
			hsv.y = clamp(hsv.y*s,0,1);
			hsv.z = clamp(hsv.z*b,0,1);
			return (HSVtoRGB(hsv));
		}

and then try something like this:

OUT.color.rgb=Saturate(Lg_vSunColorSunColorIntensity,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…

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:

Would it be possible to repack this as a package? I’d love to give it a spin with the new colors.

Here’s the package with the color-correction stuff in the mix.

454833–15924–$SkydomeColorCorrection.unitypackage (247 KB)

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.