Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LightingConfigurationData.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 
5 using SiliconStudio.Paradox.DataModel;
6 using SiliconStudio.Paradox.Shaders;
7 
8 namespace SiliconStudio.Paradox.Effects.Data
9 {
10  public partial class LightingConfigurationData
11  {
12  public int TotalLightCount
13  {
14  get
15  {
16  var shadowLightCount = 0;
17  if (ShadowConfigurations != null && ShadowConfigurations.Groups.Count > 0)
18  {
19  foreach (var group in ShadowConfigurations.Groups)
20  shadowLightCount += group.ShadowCount;
21  }
22  return MaxNumDirectionalLight + MaxNumPointLight + MaxNumSpotLight + shadowLightCount;
23  }
24  }
25 
27  {
28  MaxNumDirectionalLight = 0;
29  MaxNumPointLight = 0;
30  MaxNumSpotLight = 0;
31 
32  UnrollDirectionalLightLoop = false;
33  UnrollPointLightLoop = false;
34  UnrollSpotLightLoop = false;
35  }
36 
37  /// <summary>
38  /// Creates a new LightingConfigurationData from a collection of parameters.
39  /// </summary>
40  /// <param name="collection">The parameter collection.</param>
42  {
43  MaxNumDirectionalLight = collection.Get(LightingKeys.MaxDirectionalLights);
44  MaxNumPointLight = collection.Get(LightingKeys.MaxPointLights);
45  MaxNumSpotLight = collection.Get(LightingKeys.MaxSpotLights);
46 
47  UnrollDirectionalLightLoop = false;
48  UnrollPointLightLoop = false;
49  UnrollSpotLightLoop = false;
50 
51  var configs = collection.Get(ShadowMapParameters.ShadowConfigurations);
52  if (configs != null)
53  {
54  ShadowConfigurations = new ShadowConfigurationArrayData();
55  if (configs.Groups.Count > 0)
56  {
57  ShadowConfigurations.Groups = new List<ShadowConfigurationData>();
58  for (var i = 0; i < configs.Groups.Count; ++i)
59  {
60  if (configs.Groups[i].ShadowCount > 0)
61  {
62  var configData = new ShadowConfigurationData();
63  configData.LightType = configs.Groups[i].LightType;
64  configData.ShadowCount = configs.Groups[i].ShadowCount;
65  configData.CascadeCount = configData.LightType == LightType.Directional ? configs.Groups[i].CascadeCount : 1;
66  configData.FilterType = configs.Groups[i].FilterType;
67  ShadowConfigurations.Groups.Add(configData);
68  }
69  }
70  }
71  }
72  }
73 
74  /// <summary>
75  /// Gets the collection of parameters from the data.
76  /// </summary>
77  /// <returns>The parameter collection.</returns>
79  {
80  var parameters = new ParameterCollectionData();
81  parameters.Set(LightingKeys.MaxDirectionalLights, MaxNumDirectionalLight);
82  parameters.Set(LightingKeys.MaxPointLights, MaxNumPointLight);
83  parameters.Set(LightingKeys.MaxSpotLights, MaxNumSpotLight);
84  parameters.Set(LightingKeys.UnrollDirectionalLightLoop, UnrollDirectionalLightLoop);
85  parameters.Set(LightingKeys.UnrollPointLightLoop, UnrollPointLightLoop);
86  parameters.Set(LightingKeys.UnrollSpotLightLoop, UnrollSpotLightLoop);
87 
88  if (ShadowConfigurations != null && ShadowConfigurations.Groups != null && ShadowConfigurations.Groups.Count > 0)
89  {
90  var shadow = new List<ShadowMapParameters>();
91  foreach (var shadowConfig in ShadowConfigurations.Groups)
92  {
93  var shadowParams = new ShadowMapParameters();
95  shadowParams.Set(ShadowMapParameters.ShadowMapCount, shadowConfig.ShadowCount);
96  shadowParams.Set(ShadowMapParameters.ShadowMapCascadeCount, shadowConfig.LightType == LightType.Directional ? shadowConfig.CascadeCount : 1);
97  shadowParams.Set(ShadowMapParameters.FilterType, shadowConfig.FilterType);
98  shadow.Add(shadowParams);
99  }
100  parameters.Set(ShadowMapParameters.ShadowMaps, shadow.ToArray());
101  }
102  return parameters;
103  }
104 
105  public static void CheckUnrolls(LightingConfigurationData[] sortedConfigs)
106  {
107  // find unroll optimizations
108  for (var i = 0; i < sortedConfigs.Length; ++i)
109  {
110  var currentConfig = sortedConfigs[i];
111  var lightCount = currentConfig.MaxNumDirectionalLight + currentConfig.MaxNumPointLight + currentConfig.MaxNumSpotLight;
112  for (var j = 0; j < sortedConfigs.Length; ++j)
113  {
114  var localConfig = sortedConfigs[j];
115  var localCount = localConfig.MaxNumDirectionalLight + localConfig.MaxNumPointLight + localConfig.MaxNumSpotLight;
116  if (localCount == lightCount)
117  break;
118  if (localCount + 1 == lightCount)
119  {
120  if (localConfig.MaxNumDirectionalLight + 1 == currentConfig.MaxNumDirectionalLight)
121  currentConfig.UnrollDirectionalLightLoop = true;
122  if (localConfig.MaxNumPointLight + 1 == currentConfig.MaxNumPointLight)
123  currentConfig.UnrollPointLightLoop = true;
124  if (localConfig.MaxNumSpotLight + 1 == currentConfig.MaxNumSpotLight)
125  currentConfig.UnrollSpotLightLoop = true;
126  }
127  }
128  }
129  }
130  }
131 }
Data type for SiliconStudio.Paradox.Effects.LightingConfiguration.
Definition: EngineData.cs:95
LightingConfigurationData(ParameterCollection collection)
Creates a new LightingConfigurationData from a collection of parameters.
Data type for SiliconStudio.Paradox.Effects.ShadowConfigurationArray.
Definition: EngineData.cs:324
Data type for SiliconStudio.Paradox.Effects.ParameterCollection.
Definition: ParadoxData.cs:31
ParameterCollectionData GetCollection()
Gets the collection of parameters from the data.
static void CheckUnrolls(LightingConfigurationData[] sortedConfigs)
Data type for SiliconStudio.Paradox.Effects.ShadowConfiguration.
Definition: EngineData.cs:297
A container to handle a hierarchical collection of effect variables.