Cloud shadows in Unity

unity

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

Somthing like this :


#2

Giant low opacity decal maybe? :thinking:


#3

That would be rather expensive haha : P


#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.


#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


#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 all sounded awesome. However I have no idea what a command buffer is :" ). All of that you said almost sounded like an alien language to me. I want to do it and try it, but I have no idea how to even get started with that haha. Even the bottom one you mentioned im not super sure how to do. Any sources you can recommend I look into? Thanks heaps!


#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 with the “big plane in the sky” option is Unity doesn’t really support semi transparent shadows, only fully opaque. The Standard shader does support dithered shadows, which as long a single you’re using soft shadows can be a decent approximation of semi-transparent shadows, but your mileage may vary.


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


#9

That or an animation.

That’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.


#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?


#11

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


#12

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