public override bool Update(LightComponent lightComponent) { var range = Math.Max(0.001f, Range); InvSquareRange = 1.0f / (range * range); var innerAngle = Math.Min(AngleInner, AngleOuter); var outerAngle = Math.Max(AngleInner, AngleOuter); AngleOuterInRadians = MathUtil.DegreesToRadians(outerAngle); var cosInner = (float)Math.Cos(MathUtil.DegreesToRadians(innerAngle / 2)); var cosOuter = (float)Math.Cos(AngleOuterInRadians * 0.5f); LightAngleScale = 1.0f / Math.Max(0.001f, cosInner - cosOuter); LightAngleOffset = -cosOuter * LightAngleScale; LightRadiusAtTarget = (float)Math.Abs(Range * Math.Sin(AngleOuterInRadians * 0.5f)); return true; }
public static async Task AnimateLight(EngineContext engineContext, int index, LightComponent lightComponent) { // Wait different time for each light await TaskEx.Delay(index * 20); var startIntensity = lightComponent.Intensity; // Turn light off var startTime = DateTime.UtcNow; while (true) { await engineContext.Scheduler.NextFrame(); var elapsedTime = (DateTime.UtcNow - startTime).Seconds * 0.2f; if (elapsedTime > 1.0f) break; lightComponent.Intensity = startIntensity * (1.0f - elapsedTime); } // Turn light on lightComponent.Intensity = startIntensity; }
public override bool Update(LightComponent lightComponent) { return true; }
private LightComponentCollectionGroup GetLightGroup(RenderViewLightData renderViewData, LightComponent light) { LightComponentCollectionGroup lightGroup; var directLight = light.Type as IDirectLight; var lightGroups = renderViewData.ActiveLightGroups; var type = light.Type.GetType(); if (!lightGroups.TryGetValue(type, out lightGroup)) { lightGroup = new LightComponentCollectionGroup(type); lightGroups.Add(type, lightGroup); } return lightGroup; }
public override bool Update(LightComponent lightComponent) { var range = Math.Max(0.001f, Radius); InvSquareRadius = 1.0f / (range * range); return true; }
public bool Update(LightComponent lightComponent) { SkyMatrix = Matrix.RotationQuaternion(lightComponent.Entity.Transform.Rotation); SkyboxComponent = lightComponent.Entity.Get<SkyboxComponent>(); return SkyboxComponent != null && SkyboxComponent.Skybox != null; }
public LightEntry(int currentLightGroupIndex, int currentLightGroupIndexNoShadows, LightComponent light, LightShadowMapTexture shadow) { GroupIndex = currentLightGroupIndex; GroupIndexNoShadows = currentLightGroupIndexNoShadows; Light = light; Shadow = shadow; }
private LightComponentCollectionGroup GetLightGroup(LightComponent light) { LightComponentCollectionGroup lightGroup; var directLight = light.Type as IDirectLight; var lightGroups = directLight != null && directLight.Shadow.Enabled && shadowMapRenderer != null ? activeLightGroupsWithShadows : activeLightGroups; var type = light.Type.GetType(); if (!lightGroups.TryGetValue(type, out lightGroup)) { lightGroup = new LightComponentCollectionGroup(); lightGroups.Add(type, lightGroup); } return lightGroup; }
private static string GetButtonTextOnOffLight(LightComponent component) { return component.Entity.Name + ": " + (component.Enabled ? "On" : "Off"); }
private static string GetButtonTextOnOffShadow(LightComponent component) { var isEnabled = component.Type is IDirectLight && ((IDirectLight)component.Type).Shadow.Enabled; return "Shadow: " + (isEnabled ? "On" : "Off"); }
// Create a button that can toggle on/off the light shadow map private Button CreateShadowButton(UIElement parentButton, LightComponent component) { var button = new Button { Margin = new Thickness(20, 5, 5, 5), Name = "Shadow Button " + component.Entity.Name, Opacity = component.Enabled ? 1.0f : 0.3f, CanBeHitByUser = component.Enabled, Content = new TextBlock { Font = Font, TextAlignment = TextAlignment.Right, Text = GetButtonTextOnOffShadow(component), }, }; button.Click += ToggleShadowMap; button.DependencyProperties.Set(LightKey, component); parentButton.DependencyProperties.Set(ShadowButtonKey, button); return button; }
// Create a button that can toggle on/off the Light component private Button CreateLightButton(LightComponent component) { var button = new Button { Name = component.Entity.Name, Margin = Thickness.UniformRectangle(5), Content = new TextBlock { Font = Font, TextAlignment = TextAlignment.Right, Text = GetButtonTextOnOffLight(component), }, }; button.Click += ToggleLight; button.DependencyProperties.Set(LightKey, component); return button; }
/// <summary> /// Try to add light to this group (returns false if not possible). /// </summary> /// <param name="light"></param> /// <param name="shadowMapTexture"></param> /// <returns></returns> public bool AddLight(LightComponent light, LightShadowMapTexture shadowMapTexture) { Lights.Add(new LightDynamicEntry(light, shadowMapTexture)); return true; }
public abstract bool Update(LightComponent lightComponent);
public LightDynamicEntry(LightComponent light, LightShadowMapTexture shadowMapTexture) { Light = light; ShadowMapTexture = shadowMapTexture; }
public void Initialize(LightComponent lightComponent, IDirectLight light, LightShadowMap shadowMap, int size, ILightShadowMapRenderer renderer) { if (lightComponent == null) throw new ArgumentNullException("lightComponent"); if (light == null) throw new ArgumentNullException("light"); if (shadowMap == null) throw new ArgumentNullException("shadowMap"); if (renderer == null) throw new ArgumentNullException("renderer"); LightComponent = lightComponent; Light = light; Shadow = shadowMap; Size = size; FilterType = Shadow.Filter == null || !Shadow.Filter.RequiresCustomBuffer() ? null : Shadow.Filter.GetType(); Renderer = renderer; Atlas = null; // Reset the atlas, It will be setup after ShadowType = renderer.GetShadowType(Shadow); }