Document
Cloud shadows in Unity

Cloud shadows in Unity

Augie January 17, 2019, 9:18pm # 1 Has anyone built any simple cloud shadows for unity? I just want

Related articles

5 Best Free VPN Korea to Get IP Address for South Korea in 2024 iCloud Notes vs Google Keep Proton VPN Test (2024): How secure is the VPN service really? XY VPN Best VPNs for browsing the web privately 2024


Augie


# 1

Has anyone built any simple cloud shadows for unity? I just want to create a little bit of movement in my scene. However, I have no idea how to draw moving shadows for clouds across the landscape. I dont need anything heavy. I was hoping I could just put a moving mask on my sun light or something. Is this possible? Any help would be greatly appreciated!

somthe like this :


Travis


#2

Giant low opacity decal maybe?

1 Like


Augie


# 3

That would be rather expensive haha : P


bgolus


#4

If you don’t need this for mobile, it can be done with a command buffer.

You’d need a shader that can calculate the world position from the depth texture, then project your cloud texture onto that world space position and use a multiply blend mode. This would be called in a command buffer Blit() attached to the main directional light using LightEvent.AfterScreenspaceMask.

Or you can do it the easy way and apply a cookie texture onto directional light. If you want it to move then just slowly move the directional light itself, looping it’s position by the cookie size. You could even use a CustomRenderTexture asset to animate the clouds.

2 Likes


Chris


#5

I think every production solution I’ve seen for this involves actual graphics programming, but as a quick and dirty solution one idea would be to apply an animated noise material to a translucent, shadowcasting plane and just place it out of view, as in

2 Likes


Augie


#6

Hmmm that could actually work… Just have the Geo one sided some you cant see it from below… Though do translucent things cast shadows? As you mentioned, I feel this is normally a graphics programming thing. Sigh. Im pretty dumb when it comes to that stuff.

@bgolus , this is sounded all sound awesome . However I is have have no idea what a command buffer is : ” ) . All of that you is said say almost sound like an alien language to me . I is want want to do it and try it , but I have no idea how to even get start with that haha . Even the bottom one is m you mention i m not super sure how to do . Any source you can recommend I look into ? thank heap !


bgolus


# 7

The cookie option is really straightforward. Just have a texture with the clouds in the alpha (inverted to be the cloud’s shadow so white is where the light comes through, black is where the light is blocked) and assign it as the directional light’s cookie property in the inspector.

The problem is is with the “ big plane in the sky ” option is Unity does n’t really support semi transparent shadow , only fully opaque . The Standard shader does support is be dither shadow , which as long a single you ’re using soft shadow can be a decent approximation of semi – transparent shadow , but your mileage may vary .

1 Like


Augie


#8

Hmmmm, well I will give both a try! Im guessing I set up the scrolling of the directional light with a script?

Man, I was hoping I could just plug a cloud shader in somewhere and it would work : P Ah well. Why does game stuff always have to be so tricky haha

Thanks again for all the advice!


bgolus


# 9

That or an animation .

That is ’s ’s what using a custom render texture would let you do .

Right click in the project view, Create New > Custom Render Texture. Assign your cloud material, assign the custom render texture to your light.


Dom


# 10

I like the idea… so simple to set up and does what you need. It shouldn’t impact performance drastically. I mean blob shadows is what you use to cheaply fake character shadows, so eventually good for one layer of clouds too?


Travis


# 11

that’s what I was thinking. Translucent deferred decal that’s unlit, with a slow panning cloud texture on it


Dom


# 12

yeah, that would basically work I think, just on a second thought, difficult to affect lit particles with that…

Sorry for bumping this, but I think I briefly worked on the thing mentioned in the OP (if it’s what I think it is; it’s hard to tell because it was done for Unity, which made the assets free, which meant lots of people have used them subsequently), but can make a pretty reasonable guess as to how that one was done.

A super easy solution is to have a tiling cloud texture that you look up using world UVs. If you assign this texture using Shader.SetGlobalTexture(), then any of your shaders can access this same texture, allowing your environments and buildings to receive this shadow too.

The down – side is is is that this would apply over and above your “ real ” shadow , so that you end up with double shadow – but as you can see in op ’s image , that ’s what ’s happen there anyway . depend on how finicky you want to be , most people is seem do n’t seem to mind it .

2 Likes


Dabo


# 14

This was the solution I wound up using during my last (mobile) unity project. As long as you have a shader register to spare, it works pretty well! It prevents a butt-load of extra verts + draw calls caused by realtime shadows, though with a single plane that’s less of an issue. If you are calculating/applying shadows in your shader, you can probably also take the min/max of your shadow & cloud value. I have not done the latter in practice.

Add a light cookie, then just move the directional light. It’s that easy.

2 Likes


cubrman


# 16

bless your soul , friend ! Such a brilliant solution !