Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 |
// // ShadowProjector // class ShadowProjector extends Projector; var() Actor ShadowActor; var() vector LightDirection; var() float LightDistance; var() float InterpolateRate; var() float BoundScale; var() int ShadowResolution; var() bool bBlobShadow; var() bool bForceFullPolyShadow; var() bool bForceBlobShadow; var() bool bShadowActive; var() bool bAlwaysAllocate; var() bool bBlurShadow; var() bool bStaticLights; // light sourced via static lights. var() bool bDynamicLights; // light sourced via dynamic lights. var ShadowBitmapMaterial ShadowTexture; var float LastRenderTime; var float LastLightDistance; // // PostBeginPlay // event PostBeginPlay() { Super(Actor).PostBeginPlay(); } // // Destroyed // event Destroyed() { if(ShadowTexture != None) { ShadowTexture.ShadowActor = None; if(!ShadowTexture.Invalid) Level.ObjectPool.FreeObject(ShadowTexture); ShadowTexture = None; ProjTexture = None; } Super.Destroyed(); } // // InitShadow // function InitShadow() { local Plane BoundingSphere; if(ShadowActor != None) { // Attach the shadow projector with the blob texture until the first time it's rendered. BoundingSphere = ShadowActor.GetRenderBoundingSphere(); FOV = Max(1, Atan2(BoundingSphere.W * 2 + BoundScale, LightDistance) * 180 / PI); if(bAlwaysAllocate) { Level.ObjectPool.FreeObject(Level.ObjectPool.AllocateObject(class'ShadowBitmapMaterial',Level)); PreRender(); } Enable('Tick'); UpdateShadow(); } else Log(Name$".InitShadow: No actor"); } // // UpdateShadow // function UpdateShadow(optional float DeltaTime) { local coords C; local bool bSuccess; DetachProjector(true); if(ShadowActor != None && !ShadowActor.bHidden) { bSuccess = CalcPos(DeltaTime); if(Level.TimeSeconds > LastRenderTime + 1.0f && ShadowTexture != None) { Level.ObjectPool.FreeObject(ShadowTexture); ShadowTexture = None; ProjTexture = class'ShadowBitmapMaterial'.default.BlobShadow; } if(ShadowTexture != None) { ShadowTexture.Dirty = true; ProjTexture = ShadowTexture; } else ProjTexture = class'ShadowBitmapMaterial'.default.BlobShadow; if(!bSuccess && ShadowTexture != None) // Fix ARL: It would be better just to not reattach, but then it never gets updated again. { Level.ObjectPool.FreeObject(ShadowTexture); ShadowTexture = None; ProjTexture = None; } AttachProjector(); } } // // CalcPos: Precondition(ShadowActor != None) // function bool CalcPos(float DeltaTime) { local float Pct; local float Dist; local vector Diff; local vector LightLoc; local rotator LightRot; local Actor LightSource; local bool bAttach; // Update projector location. if(ShadowTexture != None) SetLocation(ShadowTexture.GetShadowLocation()); else { SetLocation(ShadowActor.Location + vect(0,0,5)); SetRotation(Rotator(Normal(-LightDirection))); return true; } // Get proper light source. if(bStaticLights) { LightSource = ShadowActor.PrimaryStaticLight; if(!LightSource) return false; } if(bDynamicLights) { LightSource = ShadowActor.PrimaryDynamicLight; if(!LightSource) return false; } // Handle non-lightsourced rotation. if(!LightSource) { ShadowTexture.LightDirection = Normal(LightDirection); ShadowTexture.LightDistance = LightDistance; ShadowTexture.FrustumOrigin = Location + ShadowTexture.LightDirection * ShadowTexture.LightDistance; SetRotation(Rotator(Normal(-LightDirection))); return true; } // Calculate light position. if(LightSource.LightEffect == LE_Sunlight) { Dist = 1024; LightRot = LightSource.Rotation; } else { Diff = Location - LightSource.Location; Dist = FMin( VSize(Diff), 1024 ); if(Dist>0) LightRot = Rotator(Diff); else LightRot = LightSource.Rotation; } LightLoc = Location - Vector(LightRot) * Dist; // Interpolate from last light position (in case we've switched to a new light). Pct = FMin(1.0, (DeltaTime * InterpolateRate)); ShadowTexture.FrustumOrigin += (LightLoc - ShadowTexture.FrustumOrigin) * Pct; Diff = Location - ShadowTexture.FrustumOrigin; LightRot = Rotator(Diff); // recalc so we're always facing our caster. SetRotation(LightRot); SetLightDistance(VSize(Diff),LightSource.LightEffect == LE_Sunlight); LightDirection = -Vector(LightRot) * LightDistance; ShadowTexture.LightDirection = Normal(LightDirection); ShadowTexture.LightDistance = LightDistance; return true; } // // SetLightDistance: Precondition(ShadowTexture != None && ShadowActor != None) // function SetLightDistance(float Dist,optional bool bSunlight) { local Plane BoundingSphere; LightDistance = Dist; if(LightDistance != LastLightDistance) { LastLightDistance = LightDistance; BoundingSphere = ShadowActor.GetRenderBoundingSphere(); FOV = Max(1, Atan2(BoundingSphere.W * 2 + BoundScale, LightDistance) * 180 / PI); ShadowTexture.LightDistance = LightDistance; ShadowTexture.LightFOV = FOV; if(bSunlight) SetDrawScale((BoundingSphere.W * 2.0) / ShadowTexture.USize); else SetDrawScale(LightDistance * tan(0.5 * FOV * PI / 180) / (0.5 * ShadowTexture.USize)); } } // // PreRender // event PreRender() { if(ShadowTexture == None) { // The first time the shadow projector is rendered, allocate the actual shadow texture. //NOTE[aleiby]: RenderTargets allocated mid-game are useless since they aren't precached often kill performance. // if(bAlwaysAllocate) // ShadowTexture = ShadowBitmapMaterial(Level.ObjectPool.AllocateObject(class'ShadowBitmapMaterial',Level)); // else ShadowTexture = ShadowBitmapMaterial(Level.ObjectPool.GetObject(class'ShadowBitmapMaterial')); if(!ShadowTexture) ShadowTexture = ShadowBitmapMaterial(Level.ObjectPool.AllocateObject(class'ShadowBitmapMaterialFallback',Level)); ProjTexture = ShadowTexture; if(ShadowTexture != None) { if(bForceBlobShadow) bBlobShadow = true; if(bForceFullPolyShadow) bBlobShadow = false; ShadowTexture.bBlobShadow = bBlobShadow; ShadowTexture.bBlurShadow = bBlurShadow; ShadowTexture.ShadowActor = ShadowActor; ShadowTexture.LightDirection = Normal(LightDirection); ShadowTexture.LightDistance = LightDistance; ShadowTexture.LightFOV = FOV; ShadowTexture.SetRes(ShadowResolution); ShadowTexture.CullDistance = VisibilityRadius; ShadowTexture.Dirty = true; SetDrawScale(LightDistance * tan(0.5 * FOV * PI / 180) / (0.5 * ShadowTexture.USize)); AttachProjector(); // Update the current projected texture. } else { Log(Name$".PreRender: Failed to allocate texture"); Destroy(); } } LastRenderTime = Level.TimeSeconds; } // // Tick // event Tick(float DeltaTime) { super.Tick(DeltaTime); UpdateShadow(DeltaTime); } // // Default properties // defaultproperties { InterpolateRate=2.500000 BoundScale=35.000000 ShadowResolution=256 bShadowActive=true bBlurShadow=true MaxTraceDistance=220 bProjectActor=false bClipBSP=true bGradient=true bProjectOnAlpha=true bProjectOnParallelBSP=true bDynamicAttach=true bStatic=false bOwnerNoSee=true RemoteRole=ROLE_None VisibilityRadius=1000.000000 UseReticleOnEvents(0)="UseReticleText" UseReticleOnEvents(1)="UseReticleCorners" UseReticleOnEvents(2)="UseReticleTopBars" ProximityReticleOnEvents(0)="ProximityReticleCorners" ProximityReticleOnEvents(1)="ProximityReticleTopBars" } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |