1 using System.Collections.Generic;
4 using SiliconStudio.Paradox.DataModel;
5 using SiliconStudio.Paradox.Effects.Data;
6 using SiliconStudio.Paradox.Graphics;
7 using SiliconStudio.Paradox.Shaders;
8 using SiliconStudio.Paradox.Shaders.Compiler;
10 namespace SiliconStudio.
Paradox.Effects
16 Flags |= EffectPluginFlags.StaticPermutation;
24 return new MaterialShaderPluginPermutationKey((
Mesh)permutation);
32 var permutationKey =
new MaterialShaderPluginPermutationKey(effectMesh.MeshData);
35 int defaultSkinningMaxBones = GraphicsDevice.Features.Profile <= GraphicsProfile.Level_9_3 ? 56 : 200;
37 if (permutationKey.SkinningPosition)
39 DefaultShaderPass.Macros.Add(
new ShaderMacro(
"SkinningMaxBones", defaultSkinningMaxBones));
40 BasicShaderPlugin.ApplyMixinClass(DefaultShaderPass.Shader,
new ShaderClassSource(
"TransformationSkinning"),
true);
43 if (permutationKey.SkinningNormal)
44 BasicShaderPlugin.ApplyMixinClass(DefaultShaderPass.Shader,
new ShaderClassSource(
"NormalSkinning"),
true);
45 if (permutationKey.SkinningTangent)
46 BasicShaderPlugin.ApplyMixinClass(DefaultShaderPass.Shader,
new ShaderClassSource(
"TangentSkinning"),
true);
48 if (permutationKey.AlbedoMaterial != null)
49 BasicShaderPlugin.ApplyMixinClass(DefaultShaderPass.Shader, permutationKey.AlbedoMaterial,
true);
56 effectMesh.Parameters.Set(BlendStateKey, GraphicsDevice.BlendStates.NonPremultiplied);
60 private class MaterialShaderPluginPermutationKey
62 public MaterialShaderPluginPermutationKey(
Mesh meshData)
64 if (meshData.
Draw == null)
67 var subMeshData = meshData.Draw;
69 NeedAlphaBlending = meshData.EffectParameters.Get(EffectData.NeedAlphaBlending);
70 AlbedoMaterial = meshData.EffectParameters.Get(EffectData.AlbedoMaterial);
72 var vertexElementUsages =
new HashSet<string>(subMeshData
74 .SelectMany(x => x.Declaration.VertexElements)
75 .Select(x => x.SemanticAsText));
77 if (vertexElementUsages.Contains(
"BLENDWEIGHT"))
79 SkinningPosition =
true;
80 if (vertexElementUsages.Contains(
"NORMAL"))
81 SkinningNormal =
true;
82 if (vertexElementUsages.Contains(
"TANGENT"))
83 SkinningTangent =
true;
88 public bool NeedAlphaBlending {
get; set; }
89 public bool SkinningPosition {
get; set; }
90 public bool SkinningNormal {
get; set; }
91 public bool SkinningTangent {
get; set; }
93 protected bool Equals(MaterialShaderPluginPermutationKey other)
95 return ShaderSourceComparer.Default.Equals(AlbedoMaterial, other.AlbedoMaterial)
96 && SkinningPosition.
Equals(other.SkinningPosition)
97 && SkinningNormal.Equals(other.SkinningNormal)
98 && SkinningTangent.Equals(other.SkinningTangent)
99 && NeedAlphaBlending.Equals(other.NeedAlphaBlending);
102 public override bool Equals(
object obj)
104 if (ReferenceEquals(null, obj))
return false;
105 if (ReferenceEquals(
this, obj))
return true;
106 if (obj.GetType() != typeof(MaterialShaderPluginPermutationKey))
return false;
107 return Equals((MaterialShaderPluginPermutationKey)obj);
110 public override int GetHashCode()
114 int hashCode = (AlbedoMaterial != null ? ShaderSourceComparer.Default.GetHashCode(AlbedoMaterial) : 0);
115 hashCode = (hashCode * 397) ^ SkinningPosition.GetHashCode();
116 hashCode = (hashCode * 397) ^ SkinningNormal.GetHashCode();
117 hashCode = (hashCode * 397) ^ SkinningTangent.GetHashCode();
118 hashCode = (hashCode * 397) ^ NeedAlphaBlending.GetHashCode();
SiliconStudio.Paradox.Shaders.ShaderMacro ShaderMacro
A mixin performing a combination of ShaderClassSource and other mixins.
override void SetupShaders(EffectMesh effectMesh)
static readonly ParameterKey< bool > NeedAlphaBlending
Flags
Enumeration of the new Assimp's flags.
override bool Equals(object against)
Determines whether the specified System.Object is equal to this instance.
override void SetupResources(EffectMesh effectMesh)
object GenerateEffectKey(Dictionary< ParameterKey, object > permutations)
A shader class used for mixin.
static ParameterKey< Mesh > Key