Advertisement
Guest User

ObjectShadow.uc

a guest
Apr 7th, 2018
64
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() config 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.  
  24.     if ( Owner==None || Owner.bDeleteMe )
  25.     {
  26.         Destroy();
  27.         Return;
  28.     }
  29.  
  30.     if (!class'GameInfo'.default.bCastShadow ||
  31.         Owner.Style == STY_Translucent ||
  32.         Owner.bHidden ||
  33.         Owner.DrawType == DT_None)
  34.     {
  35.         DetachDecal();
  36.         bOptionalUpdate = false;
  37.         return;
  38.     }
  39.  
  40.     if (class'GameInfo'.Default.bUseRealtimeShadow)
  41.         ShadowDetail = ShadowDetailRes; // else keep the initial value - zero
  42.     if (bOptionalUpdate && OldOwnerLocation == Owner.Location && ShadowDetail == OldShadowDetail)
  43.         return;
  44.  
  45.     OldOwnerLocation = Owner.Location;
  46.     OldShadowDetail = ShadowDetail;
  47.     bOptionalUpdate = true;
  48.     DetachDecal();
  49.  
  50.     ShadowStart = Owner.Location;
  51.     ShadowStart.Z-=(Owner.CollisionHeight-5);
  52.     HitActor = Trace(HitLocation, HitNormal, ShadowStart - vect(0,0,500), ShadowStart, false);
  53.  
  54.     if (HitActor == none)
  55.         return;
  56.  
  57.     if (class'GameInfo'.Default.bUseRealtimeShadow && PLShadow == none)
  58.     {
  59.         PLShadow = ShadowBitMap(Level.AllocateObj(Class'ShadowBitMap'));
  60.         if( PLShadow==None )
  61.             PLShadow = new(Outer)Class'ShadowBitMap';
  62.         PLShadow.ProjectingActor = Owner;
  63.         PLShadow.ProjectDirection = rot(16384,0,0);
  64.         Texture = PLShadow;
  65.         if (PLShadow.USize != ShadowDetailRes || PLShadow.VSize != ShadowDetailRes)
  66.             PLShadow.SetShadowRes(ShadowDetailRes, ShadowDetailRes);
  67.         PLShadow.Softness = GetShadowSoftness();
  68.         PLShadow.StaticLevel = 0;
  69.         Style = STY_AlphaBlend;
  70.     }
  71.     else if (!class'GameInfo'.Default.bUseRealtimeShadow && PLShadow != none)
  72.     {
  73.         PLShadow.ProjectingActor = none;
  74.         Level.FreeObject(PLShadow);
  75.         PLShadow = none;
  76.         Texture = default.Texture;
  77.         Style = default.Style;
  78.     }
  79.  
  80.     if (PLShadow != none)
  81.     {
  82.         if (PLShadow.USize != ShadowDetailRes || PLShadow.VSize != ShadowDetailRes)
  83.         {
  84.             PLShadow.SetShadowRes(ShadowDetailRes, ShadowDetailRes);
  85.             PLShadow.Softness = GetShadowSoftness();
  86.         }
  87.         DrawScale = FMax(Owner.CollisionRadius,16.f)*(12.f/ShadowDetailRes);
  88.         PLShadow.ShadowScale = 1.f/DrawScale;
  89.         PLShadow.Gradience = Min(FMax(ShadowStart.Z-HitLocation.Z,0.f)/700.f*255+100,255);
  90.         if (PLShadow.Gradience == 255)
  91.             return;
  92.     }
  93.     else
  94.     {
  95.         DrawScale = Owner.CollisionRadius/35.f * FMin(1.0, ShadowScaling) * (1.f-FMax(ShadowStart.Z-HitLocation.Z,0.f)/500.f);
  96.         if (DrawScale <= 0)
  97.             return;
  98.     }
  99.  
  100.     SetLocation(HitLocation + HitNormal);
  101.     SetRotation(rotator(HitNormal));
  102.     AttachDecal(30, vect(1,0,0));
  103. }
  104. simulated function Destroyed()
  105. {
  106.     if( PLShadow!=None )
  107.     {
  108.         PLShadow.ProjectingActor = None;
  109.         Level.FreeObject(PLShadow);
  110.         PLShadow = None;
  111.     }
  112.     Super.Destroyed();
  113. }
  114. simulated static final function byte GetShadowSoftness()
  115. {
  116.     if( Default.ShadowDetailRes<=64 )
  117.         return 0;
  118.     switch( Default.ShadowDetailRes )
  119.     {
  120.     case 128:
  121.         return 1;
  122.     case 256:
  123.         return 2;
  124.     case 512:
  125.         return 3;
  126.     default:
  127.         return 4;
  128.     }
  129. }
  130.  
  131. defaultproperties
  132. {
  133.     MultiDecalLevel=3
  134.     Texture=Texture'BlobShadow'
  135.     DrawScale=0.50
  136.     ShadowScaling=1
  137.     bAttachPanningSurfs=True
  138.     ShadowDetailRes=128
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement