UDN
Search public documentation:

DevelopmentKitGemsCreatingASimpleBlobShadow
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Unreal Development Kit Gems > Creating Simple Blob Shadows
UE3 Home > Particle & Effects > Decals > Creating Simple Blob Shadows

Creating Simple Blob Shadows


Last tested against UDK Mar, 2011
PC compatible

Overview


Sometimes it isn't necessary to have accurate real time dynamic shadows on your actors, when a simple blob shadow will do the trick. This is also a useful technique when you have many actors on screen that require shadowing; while maintaining performance.

To achieve this effect, you attach a dynamic decal actor to the actor. The rotation of the decal actor can be used if you want to cast long shadows, however decal components do not have a FOV setting so this may not be ideal. The color and the darkness of the shadow is controlled by the decal material instance. Lastly, the size of the shadow projected is controlled by the decal component within the decal actor.

Decal material Layout


This is the decal material layout used to create the shadow. It is using the modulate blend mode. While it is possible to use the transparent blend mode, the modulation blend mode is much cheaper to render on screen (~14 instructions vs ~110 instructions).

SimpleBlobShadowMaterialLayout.png

  • Constant Clamp - This is used to ensure that the output values from all previous calculations wind up being within the 0.f and 1.f range. Modulation does still work with values outside that range, but it is not desirable in this instance.
  • Add - This is used to add the opacity texture mask to the interpolated shadow color. Adding an 'inversed' mask of the shadow, will add 1.f to the areas that are not part of the shadow. Thus, when these values are clamped, they will become 1.f and will be invisible when the decal is rendered.
  • 'Opacity Texture' - This defines the shadow mask. It is not necessary to use a circular shadow, thus you can create other static shadow shapes.
  • Linear Interpolation - This linearly interpolates between (1, 1, 1, 1) and the 'ShadowColor'. By using the 'ShadowColor''s Alpha output you can control how light or dark the shadow is.
  • Constant [1] - This is one of the parameters of the linear interpolation function. This defines the maximum lightness of the shadow, which in this case is 1.
  • 'Shadow Color' - This defines the color of the shadow. It is not necessary to use a black color.

Related topics

Testing the decal material


To test your new simple shadow blob decal material, use the following steps.

  1. Select your decal material in the Content Browser
  2. Right click within the world viewport where you would like the decal to be placed and a context menu will appear
  3. Left click either "Add Movable Decal: *" or "Add Decal: *"

SimpleBlobShadowAddingATestDecal.jpg

Related topics

Creating and modifying decal material instance


Decal material instances allow developers to redefine existing parameters within the material to create a different versions quickly. In this case we allow developers to change the color, brightness or shadow mask. To do this, follow the steps below.

Right click on the decal material within the Content Browser, then select and left click on Create New Material Instance (Constant).

SimpleBlobShadowCreateNewMaterialInstanceMenu.jpg

This dialog box will appear. Enter in where you would like to store the material instance and what you want to call it.

SimpleBlobShadowCreateNewMaterialInstance.jpg

From here, click on the check boxes on the left hand side of the properties you wish to alter. These check boxes define which properties to override. Alter the values as you see fit.

SimpleBlobShadowAlterMaterialInstance.jpg

Repeat the steps above this chapter to test you new decal material instance.

SimpleBlobShadowTestNewMaterialInstance.jpg

Related topics

Adding the simple blob shadow to an actor


There are three ways you could do this. You could attach a movable decal to actors that exist in map via the attachment system or kismet, or you can spawn a decal actor during the game.

Attachment

In this example, a simple blob shadow will be attached to an interpolated actor using the attachment tool that Unreal Editor provides.

Add the actors that you want to attach the Movable Decal Actor to. In this case, I've added a spherical interp actor.

SimpleBlobShadowAttachmentAddActors.jpg

Open the Attachments window. This is now located here by default, and not attached to the Content Browser like before.

SimpleBlobShadowAttachmentOpenAttachment.jpg

Select the actors you wish to attach in the viewport, right click within the Attachments window and click "Add Selected Actors".

SimpleBlobShadowAttachmentAddAttachmentActors.jpg

Click and hold on one of the small black boxes on the right hand side of InterpActor_0 (or the actor you want to attach the decal to), and drag and release on one of the small black boxes on the left hand side of the DecalActorMovable_1 (or the movable decal actor). The movable decal actor is now attached and will move with the spherical mesh.

SimpleBlobShadowAttachmentBindActors.jpg

Related topics

Kismet


In this example, a simple blob shadow will be attached to the player using Kismet.

Add a movable decal actor into the world. SimpleBlobKismetAddDecal.jpg

Select the movable decal actor in the world. Open the Kismet window, by pressing KismetIcon.jpg on the toolbar. Right click within the Kismet space, and add the decal movable actor.

SimpleBlobKismetAddDecalReferenceInKismet.jpg

Add a Player Spawned event by using the context menu. This will allow Kismet to detect when a player is spawned. It can output the instigator (the player's pawn) into an Object variable.

SimpleBlobKismetAddPlayerSpawnedEvent.jpg

Next add the Teleport action by using the context menu. The movable decal actor will not be under the player's pawn when the player first spawns. Thus, we teleport the movable decal actor to the same place as the player's pawn.

SimpleBlobKismetAddTeleportAction.jpg

Set the 'Update Rotation' to false. The rotation of the movable decal actor does not need to be changed.

SimpleBlobKismetTweakTeleportAction.jpg

Next add an Object variable by using the context menu. This allows Kismet to store a reference of the player's pawn, which can be used at a later time.

SimpleBlobKismetAddObjectVariable.jpg

Connect up all of the Kismet nodes. To do so, left click and drag on the small boxes or triangles to the appropriate targets. When the player spawns, the Player Spawned Kisment node will activate and output the instigator into the empty object variable. It then executes the Teleport Kismet node, which teleports the movable decal actor to the same place as the player's pawn stored within the object variable. This ensures that the movable decal actor is in the correct place when the player is spawned in.

SimpleBlobKismetConnectTeleport.jpg

Add the Attach to Actor action by using the context menu. This Kismet node attaches an actor to another actor. In this case, the movable decal actor will be attached to the player's pawn.

SimpleBlobKismetAddAttachAction.jpg

Connect up all of the elements. Appending to the previous instructions, when the Teleport Kismet node is executed, it will then execute the Attach Kismet node. This Kismet node will then attach the movable decal actor to the player's pawn.

SimpleBlobKismetConnectAttach.jpg

Start up the level, and you'll see the red decal is attached to you as you move around.

SimpleBlobKismetInGame.jpg

Related topics

Unrealscript


This method is used when you want to attach shadows onto run time created actors.

Unreal Engine 3 doesn't have a spawnable decal actor by default. The code above can be added and compiled into Engine or your own package.

DecalActorSpawnable.uc
class DecalActorSpawnable extends DecalActorMovable;

defaultproperties
{
  // bStatic and bNoDelete prevent actors from being spawned at run time.
  bStatic=false
  bNoDelete=false
}

The code below is an example of how to attach a spawn able movable decal actor to a pawn.

SimpleBlobShadowPawn.uc
class SimpleBlobShadowPawn extends UTPawn
  placeable;

// The spawned simple blob shadow.
var PrivateWrite DecalActorSpawnable SimpleBlobShadowDecal;
// A reference to the archetyped simple blob shadow actor that we will be spawning.
var(Shadow) const DecalActorSpawnable SimpleBlobShadowDecalArchetype;

simulated function PostBeginPlay()
{
  local MaterialInstanceConstant DecalMaterialInstanceConstant;

  Super.PostBeginPlay();

  // Dedicated servers do not need to spawn the simple blob shadow
  if (WorldInfo.NetMode == NM_DedicatedServer)
  {
    return;
  }

  // No blob shadow archetype
  // The archetype was not the correct class type
  if (SimpleBlobShadowDecalArchetype == None)
  {
    return;
  }

  // Spawn the simple blob shadow actor
  SimpleBlobShadowDecal = Spawn(SimpleBlobShadowDecalArchetype.Class, Self,, Location, Rot(49152, 0, 0), SimpleBlobShadowDecalArchetype);

  if (SimpleBlobShadowDecal != None)
  {
    if (SimpleBlobShadowDecal.Decal != None && SimpleBlobShadowDecal.Decal.GetDecalMaterial() != None)
    {
      // Create a new material instance so that we can alter the parameters dynamically
      DecalMaterialInstanceConstant = new class'MaterialInstanceConstant';

      if (DecalMaterialInstanceConstant != None)
      {
        DecalMaterialInstanceConstant.SetParent(SimpleBlobShadowDecal.Decal.GetDecalMaterial());
        SimpleBlobShadowDecal.Decal.SetDecalMaterial(DecalMaterialInstanceConstant);
      }
    }

    // Attach the simple blob shadow to myself
    Attach(SimpleBlobShadowDecal);
  }
}

defaultproperties
{
}

The logic behind the code is as follows:

  • PostBeginPlay is executed when Actors (which UTPawn is a subclass of) are first spawned.
  • Abort if this actor is on a dedicated server. Dedicated servers don't need to spawn blob shadows.
  • Abort if no shadow archetypes have been set.
  • Spawn an instance of the archetype, facing down. Assign the instance to a variable so we can keep track of it.
  • Check that the decal component has a decal material.
  • If it is does, then create a new material instance and assign its parent to the current decal material. This will allow us to alter the properties without affecting anything else.
  • Attach the spawned archetype to myself (SimpleBlobShadowPawn)

You can place the pawn within the world and start it up in editor and see it. Further advanced aspects have been demonstrated such as using an archetyped decal actor and creating a material instance at run time.

Related topics

Downloads


Download the content used in the examples above. (SimpleBlobShadow.zip)