5 using System.Collections.Generic;
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.Mathematics;
9 using SiliconStudio.Paradox.DataModel;
10 using SiliconStudio.Paradox.Effects.Modules.Processors;
11 using SiliconStudio.Paradox.Effects.Modules.Shadowmap;
12 using SiliconStudio.Paradox.Engine;
13 using SiliconStudio.Paradox.EntityModel;
14 using SiliconStudio.Paradox.Graphics;
16 namespace SiliconStudio.
Paradox.Effects.Modules.Renderers
22 internal class LightForwardModelRenderer
24 internal static Dictionary<ParameterKey, LightParamSemantic> LightParametersDict =
new Dictionary<ParameterKey, LightParamSemantic>
26 { ShadingEyeNormalVSKeys.LightDirectionsVS, LightParamSemantic.DirectionVS },
27 { ShadingEyeNormalVSKeys.LightPositionsVS, LightParamSemantic.PositionVS },
28 { ShadingEyeNormalWSKeys.LightDirectionsWS, LightParamSemantic.DirectionWS },
29 { ShadingEyeNormalWSKeys.LightPositionsWS, LightParamSemantic.PositionWS },
30 { LightParametersKeys.LightColorsWithGamma, LightParamSemantic.ColorWithGamma },
31 { LightParametersKeys.LightIntensities, LightParamSemantic.Intensity },
32 { LightParametersKeys.LightDecayStarts, LightParamSemantic.Decay },
33 { LightParametersKeys.LightSpotBeamAngle, LightParamSemantic.SpotBeamAngle },
34 { LightParametersKeys.LightSpotFieldAngle, LightParamSemantic.SpotFieldAngle },
35 { LightParametersKeys.LightCount, LightParamSemantic.Count }
38 #region Private members
40 private int maximumSupportedLights;
42 private readonly Dictionary<Entity, Vector3> lightDirectionViewSpace;
44 private readonly Dictionary<Entity, Vector3> lightDirectionWorldSpace;
46 private readonly Dictionary<Entity, Color3> lightGammaColor;
48 private float[] arrayFloat;
52 private Color3[] arrayColor3;
54 private readonly ShadowMapReceiverInfo[] receiverInfos;
56 private readonly ShadowMapReceiverVsmInfo[] receiverVsmInfos;
58 private readonly ShadowMapCascadeReceiverInfo[] cascadeInfos;
60 private readonly List<EntityLightShadow> validLights;
62 private readonly List<EntityLightShadow> directionalLights;
64 private readonly List<EntityLightShadow> directionalLightsWithShadows;
66 private readonly List<EntityLightShadow> pointLights;
68 private readonly List<EntityLightShadow> spotLights;
70 private readonly List<EntityLightShadow> spotLightsWithShadows;
72 private readonly List<EntityLightShadow> directionalLightsForMesh;
74 private readonly List<EntityLightShadow> directionalLightsWithShadowForMesh;
76 private readonly List<EntityLightShadow> pointLightsForMesh;
78 private readonly List<EntityLightShadow> spotLightsForMesh;
80 private readonly List<EntityLightShadow> spotLightsWithShadowForMesh;
82 private readonly Dictionary<ParameterKey, LightParamSemantic> lightingParameterSemantics;
84 private readonly List<List<EntityLightShadow>> directionalLightsWithShadowForMeshGroups;
86 private readonly List<List<EntityLightShadow>> spotLightsWithShadowForMeshGroups;
88 private readonly List<List<ShadowMap>> shadowMapGroups;
90 private LightingConfiguration lastConfiguration;
98 if (services == null)
throw new ArgumentNullException(
"services");
100 maximumSupportedLights = 128;
102 lightDirectionViewSpace =
new Dictionary<Entity, Vector3>();
103 lightDirectionWorldSpace =
new Dictionary<Entity, Vector3>();
104 lightGammaColor =
new Dictionary<Entity, Color3>();
106 arrayFloat =
new float[4 * maximumSupportedLights];
107 arrayVector3 =
new Vector3[2 * maximumSupportedLights];
108 arrayColor3 =
new Color3[maximumSupportedLights];
110 receiverInfos =
new ShadowMapReceiverInfo[16];
111 receiverVsmInfos =
new ShadowMapReceiverVsmInfo[16];
112 cascadeInfos =
new ShadowMapCascadeReceiverInfo[128];
114 validLights =
new List<EntityLightShadow>();
115 directionalLights =
new List<EntityLightShadow>();
116 directionalLightsWithShadows =
new List<EntityLightShadow>();
117 pointLights =
new List<EntityLightShadow>();
118 spotLights =
new List<EntityLightShadow>();
119 spotLightsWithShadows =
new List<EntityLightShadow>();
121 directionalLightsForMesh =
new List<EntityLightShadow>();
122 directionalLightsWithShadowForMesh =
new List<EntityLightShadow>();
123 directionalLightsWithShadowForMeshGroups =
new List<List<EntityLightShadow>>();
124 spotLightsWithShadowForMeshGroups =
new List<List<EntityLightShadow>>();
125 pointLightsForMesh =
new List<EntityLightShadow>();
126 spotLightsForMesh =
new List<EntityLightShadow>();
127 spotLightsWithShadowForMesh =
new List<EntityLightShadow>();
129 shadowMapGroups =
new List<List<ShadowMap>>();
131 lightingParameterSemantics =
new Dictionary<ParameterKey, LightParamSemantic>();
138 #region Protected methods
145 public void PreRender(RenderContext context)
148 var entitySystem = Services.GetServiceAs<
EntitySystem>();
150 if (lightProcessor == null)
153 foreach (var light
in lightProcessor.Lights)
155 if (!light.Value.Light.Deferred && light.Value.Light.Enabled)
157 validLights.Add(light.Value);
159 switch (light.Value.Light.Type)
161 case LightType.Point:
162 pointLights.Add(light.Value);
164 case LightType.Spherical:
166 case LightType.Directional:
167 if (light.Value.HasShadowMap && lightProcessor.ActiveShadowMaps.Contains(light.Value.ShadowMap))
168 directionalLightsWithShadows.Add(light.Value);
170 directionalLights.Add(light.Value);
173 if (light.Value.HasShadowMap && lightProcessor.ActiveShadowMaps.Contains(light.Value.ShadowMap))
174 spotLightsWithShadows.Add(light.Value);
176 spotLights.Add(light.Value);
187 public void PostRender(RenderContext context)
189 lightDirectionViewSpace.Clear();
190 lightDirectionWorldSpace.Clear();
191 lightGammaColor.Clear();
193 directionalLights.Clear();
194 directionalLightsWithShadows.Clear();
197 spotLightsWithShadows.Clear();
198 directionalLightsForMesh.Clear();
199 directionalLightsWithShadowForMesh.Clear();
200 foreach (var group
in directionalLightsWithShadowForMeshGroups)
202 foreach (var group
in spotLightsWithShadowForMeshGroups)
204 foreach (var group
in shadowMapGroups)
206 pointLightsForMesh.Clear();
207 spotLightsForMesh.Clear();
208 spotLightsWithShadowForMesh.Clear();
216 public void PreEffectUpdate(RenderContext context, RenderMesh renderMesh)
218 var mesh = renderMesh.Mesh;
227 directionalLightsForMesh.Clear();
228 directionalLightsWithShadowForMesh.Clear();
229 foreach (var group
in directionalLightsWithShadowForMeshGroups)
231 foreach (var group
in spotLightsWithShadowForMeshGroups)
233 foreach (var group
in shadowMapGroups)
235 pointLightsForMesh.Clear();
236 spotLightsForMesh.Clear();
237 spotLightsWithShadowForMesh.Clear();
239 var receiveShadows = renderMesh.Mesh.Parameters.Get(LightingKeys.ReceiveShadows);
240 var renderLayers = renderMesh.Mesh.Parameters.Get(RenderingParameters.RenderLayer);
242 foreach (var light
in directionalLights)
244 if ((light.Light.Layers & renderLayers) != 0)
245 directionalLightsForMesh.Add(light);
247 foreach (var light
in directionalLightsWithShadows)
249 if ((light.Light.Layers & renderLayers) != 0)
252 directionalLightsWithShadowForMesh.Add(light);
254 directionalLightsForMesh.Add(light);
257 foreach (var light
in pointLights)
259 if ((light.Light.Layers & renderLayers) != 0)
260 pointLightsForMesh.Add(light);
262 foreach (var light
in spotLights)
264 if ((light.Light.Layers & renderLayers) != 0)
265 spotLightsForMesh.Add(light);
267 foreach (var light
in spotLightsWithShadows)
269 if ((light.Light.Layers & renderLayers) != 0)
272 spotLightsWithShadowForMesh.Add(light);
274 spotLightsForMesh.Add(light);
278 var numDirectionalLights = directionalLightsForMesh.Count;
279 var numPointLights = pointLightsForMesh.Count;
280 var numSpotLights = spotLightsForMesh.Count;
284 var configurations = renderMesh.Mesh.Parameters.Get(LightingKeys.LightingConfigurations);
285 var lastConfigWithoutShadow = -1;
286 if (configurations != null)
288 LightingConfiguration foundConfiguration;
289 foundConfiguration.MaxNumDirectionalLight = 0;
290 foundConfiguration.MaxNumPointLight = 0;
291 foundConfiguration.MaxNumSpotLight = 0;
292 foundConfiguration.UnrollDirectionalLightLoop =
false;
293 foundConfiguration.UnrollPointLightLoop =
false;
294 foundConfiguration.UnrollSpotLightLoop =
false;
295 var configurationIndex = -1;
296 for (var i = 0; i < configurations.Configs.Length; ++i)
298 if (configurations.Configs[i].ShadowConfigurations == null || configurations.Configs[i].ShadowConfigurations.Groups.Count == 0)
299 lastConfigWithoutShadow = i;
301 if (TestConfiguration(numDirectionalLights, numPointLights, numSpotLights, configurations.Configs[i]))
303 configurationIndex = i;
309 if (configurationIndex < 0)
311 if (lastConfigWithoutShadow != -1)
312 configurationIndex = lastConfigWithoutShadow;
314 configurationIndex = configurations.Configs.Length - 1;
317 foundConfiguration = configurations.Configs[configurationIndex];
319 var maxNumDirectionalLights = foundConfiguration.MaxNumDirectionalLight;
320 var maxNumPointLights = foundConfiguration.MaxNumPointLight;
321 var maxNumSpotLights = foundConfiguration.MaxNumSpotLight;
324 if (configurationIndex != mesh.Parameters.Get(LightKeys.ConfigurationIndex))
326 CreateParametersFromLightingConfiguration(foundConfiguration, mesh.Parameters);
327 mesh.Parameters.Set(LightKeys.ConfigurationIndex, configurationIndex);
331 if (foundConfiguration.ShadowConfigurations != null)
332 AssignGroups(foundConfiguration);
334 var finalDirectionalLightCount = Math.Min(numDirectionalLights, maxNumDirectionalLights);
335 var finalPointLightCount = Math.Min(numPointLights, maxNumPointLights);
336 var finalSpotLightCount = Math.Min(numSpotLights, maxNumSpotLights);
338 var maxLights = finalDirectionalLightCount;
339 if (maxLights > finalPointLightCount)
340 maxLights = finalPointLightCount;
341 if (maxLights > finalSpotLightCount)
342 maxLights = finalSpotLightCount;
344 if (maxLights > maximumSupportedLights)
346 maximumSupportedLights = maxLights;
347 arrayFloat =
new float[4 * maxLights];
348 arrayVector3 =
new Vector3[2 * maxLights];
349 arrayColor3 =
new Color3[maxLights];
352 lastConfiguration = foundConfiguration;
361 public void PostEffectUpdate(RenderContext context, RenderMesh renderMesh)
363 var lightingGroupInfo = LightingGroupInfo.GetOrCreate(renderMesh.Effect);
365 var mesh = renderMesh.Mesh;
368 if (!lightingGroupInfo.IsLightingSetup)
370 lightingGroupInfo.LightingParameters = CreateLightingUpdateInfo(renderMesh);
371 if (lastConfiguration.ShadowConfigurations != null)
372 lightingGroupInfo.ShadowParameters = CreateEffectShadowParams(lastConfiguration);
374 lightingGroupInfo.IsLightingSetup =
true;
377 if (lightingGroupInfo.LightingParameters.Count == 0)
381 var viewMatrix = context.CurrentPass.Parameters.Get(TransformationKeys.View);
383 if (lightingGroupInfo.ShadowParameters != null)
385 for (var i = 0; i < lightingGroupInfo.ShadowParameters.Count; ++i)
386 UpdateShadowParameters(mesh.Parameters, lightingGroupInfo.ShadowParameters[i], shadowMapGroups[i]);
390 foreach (var info
in lightingGroupInfo.LightingParameters)
394 case LightingUpdateType.Point:
395 UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, pointLightsForMesh);
397 case LightingUpdateType.Directional:
398 UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, directionalLightsForMesh);
400 case LightingUpdateType.Spot:
401 UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, spotLightsForMesh);
403 case LightingUpdateType.DirectionalShadow:
404 UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, directionalLightsWithShadowForMeshGroups[info.Index]);
406 case LightingUpdateType.SpotShadow:
407 UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, spotLightsWithShadowForMeshGroups[info.Index]);
410 case LightingUpdateType.PointShadow:
413 throw new ArgumentOutOfRangeException();
420 #region Private methods
422 private bool TestConfiguration(
int numDirectionalLights,
int numPointLights,
int numSpotLights, LightingConfiguration config)
424 if (config.MaxNumDirectionalLight < numDirectionalLights || config.MaxNumPointLight < numPointLights || config.MaxNumSpotLight < numSpotLights)
428 var groupCounts =
new int[16];
432 foreach (var light
in directionalLightsWithShadowForMesh)
435 if (config.ShadowConfigurations != null)
437 for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
439 if (BelongToGroup(light.Light, light.ShadowMap, config.ShadowConfigurations.Groups[i], groupCounts[i], groupTextures[i]))
442 if (groupTextures[i] == null)
443 groupTextures[i] = light.ShadowMap.Texture.ShadowMapDepthTexture;
452 foreach (var light
in spotLightsWithShadowForMesh)
455 if (config.ShadowConfigurations != null)
457 for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
459 if (BelongToGroup(light.Light, light.ShadowMap, config.ShadowConfigurations.Groups[i], groupCounts[i], groupTextures[i]))
462 if (groupTextures[i] == null)
463 groupTextures[i] = light.ShadowMap.Texture.ShadowMapDepthTexture;
475 private void AssignGroups(LightingConfiguration config)
480 for (var i = shadowMapGroups.Count; i < config.ShadowConfigurations.Groups.Count; ++i)
481 shadowMapGroups.Add(
new List<ShadowMap>());
483 for (var i = directionalLightsWithShadowForMeshGroups.Count; i < config.ShadowConfigurations.Groups.Count; ++i)
484 directionalLightsWithShadowForMeshGroups.Add(
new List<EntityLightShadow>());
485 foreach (var light
in directionalLightsWithShadowForMesh)
487 for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
489 if (BelongToGroup(light.Light, light.ShadowMap, config.ShadowConfigurations.Groups[i], shadowMapGroups[i].Count, shadowMapGroups[i].Count > 0 ? shadowMapGroups[i][0].Texture.ShadowMapDepthTexture : null))
491 shadowMapGroups[i].Add(light.ShadowMap);
492 directionalLightsWithShadowForMeshGroups[i].Add(light);
498 for (var i = spotLightsWithShadowForMeshGroups.Count; i < config.ShadowConfigurations.Groups.Count; ++i)
499 spotLightsWithShadowForMeshGroups.Add(
new List<EntityLightShadow>());
500 foreach (var light
in spotLightsWithShadowForMesh)
502 for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
504 if (BelongToGroup(light.Light, light.ShadowMap, config.ShadowConfigurations.Groups[i], shadowMapGroups[i].Count, shadowMapGroups[i].Count > 0 ? shadowMapGroups[i][0].Texture.ShadowMapDepthTexture : null))
506 shadowMapGroups[i].Add(light.ShadowMap);
507 spotLightsWithShadowForMeshGroups[i].Add(light);
514 private void UpdateLightingParameters(LightingUpdateInfo info, ref RenderMesh renderMesh, ref
Matrix viewMatrix, List<EntityLightShadow> lightsForMesh)
516 var mesh = renderMesh.Mesh;
518 var maxLights = info.Count;
527 foreach (var light
in lightsForMesh)
533 Matrix.Multiply(ref light.Entity.Transformation.WorldMatrix, ref viewMatrix, out worldView);
534 lightDir = light.Light.LightDirection;
535 Vector3.TransformNormal(ref lightDir, ref worldView, out direction);
536 arrayVector3[lightCount] = direction;
540 lightPos = light.Entity.Transformation.Translation;
541 Vector3.TransformCoordinate(ref lightPos, ref viewMatrix, out position);
542 arrayVector3[lightCount + maxLights] = position;
549 lightDir = light.Light.LightDirection;
550 Vector3.TransformNormal(ref lightDir, ref light.Entity.Transformation.WorldMatrix, out direction);
551 arrayVector3[lightCount] = direction;
555 lightPos = light.Entity.Transformation.Translation;
556 arrayVector3[lightCount + maxLights] = lightPos;
569 arrayFloat[lightCount] = light.Light.Intensity;
573 arrayFloat[lightCount + maxLights] = light.Light.DecayStart;
577 arrayFloat[lightCount + 2 * maxLights] = (float)Math.Cos(Math.PI * light.Light.SpotBeamAngle / 180);
581 arrayFloat[lightCount + 3 * maxLights] = (float)Math.Cos(Math.PI * light.Light.SpotFieldAngle / 180);
585 if (lightCount >= maxLights)
590 mesh.Parameters.Set(info.DirectionKey, arrayVector3, 0, lightCount);
592 mesh.Parameters.Set(info.PositionKey, arrayVector3, maxLights, 0, lightCount);
594 mesh.Parameters.Set(info.DirectionKey, arrayVector3, 0, lightCount);
596 mesh.Parameters.Set(info.PositionKey, arrayVector3, maxLights, 0, lightCount);
598 mesh.Parameters.Set(info.ColorKey, arrayColor3, 0, lightCount);
600 mesh.Parameters.Set(info.IntensityKey, arrayFloat, 0, lightCount);
602 mesh.Parameters.Set(info.DecayKey, arrayFloat, maxLights, 0, lightCount);
604 mesh.Parameters.Set(info.SpotBeamAngleKey, arrayFloat, 2 * maxLights, 0, lightCount);
606 mesh.Parameters.Set(info.SpotFieldAngleKey, arrayFloat, 3 * maxLights, 0, lightCount);
608 mesh.Parameters.Set(info.LightCountKey, lightCount);
613 mesh.Parameters.Set(info.LightCountKey, 0);
617 private void UpdateShadowParameters(ParameterCollection parameters, ShadowUpdateInfo shadowUpdateInfo, List<ShadowMap> shadows)
619 if (shadows != null && shadows.Count > 0)
622 var cascadeCount = 0;
623 foreach (var shadow
in shadows)
625 receiverInfos[
count] = shadow.ReceiverInfo;
626 receiverVsmInfos[
count] = shadow.ReceiverVsmInfo;
627 for (var i = 0; i < shadowUpdateInfo.CascadeCount; ++i)
628 cascadeInfos[cascadeCount + i] = shadow.Cascades[i].ReceiverInfo;
630 cascadeCount += shadowUpdateInfo.CascadeCount;
633 parameters.Set((ParameterKey<ShadowMapReceiverInfo[]>)shadowUpdateInfo.ShadowMapReceiverInfoKey, receiverInfos, 0, count);
634 parameters.Set((ParameterKey<ShadowMapCascadeReceiverInfo[]>)shadowUpdateInfo.ShadowMapLevelReceiverInfoKey, cascadeInfos, 0, cascadeCount);
637 parameters.Set((ParameterKey<ShadowMapReceiverVsmInfo[]>)shadowUpdateInfo.ShadowMapReceiverVsmInfoKey, receiverVsmInfos, 0, count);
638 parameters.Set(shadowUpdateInfo.ShadowMapTextureKey, shadows[0].Texture.ShadowMapTargetTexture);
641 parameters.Set(shadowUpdateInfo.ShadowMapTextureKey, shadows[0].Texture.ShadowMapDepthTexture);
642 parameters.Set(shadowUpdateInfo.ShadowMapLightCountKey,
count);
645 parameters.Set(shadowUpdateInfo.ShadowMapLightCountKey, 0);
648 private List<LightingUpdateInfo> CreateLightingUpdateInfo(RenderMesh renderMesh)
650 var finalList =
new List<LightingUpdateInfo>();
651 var continueSearch =
true;
653 while (continueSearch)
655 continueSearch = SearchShadingGroup(renderMesh, index,
"ShadingGroups", 0, finalList);
659 continueSearch =
true;
661 while (continueSearch)
663 continueSearch = SearchShadingGroup(renderMesh, index,
"shadows", 3, finalList);
670 private bool SearchShadingGroup(RenderMesh renderMesh,
int index,
string groupName,
int typeOffset, List<LightingUpdateInfo> finalList)
672 var mesh = renderMesh.Mesh;
673 var constantBuffers = renderMesh.Effect.ConstantBuffers;
674 var info =
new LightingUpdateInfo();
677 var foundParam =
false;
678 var lightTypeGuess = LightTypeGuess.None;
680 UpdateLightingParameterSemantics(index, groupName);
682 foreach (var constantBuffer
in constantBuffers)
684 foreach (var member
in constantBuffer.Members)
686 if (lightingParameterSemantics.TryGetValue(member.Param.Key, out foundParameterSemantic))
688 info.Semantic = info.Semantic | foundParameterSemantic;
690 switch (foundParameterSemantic)
692 case LightParamSemantic.PositionVS:
693 info.PositionKey = (ParameterKey<Vector3[]>)member.Param.Key;
694 mesh.Parameters.Set(info.PositionKey,
new Vector3[member.Count]);
695 info.Count = member.Count;
698 case LightParamSemantic.DirectionVS:
699 info.DirectionKey = (ParameterKey<Vector3[]>)member.Param.Key;
700 mesh.Parameters.Set(info.DirectionKey,
new Vector3[member.Count]);
701 info.Count = member.Count;
702 lightTypeGuess = lightTypeGuess | LightTypeGuess.Directional;
704 case LightParamSemantic.PositionWS:
705 info.PositionKey = (ParameterKey<Vector3[]>)member.Param.Key;
706 mesh.Parameters.Set(info.PositionKey,
new Vector3[member.Count]);
707 info.Count = member.Count;
710 case LightParamSemantic.DirectionWS:
711 info.DirectionKey = (ParameterKey<Vector3[]>)member.Param.Key;
712 mesh.Parameters.Set(info.DirectionKey,
new Vector3[member.Count]);
713 info.Count = member.Count;
714 lightTypeGuess = lightTypeGuess | LightTypeGuess.Directional;
716 case LightParamSemantic.ColorWithGamma:
717 info.ColorKey = (ParameterKey<Color3[]>)member.Param.Key;
718 mesh.Parameters.Set(info.ColorKey,
new Color3[member.Count]);
719 info.Count = member.Count;
721 case LightParamSemantic.Intensity:
722 info.IntensityKey = (ParameterKey<float[]>)member.Param.Key;
723 mesh.Parameters.Set(info.IntensityKey,
new float[member.Count]);
724 info.Count = member.Count;
726 case LightParamSemantic.Decay:
727 info.DecayKey = (ParameterKey<float[]>)member.Param.Key;
728 mesh.Parameters.Set(info.DecayKey,
new float[member.Count]);
729 info.Count = member.Count;
732 case LightParamSemantic.SpotBeamAngle:
733 info.SpotBeamAngleKey = (ParameterKey<float[]>)member.Param.Key;
734 mesh.Parameters.Set(info.SpotBeamAngleKey,
new float[member.Count]);
735 info.Count = member.Count;
736 lightTypeGuess = lightTypeGuess | LightTypeGuess.Spot;
738 case LightParamSemantic.SpotFieldAngle:
739 info.SpotFieldAngleKey = (ParameterKey<float[]>)member.Param.Key;
740 mesh.Parameters.Set(info.SpotFieldAngleKey,
new float[member.Count]);
741 info.Count = member.Count;
742 lightTypeGuess = lightTypeGuess | LightTypeGuess.Spot;
744 case LightParamSemantic.Count:
745 info.LightCountKey = (ParameterKey<int>)member.Param.Key;
748 throw new ArgumentOutOfRangeException();
755 switch (lightTypeGuess)
757 case LightTypeGuess.Directional:
758 info.Type = LightingUpdateType.Directional + typeOffset;
760 case LightTypeGuess.Point:
761 info.Type = LightingUpdateType.Point + typeOffset;
763 case LightTypeGuess.Spot:
764 info.Type = LightingUpdateType.Spot + typeOffset;
767 if (lightTypeGuess != LightTypeGuess.None)
776 private static List<ShadowUpdateInfo> CreateEffectShadowParams(LightingConfiguration config)
778 var configs =
new List<ShadowUpdateInfo>();
780 for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
782 var group = LightingProcessorHelpers.CreateShadowUpdateInfo(i, config.ShadowConfigurations.Groups[i].CascadeCount);
789 private void UpdateLightingParameterSemantics(
int index,
string compositionName)
791 lightingParameterSemantics.Clear();
792 var lightGroupSubKey = string.Format(
"." + compositionName +
"[{0}]", index);
793 foreach (var param
in LightParametersDict)
795 lightingParameterSemantics.Add(ParameterKeys.AppendKey(param.Key, lightGroupSubKey), param.Value);
804 private enum LightTypeGuess
814 return light.ShadowMapCascadeCount == config.CascadeCount
815 && light.ShadowMapFilterType == config.FilterType
816 && groupCount < config.ShadowCount
817 && (groupTexture == null || groupTexture == shadow.Texture.ShadowMapDepthTexture);
820 private static void CreateParametersFromLightingConfiguration(LightingConfiguration config, ParameterCollection parameters)
823 parameters.Set(LightingKeys.MaxDirectionalLights, config.MaxNumDirectionalLight);
824 parameters.Set(LightingKeys.MaxPointLights, config.MaxNumPointLight);
825 parameters.Set(LightingKeys.MaxSpotLights, config.MaxNumSpotLight);
830 if (config.ShadowConfigurations != null)
833 foreach (var group
in config.ShadowConfigurations.Groups)
834 groupCount += (group.ShadowCount > 0 ? 1 : 0);
838 parameters.Remove(ShadowMapParameters.ShadowMaps);
842 var shadowMapParameters =
new ShadowMapParameters[groupCount];
844 for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
846 if (config.ShadowConfigurations.Groups[i].ShadowCount > 0)
848 var shadowParams =
new ShadowMapParameters();
850 shadowParams.Set(ShadowMapParameters.ShadowMapCount, config.ShadowConfigurations.Groups[i].ShadowCount);
851 shadowParams.Set(ShadowMapParameters.ShadowMapCascadeCount, config.ShadowConfigurations.Groups[i].CascadeCount);
852 shadowParams.Set(ShadowMapParameters.FilterType, config.ShadowConfigurations.Groups[i].FilterType);
853 shadowMapParameters[index] = shadowParams;
857 parameters.Set(ShadowMapParameters.ShadowMaps, shadowMapParameters);
860 parameters.Remove(ShadowMapParameters.ShadowMaps);
876 LightingParameterSemantics =
new Dictionary<ParameterKey, LightParamSemantic>();
877 var lightGroupSubKey = string.Format(
"." + compositionName +
"[{0}]", index);
878 foreach (var param
in LightForwardModelRenderer.LightParametersDict)
880 LightingParameterSemantics.Add(ParameterKeys.AppendKey(param.Key, lightGroupSubKey), param.Value);
Add a light to an Entity, that will be used during rendering.
Dictionary< ParameterKey, LightParamSemantic > LightingParameterSemantics
Represents a color in the form of rgb.
Represents a shadow map for the ShadowMapRenderer.
LightGroup(int index, string compositionName)
Represents a three dimensional mathematical vector.
A service registry is a IServiceProvider that provides methods to register and unregister services...
Flags
Enumeration of the new Assimp's flags.
Structure using the same layout than System.Drawing.Point.
SiliconStudio.Core.Mathematics.Color Color
Manage a collection of entities.
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
System.Windows.Point Point
Represents a 4x4 mathematical matrix.