-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstancedModelProcessor.cs
48 lines (40 loc) · 1.86 KB
/
InstancedModelProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/// <summary>
/// Content Pipeline processor applies the InstancedModel.fx shader
/// onto models, so they can be drawn using hardware instancing.
/// </summary>
[ContentProcessor(DisplayName = "Instanced Model")]
public class InstancedModelProcessor : ModelProcessor
{
ContentIdentity rootIdentity;
ContentIdentity shaderIdentity;
/// <summary>
/// Override the Process method to store the ContentIdentity of the model root node.
/// </summary>
public override ModelContent Process(NodeContent input, ContentProcessorContext context)
{
rootIdentity = input.Identity;
return base.Process(input, context);
}
/// <summary>
/// Override the ConvertMaterial method to apply our custom InstancedModel.fx shader.
/// </summary>
protected override MaterialContent ConvertMaterial(MaterialContent material,
ContentProcessorContext context)
{
// Create a new material.
EffectMaterialContent newMaterial = new EffectMaterialContent();
string root = @"C:\Users\armad\Desktop\wax\Wax.Desktop\Content\visual_models\Instancing.fx";
string absolute = Path.GetFullPath(root);
// Tell it to use our custom InstancedModel.fx shader.
newMaterial.Effect = new ExternalReference<EffectContent>(absolute,
rootIdentity);
// Copy the texture setting across from the original material.
BasicMaterialContent basicMaterial = material as BasicMaterialContent;
if ((basicMaterial != null) && (basicMaterial.Texture != null))
{
newMaterial.Textures.Add("Texture", basicMaterial.Texture);
}
// Chain to the base ModelProcessor, so it can build our new material.
return base.ConvertMaterial(newMaterial, context);
}
}