Advertisement
Guest User

ObjectShadow.uc

a guest
Apr 7th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ObjectShadow extends Decal
  2.     Config(User)
  3.     Abstract;
  4.  
  5. #exec TEXTURE IMPORT NAME=BlobShadow FILE=Textures\BlobShadow.pcx LODSET=2
  6.  
  7. var() config int ShadowDetailRes; // Must be a value in power of 2
  8. var() float ShadowScaling;
  9. var transient vector OldOwnerLocation;
  10. var transient int OldShadowDetail;
  11. var transient bool bOptionalUpdate;
  12. var ShadowBitMap PLShadow;
  13.  
  14. function AttachToSurface();
  15.  
  16. function Timer();
  17.  
  18. simulated event Tick( float Delta )
  19. {
  20.     local Actor HitActor;
  21.     local Vector HitNormal, HitLocation, ShadowStart;
  22.     local float ShadowDetail;
  23.     local float Distance;
  24.  
  25.     if ( Owner==None || Owner.bDeleteMe )
  26.     {
  27.         Destroy();
  28.         Return;
  29.     }
  30.  
  31.     if (!class'GameInfo'.default.bCastShadow ||
  32.         Owner.Style == STY_Translucent ||
  33.         Owner.bHidden ||
  34.         Owner.DrawType == DT_None)
  35.     {
  36.         DetachDecal();
  37.         bOptionalUpdate = false;
  38.         return;
  39.     }
  40.  
  41.     if (class'GameInfo'.Default.bUseRealtimeShadow)
  42.         ShadowDetail = ShadowDetailRes; // else keep the initial value - zero
  43.     if (bOptionalUpdate && OldOwnerLocation == Owner.Location && ShadowDetail == OldShadowDetail)
  44.         return;
  45.  
  46.     OldOwnerLocation = Owner.Location;
  47.     OldShadowDetail = ShadowDetail;
  48.     bOptionalUpdate = true;
  49.     DetachDecal();
  50.  
  51.     ShadowStart = Owner.Location;
  52.     ShadowStart.Z-=(Owner.CollisionHeight-5);
  53.     HitActor = Trace(HitLocation, HitNormal, ShadowStart - vect(0, 0, 200), ShadowStart, false);
  54.  
  55.     if (HitActor == none)
  56.         return;
  57.  
  58.     if (class'GameInfo'.Default.bUseRealtimeShadow && PLShadow == none)
  59.     {
  60.         PLShadow = ShadowBitMap(Level.AllocateObj(Class'ShadowBitMap'));
  61.         if( PLShadow==None )
  62.             PLShadow = new(Outer)Class'ShadowBitMap';
  63.         PLShadow.ProjectingActor = Owner;
  64.         PLShadow.ProjectDirection = rot(16384,0,0);
  65.         Texture = PLShadow;
  66.         if (PLShadow.USize != ShadowDetailRes || PLShadow.VSize != ShadowDetailRes)
  67.             PLShadow.SetShadowRes(ShadowDetailRes, ShadowDetailRes);
  68.         PLShadow.Softness = GetShadowSoftness();
  69.         PLShadow.StaticLevel = 0;
  70.         Style = STY_AlphaBlend;
  71.     }
  72.     else if (!class'GameInfo'.Default.bUseRealtimeShadow && PLShadow != none)
  73.     {
  74.         PLShadow.ProjectingActor = none;
  75.         Level.FreeObject(PLShadow);
  76.         PLShadow = none;
  77.         Texture = default.Texture;
  78.         Style = default.Style;
  79.     }
  80.  
  81.     Distance = FMax(Owner.Location.Z - Owner.CollisionHeight - HitLocation.Z, 0.f);
  82.  
  83.     if (PLShadow != none)
  84.     {
  85.         if (PLShadow.USize != ShadowDetailRes || PLShadow.VSize != ShadowDetailRes)
  86.         {
  87.             PLShadow.SetShadowRes(ShadowDetailRes, ShadowDetailRes);
  88.             PLShadow.Softness = GetShadowSoftness();
  89.         }
  90.         DrawScale = FMax(Owner.CollisionRadius,16.f)*(12.f/ShadowDetailRes);
  91.         PLShadow.ShadowScale = 1.f/DrawScale;
  92.         PLShadow.Gradience = Min(Distance + 100, 255);
  93.         if (PLShadow.Gradience == 255)
  94.             return;
  95.     }
  96.     else
  97.     {
  98.         DrawScale = Owner.CollisionRadius/70.f * ShadowScaling * (1.f - Distance / FMin(2 * Owner.CollisionRadius, 155.0));
  99.         if (DrawScale <= 0)
  100.             return;
  101.     }
  102.  
  103.     SetLocation(HitLocation + HitNormal);
  104.     SetRotation(rotator(HitNormal));
  105.     AttachDecal(30, vect(1,0,0));
  106. }
  107. simulated function Destroyed()
  108. {
  109.     if( PLShadow!=None )
  110.     {
  111.         PLShadow.ProjectingActor = None;
  112.         Level.FreeObject(PLShadow);
  113.         PLShadow = None;
  114.     }
  115.     Super.Destroyed();
  116. }
  117. simulated static final function byte GetShadowSoftness()
  118. {
  119.     if( Default.ShadowDetailRes<=64 )
  120.         return 0;
  121.     switch( Default.ShadowDetailRes )
  122.     {
  123.     case 128:
  124.         return 1;
  125.     case 256:
  126.         return 2;
  127.     case 512:
  128.         return 3;
  129.     default:
  130.         return 4;
  131.     }
  132. }
  133.  
  134. defaultproperties
  135. {
  136.     MultiDecalLevel=3
  137.     Texture=Texture'BlobShadow'
  138.     DrawScale=0.50
  139.     ShadowScaling=1
  140.     bAttachPanningSurfs=True
  141.     ShadowDetailRes=128
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement