public override void ApplyViewParameters(RenderDrawContext context, int viewIndex, ParameterCollection parameters) { CurrentLights.Clear(); var lightRange = LightRanges[viewIndex]; for (int i = lightRange.Start; i < lightRange.End; ++i) { CurrentLights.Add(Lights[i]); } base.ApplyViewParameters(context, viewIndex, parameters); foreach (var lightEntry in CurrentLights) { var light = lightEntry.Light; lightsData.Add(new DirectionalLightData { DirectionWS = light.Direction, Color = light.Color, }); } parameters.Set(countKey, lightsData.Count); parameters.Set(lightsKey, lightsData.Count, ref lightsData.Items[0]); lightsData.Clear(); }
public override void ApplyDrawParameters(RenderDrawContext context, int viewIndex, ParameterCollection parameters, ref BoundingBoxExt boundingBox) { // TODO THREADING: Make CurrentLights and lightData (thread-) local lock (applyLock) { CurrentLights.Clear(); var lightRange = LightRanges[viewIndex]; for (int i = lightRange.Start; i < lightRange.End; ++i) { CurrentLights.Add(Lights[i]); } base.ApplyDrawParameters(context, viewIndex, parameters, ref boundingBox); // TODO: Octree structure to select best lights quicker var boundingBox2 = (BoundingBox)boundingBox; for (int i = 0; i < CurrentLights.Count; i++) { var light = CurrentLights[i].Light; if (light.BoundingBox.Intersects(ref boundingBox2)) { var spotLight = (LightSpot)light.Type; lightsData.Add(new SpotLightData { PositionWS = light.Position, DirectionWS = light.Direction, AngleOffsetAndInvSquareRadius = new Vector3(spotLight.LightAngleScale, spotLight.LightAngleOffset, spotLight.InvSquareRange), Color = light.Color, }); // Did we reach max number of simultaneous lights? // TODO: Still collect everything but sort by importance and remove the rest? if (lightsData.Count >= LightCurrentCount) { break; } } } parameters.Set(countKey, lightsData.Count); parameters.Set(lightsKey, lightsData.Count, ref lightsData.Items[0]); lightsData.Clear(); TextureProjectionShaderGroupData?.ApplyDrawParameters(context, parameters, CurrentLights, ref boundingBox); } }
public override void ApplyDrawParameters(RenderDrawContext context, int viewIndex, ParameterCollection parameters, ref BoundingBoxExt boundingBox) { // TODO THREADING: Make CurrentLights and lightData (thread-) local lock (applyLock) { CurrentLights.Clear(); var lightRange = LightRanges[viewIndex]; for (int i = lightRange.Start; i < lightRange.End; ++i) { CurrentLights.Add(Lights[i]); } base.ApplyDrawParameters(context, viewIndex, parameters, ref boundingBox); // TODO: Since we cull per object, we could maintain a higher number of allowed light than the shader support (i.e. 4 lights active per object even though the scene has many more of them) // TODO: Octree structure to select best lights quicker var boundingBox2 = (BoundingBox)boundingBox; foreach (var lightEntry in CurrentLights) { var light = lightEntry.Light; if (light.BoundingBox.Intersects(ref boundingBox2)) { var pointLight = (LightPoint)light.Type; lightsData.Add(new PointLightData { PositionWS = light.Position, InvSquareRadius = pointLight.InvSquareRadius, Color = light.Color, }); // Did we reach max number of simultaneous lights? // TODO: Still collect everything but sort by importance and remove the rest? if (lightsData.Count >= LightCurrentCount) { break; } } } parameters.Set(countKey, lightsData.Count); parameters.Set(lightsKey, lightsData.Count, ref lightsData.Items[0]); lightsData.Clear(); } }