Final Product What You'll Be Creating
If we start UDK and load any default template map, we get a sky dome loaded with its pre-defined time of the day, set along with the animation of the clouds. Well that’s actually the material setup in UDK which is applied to a Skydome mesh and thus we can see the Sun and all the clouds moving, but no shadows on the ground. So today we’ll be learning how to get cloud shadows just by setting up a Cloud material and plugging it into the function of the Light. Yes it’s very easy and looks very Real too, so let’s get started.
Load your UDK and Go to the File menu option, Click on New and choose any Template map from the options. For this tutorial I’ll go with the Midday Lighting as it’s the best time to see any shadows clearly on the Ground.
After selecting the template Midday Lighting you’ll get an empty Map with a cube right in the Center, just ignore that Cube or you can even delete it if you want. Before we proceed, lets save this Map as Realtime Clouds just in case UDK crashes.
Now go to the Content Browser and Create a new package called RT_clouds (or anything you like) and set the Factory Option to Material as shown in the above pic. Before you hit OK give this Material a name as RT_Clouds_Mat and then Hit OK. A new package will be created and a Material Editor window will open, close that window and save the package.
We need a Black and white cloud Texture and it’s very easy to create such cloud textures in Photoshop, but still I’ll show you how to create a simple cloud texture in Photoshop. So load up Photoshop.
Create a new file with a Resolution of 512 by 512.
Now go to Filter>Render>Clouds but before that, make sure that your Foreground and Background colors are set to Black and White. Or simply press D in Photoshop to set the Foreground and Background color to Black and White.
Keep hitting CTRL+F to render the last used Filter (that is the Cloud render) until you see a nice spread out Black and White pattern, and then try to tone the grayish color down just by adjusting the Levels like I have done in the above pic. You should get a similar texture pattern like in the pic above and then save this as cloud.tga.
The above pic is the final texture that we are going to use to setup the Cloud Material in UDK.
Now go to UDK and in the Content Browser load your RT_Cloud Package and Import that Cloud.tga Texture that we created earlier. It’s time to setup the Material so just Double click on the RT_cloud_mat Material to bring up its material editor window.
I have divided the following setup process into 3 Parts (that is A,B,and C) just to understand the setup Better.
Drag and drop that cloud Texture into this RT_cloud_mat material editor and then drag in two expressions, a Panner and a TextureCoordinate. Set the TexCoord’s UTiling to 0.5 and VTiling to 1.0 and plug it into the coordinate of Panner. Now set the Panner Speed of X and Y to 0.02 and plug it into the UVs of the Cloud Texture as shown in the above pic. With the above setup the cloud texture will move only in one direction. Now copy and paste this setup by pressing CTRL+C and CTRL+V respectively.
After copying the above A setup, Delete the TexCoord expression and just add two expressions, a Rotator and a Constant with a value of 0.5 and Plug that Constant into the Time of the Panner expression. And then plug it into the Coordinate of the Rotator and then finally Plug the output of the Rotator into the UVs of the Texture.
The above setup is basically for Random Cloud shadows that rotate and move away. You can change the speed of the Rotation just by simply changing the Constant Value. Now that we have Setup A and B ready, Lets proceed to next setup.
Final Setup C:
As shown in the above pic, Just ADD Setup A & B simply by using an ADD node and then the output is Multiplied with Setup B which is then plugged into the Alpha node of the Linear Interpolation node (Lerp node.) Now Setup A and B are plugged into the node of A and B’s of the Lerp node respectively, and then plug the Lerp node into the Emissive Channel.
In short, Setup A and B is added which is then multiplied with B and then plugged into the alpha channel of the Lerp node. Before we save out this material setup we need to setup some properties of this material, so go to the Properties from Window>Properties option.
As shown in the above pic, In the properties section just change the lighting mode to MLM_UNLIT and Enable/Check the Used As Light Function checkbox under the Mutually Exclusive Usage option. That’s it, your Cloud material is ready so save and exit this material editor and go back to your scene.
We have to add a Function in the Light for the cloud shadows to work, so search for the Dominant light in your scene and go to its Properties window by hitting F4. Now Expand Light>Light Component>Light Component, To enable the Function option, click on the blue icon on the right side to get more options and then click Function from the dropdown option.
You’ll get more options under Function, so just expand it and link the Cloud material in the Source Material Field just by clicking that green arrow on the right side, but make sure your cloud material is selected in the content browser just like in the above pic. But you won’t see any Cloud shadow movement in your scene yet because you need to set the Trace Distance to its Default value.
In the properties of the Dominant light, go to Lights>Light Component>Advanced Lighting and set the Trace distance to Default, just like in the above pic. The moment you click Default you’ll see random shadows animating on the ground surface, that’s the cloud shadow material which is animating on the ground. Just a couple of more tweaks to get it to be a bit more realistic looking.
Expand the Scale option below the Function option of the light properties, Scale X and Y to 2048 and Z to 512, or you can even play with this scale setting to get your desired result. Now that the scaling is done let’s move onto the Light Channel setup.
Now Expand the Lighting Channels under Light Component of the light Properties and Uncheck the Skybox (by default it should be unchecked.) Now select this light and duplicate it by holding the ALT Key and dragging the left mouse button on any axis.
After duplicating the above light, Uncheck all the Lighting Channels except the Skybox of the newly copied light. The moment you uncheck all the channels the icon on the Light Becomes U which means some of the channels or options have been modified. Also just clear the Light Function Source Material. This Light here is dedicated for the Skybox only and the Previous Light is the actual dominate light for the scene.
Now select the Skydome mesh in your scene and hit F4 to bring up its Properties, Expand Static Mesh Component>Lighting>Lighting Channels and in the lighting channels you’ll find a Skybox Option to Enable/Disable it, so we just need to Enable it if it’s Disabled or else leave it. That’s it you’ll now see nice and smooth clouds shadows on the ground animating!
Merry Xmas and a Happy New Year Everyone!