UDN
Search public documentation:

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

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 > Rendering Occluded Actors
UE3 Home > Materials & Textures > Rendering Occluded Actors

Rendering Occluded Actors


Last tested against UDK Mar, 2011
PC compatible

Overview


In third person games, sometimes it can visually appealing to block the player's view with something interesting. However, this can lead to problems when the player actually needs to be able to view through the blocking pixels. This gem demonstrates a simple, performance friendly method to render occluded actors.

OccludedPawnScreenshot.jpg

Material


This method uses depth checking to alter the opacity of the foreground rendered mesh. To clarify here is the list of steps that the rendering pipeline does.

  1. Render the actor's mesh as per normal
  2. Render an occluded version of the actor's mesh on top; for each pixel
    1. Check the new pixel depth against the existing pixel depth
    2. If the difference in depth is above a value, then continue to render the occluded pixel
    3. Otherwise do not render the pixel

OccludedPawnMaterialNodeSetup.jpg

Material properties

In order to have access to the Scene Depth node in the material, the material must be Translucent. Set the material to Unlit to help with performance.

OccludedPawnMaterialProperties.jpg

Related topics

Example


This is an example of how to add the occlusion effect to a pawn. This can of course be used for other actors such as Static mesh actors. The only condition is that the occluded mesh must match the normally visible mesh in terms of location, rotation and scale.

OccludedPawn.uc
  class OccludedPawn extends UTPawn;
  
  var(Pawn) const SkeletalMeshComponent OccludedMesh;
  
  simulated function SetMeshVisibility(bool bVisible)
  {
    Super.SetMeshVisibility(bVisible);
  
    if (OccludedMesh != None)
    {
      OccludedMesh.SetOwnerNoSee(!bVisible);
    }
  }
  
  simulated function SetCharacterMeshInfo(SkeletalMesh SkelMesh, MaterialInterface HeadMaterial, MaterialInterface BodyMaterial)
  {
    Super.SetCharacterMeshInfo(SkelMesh, HeadMaterial, BodyMaterial);
  
    if (OccludedMesh != None)
    {
      OccludedMesh.SetSkeletalMesh(SkelMesh);
    }
  }
  
  defaultproperties
  {
    Begin Object Class=SkeletalMeshComponent Name=OPawnSkeletalMeshComponent
      Materials(0)=Material'OccludedPawnContent.OccludedMaterial'
      Materials(1)=Material'OccludedPawnContent.OccludedMaterial'
      DepthPriorityGroup=SDPG_Foreground // Render the occluded skeletal mesh in the foreground layer
      ShadowParent=WPawnSkeletalMeshComponent
      ParentAnimComponent=WPawnSkeletalMeshComponent
      bCacheAnimSequenceNodes=false
      AlwaysLoadOnClient=true
      AlwaysLoadOnServer=true
      bOwnerNoSee=true
      CastShadow=false // Casting shadows is not required
      BlockRigidBody=true
      bUpdateSkelWhenNotRendered=false
      bIgnoreControllersWhenNotRendered=true
      bUpdateKinematicBonesFromAnimation=true
      bCastDynamicShadow=false // Casting shadows is not required
      RBChannel=RBCC_Untitled3
      RBCollideWithChannels=(Untitled3=true)
      LightEnvironment=MyLightEnvironment
      bOverrideAttachmentOwnerVisibility=true
      bAcceptsDynamicDecals=false
      bHasPhysicsAssetInstance=true
      TickGroup=TG_PreAsyncWork
      MinDistFactorForKinematicUpdate=0.2f
      bChartDistanceFactor=true
      RBDominanceGroup=20
      MotionBlurScale=0.f
      bUseOnePassLightingOnTranslucency=true
      bPerBoneMotionBlur=true
    End Object
    OccludedMesh=OPawnSkeletalMeshComponent
    Components.Add(OPawnSkeletalMeshComponent)
  
    CamOffset=(X=16.0,Y=64.0,Z=-52.0)
  }
  

This game info subclass is only required to spawn in the OccludedPawn class that was created above.

OccludedGameInfo.uc
  class OccludedGameInfo extends UTDeathmatch;
  
  defaultproperties
  {
    DefaultPawnClass=class'OccludedPawn'
  }
  

Related topics

Limitations


A limitation of this method is the way it checks for occlusion. By simply comparing the depth differences and not checking what rendered the pixel, this method can often perform a lot of occlusions incorrectly.

The best way to over come this limitation is to alter the level geometry to ensure that there is a large depth difference potential.

Downloads


  • Download the source and content used in this gem. (OccludedPawn.zip)