Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TessellationPlugin.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.Linq;
3 using SiliconStudio.Paradox.Effects.Data;
4 using SiliconStudio.Paradox.Extensions;
5 using SiliconStudio.Paradox.DataModel;
6 using SiliconStudio.Paradox.Graphics;
7 using SiliconStudio.Paradox.Shaders;
8 using SiliconStudio.Paradox.Shaders.Compiler;
9 
10 namespace SiliconStudio.Paradox.Effects
11 {
12  public class TessellationPlugin : ShaderPlugin<RenderPassPlugin>
13  {
15  {
16  Flags |= EffectPluginFlags.StaticPermutation;
17  }
18 
20  {
21  object permutation;
22  if (permutations.TryGetValue(EffectMeshDataPermutation.Key, out permutation))
23  {
24  return new TessellationPluginPermutationKey((Mesh)permutation);
25  }
26 
27  return null;
28  }
29 
30  public override void SetupShaders(EffectMesh effectMesh)
31  {
32  var permutationKey = new TessellationPluginPermutationKey(effectMesh.MeshData);
33  if (permutationKey != null && permutationKey.Tessellation != null)
34  {
35  int inputControlPointCount = 3;
36 
37  BasicShaderPlugin.ApplyMixinClass(DefaultShaderPass.Shader, permutationKey.Tessellation, true);
38 
39  // Apply Displacement AEN plugin if both AEN is available and displacement is active
40  if (permutationKey.TessellationAEN)
41  {
42  BasicShaderPlugin.ApplyMixinClass(DefaultShaderPass.Shader, new ShaderClassSource("TessellationDisplacementAEN"), true);
43  DefaultShaderPass.SubMeshDataKey = "TessellationAEN";
44  inputControlPointCount = 12;
45  }
46 
47  DefaultShaderPass.Macros.Add(new ShaderMacro("InputControlPointCount", inputControlPointCount));
48  DefaultShaderPass.Macros.Add(new ShaderMacro("OutputControlPointCount", 3));
49  }
50  }
51 
52  private class TessellationPluginPermutationKey
53  {
54  public TessellationPluginPermutationKey(Mesh meshData)
55  {
56  if (meshData.Draw == null)
57  return;
58 
59  Tessellation = meshData.EffectParameters.Get(EffectData.Tessellation);
60  if (Tessellation != null)
61  {
62  TessellationAEN = meshData.Material.Parameters.Get(EffectData.TessellationAEN);
63  }
64  }
65 
66  public ShaderMixinSource Tessellation { get; set; }
67  public bool TessellationAEN { get; set; }
68 
69  protected bool Equals(TessellationPluginPermutationKey other)
70  {
71  return ShaderSourceComparer.Default.Equals(Tessellation, other.Tessellation)
72  && TessellationAEN.Equals(other.TessellationAEN);
73  }
74 
75  public override bool Equals(object obj)
76  {
77  if (ReferenceEquals(null, obj)) return false;
78  if (ReferenceEquals(this, obj)) return true;
79  if (obj.GetType() != typeof(TessellationPluginPermutationKey)) return false;
80  return Equals((TessellationPluginPermutationKey)obj);
81  }
82 
83  public override int GetHashCode()
84  {
85  unchecked
86  {
87  int hashCode = (Tessellation != null ? ShaderSourceComparer.Default.GetHashCode(Tessellation) : 0);
88  hashCode = (hashCode * 397) ^ TessellationAEN.GetHashCode();
89  return hashCode;
90  }
91  }
92  }
93  }
94 }
SiliconStudio.Paradox.Shaders.ShaderMacro ShaderMacro
A mixin performing a combination of ShaderClassSource and other mixins.
override void SetupShaders(EffectMesh effectMesh)
Flags
Enumeration of the new Assimp's flags.
override bool Equals(object against)
Determines whether the specified System.Object is equal to this instance.
object GenerateEffectKey(Dictionary< ParameterKey, object > permutations)