Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LightingPermutation.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.Specialized;
4 using System.ComponentModel;
5 using System.Linq;
6 using ScriptShader.Effects;
7 using SiliconStudio.Paradox.Engine;
8 
9 namespace SiliconStudio.Paradox.Effects
10 {
11  public struct LightBinding
12  {
13  public LightBinding(Light light) : this()
14  {
15  Light = light;
16  LightShaderType = light.LightShaderType;
17  }
18 
19  /// <summary>
20  /// The light.
21  /// </summary>
22  public Light Light;
23 
24  /// <summary>
25  /// Specifies LightShaderType. Might be different than Light's one, since depending on Material or HW limitations it might be downgraded or ignored.
26  /// </summary>
27  public LightShaderType LightShaderType;
28  }
29 
31  {
32  public static ParameterKey<LightingPermutation> Key = ParameterKeys.Resource(new LightingPermutation(new LightBinding[0]));
33 
35  {
36  PerPixelDiffuseDirectionalLights = lightBindings.Where(IsDirectionalDiffusePixel).ToArray();
37  PerPixelDirectionalLights = lightBindings.Where(IsDirectionalDiffuseSpecularPixel).ToArray();
38  PerVertexDirectionalLights = lightBindings.Where(IsDirectionalDiffuseVertex).ToArray();
39  PerVertexDiffusePixelSpecularDirectionalLights = lightBindings.Where(IsDirectionalDiffuseVertexPixelSpecular).ToArray();
40  }
41 
42  public LightBinding[] PerPixelDiffuseDirectionalLights { get; set; }
43  public LightBinding[] PerPixelDirectionalLights { get; set; }
44  public LightBinding[] PerVertexDirectionalLights { get; set; }
45  public LightBinding[] PerVertexDiffusePixelSpecularDirectionalLights { get; set; }
46 
47  public override object GenerateKey()
48  {
49  return new KeyInfo
50  {
51  PerPixelDiffuseDirectionalLightCount = PerPixelDiffuseDirectionalLights.Length,
52  PerPixelDirectionalLightCount = PerPixelDirectionalLights.Length,
53  PerVertexDirectionalLightCount = PerVertexDirectionalLights.Length,
54  PerVertexDiffusePixelSpecularDirectionalLightCount = PerVertexDiffusePixelSpecularDirectionalLights.Length,
55  };
56  }
57 
59  {
60  return (x.LightShaderType & LightShaderType.DiffuseVertexSpecularPixel) == LightShaderType.DiffuseVertexSpecularPixel;
61  }
62 
64  {
65  return (x.LightShaderType & LightShaderType.DiffuseVertex) == LightShaderType.DiffuseVertex;
66  }
67 
69  {
70  return (x.LightShaderType == LightShaderType.DiffusePixel);
71  }
72 
74  {
75  return (x.LightShaderType & LightShaderType.DiffuseSpecularPixel) == LightShaderType.DiffuseSpecularPixel;
76  }
77 
78  public class KeyInfo : IEquatable<KeyInfo>
79  {
84 
85  public bool Equals(KeyInfo other)
86  {
87  if (ReferenceEquals(null, other)) return false;
88  if (ReferenceEquals(this, other)) return true;
89  return PerPixelDiffuseDirectionalLightCount == other.PerPixelDiffuseDirectionalLightCount
90  && PerPixelDirectionalLightCount == other.PerPixelDirectionalLightCount
91  && PerVertexDirectionalLightCount == other.PerVertexDirectionalLightCount
92  && PerVertexDiffusePixelSpecularDirectionalLightCount == other.PerVertexDiffusePixelSpecularDirectionalLightCount;
93  }
94 
95  public override bool Equals(object obj)
96  {
97  if (ReferenceEquals(null, obj)) return false;
98  if (ReferenceEquals(this, obj)) return true;
99  if (obj.GetType() != this.GetType()) return false;
100  return Equals((KeyInfo)obj);
101  }
102 
103  public override int GetHashCode()
104  {
105  unchecked
106  {
107  int hashCode = PerPixelDiffuseDirectionalLightCount;
108  hashCode = (hashCode * 397) ^ PerPixelDirectionalLightCount;
109  hashCode = (hashCode * 397) ^ PerVertexDirectionalLightCount;
110  hashCode = (hashCode * 397) ^ PerVertexDiffusePixelSpecularDirectionalLightCount;
111  return hashCode;
112  }
113  }
114  }
115  }
116 }
Key of an effect parameter.
Definition: ParameterKey.cs:15
static bool IsDirectionalDiffuseVertexPixelSpecular(LightBinding x)
static bool IsDirectionalDiffuseSpecularPixel(LightBinding x)
LightShaderType LightShaderType
Specifies LightShaderType. Might be different than Light's one, since depending on Material or HW lim...
LightingPermutation(IEnumerable< LightBinding > lightBindings)