本文整理汇总了C#中ParameterCollection.AddSources方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterCollection.AddSources方法的具体用法?C# ParameterCollection.AddSources怎么用?C# ParameterCollection.AddSources使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterCollection
的用法示例。
在下文中一共展示了ParameterCollection.AddSources方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShadowMap
public ShadowMap(DirectionalLight light)
{
Light = light;
Parameters = new ParameterCollection("ShadowMap parameters");
// Inherits light parameters (to have its color and direction or viewproj matrix).
Parameters.AddSources(light.Parameters);
CasterParameters = new ParameterCollection("ShadowMap Caster Parameters");
CasterParameters.AddSources(Parameters);
ShadowDistance = 1000.0f;
ShadowMapSize = 512;
}
示例2: RenderMesh
/// <summary>
/// Initializes a new instance of the <see cref="RenderMesh" /> class.
/// </summary>
/// <param name="renderModel">The render model.</param>
/// <param name="mesh">The mesh data.</param>
/// <exception cref="System.ArgumentNullException">mesh</exception>
public RenderMesh(RenderModel renderModel, Mesh mesh)
{
if (renderModel == null) throw new ArgumentNullException("renderModel");
if (mesh == null) throw new ArgumentNullException("mesh");
RenderModel = renderModel;
Mesh = mesh;
Enabled = true;
UpdateMaterial();
// A RenderMesh is inheriting values from Mesh.Parameters
// We are considering that Mesh.Parameters is not updated frequently (should be almost immutable)
parameters = new ParameterCollection();
if (mesh.Parameters != null)
{
parameters.AddSources(mesh.Parameters);
}
}
示例3: TestCollections2
public void TestCollections2()
{
//
// => Initialize
//
// ---------------
// | P = 1,1,1 | (Root1)
// | V = 2,2,2 |
// | VP = V+P |
// ---------------
//
// --------------- ---------------
// | P = 3,3,3 | (Root2) | P = 5,5,5 | (Root3)
// | | | V = P |
// | | | |
// --------------- ---------------
var root1Collection = new ParameterCollection("Root1");
var root2Collection = new ParameterCollection("Root2");
var root3Collection = new ParameterCollection("Root3");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
var paramVP = new ParameterKey<Vector3>("ViewProj");
root1Collection.Set(paramP, new Vector3(1, 1, 1));
root1Collection.Set(paramV, new Vector3(2, 2, 2));
root1Collection.AddDynamic(paramVP, ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg));
root2Collection.Set(paramP, new Vector3(3, 3, 3));
root3Collection.Set(paramP, new Vector3(5, 5, 5));
root3Collection.AddDynamic(paramV, ParameterDynamicValue.New(paramP, (ref Vector3 paramPArg, ref Vector3 paramVArg) => paramVArg = paramPArg));
//
// => Add Root1 as a source of Root2
//
// ---------------
// | P = 1,1,1 | (Root1)
// | V = 2,2,2 |
// | VP = V+P |
// ---------------
// |
// --------------- ---------------
// | P = 3,3,3 | (Root2) | P = 5,5,5 | (Root3)
// | V = ^,^,^ | | V = P |
// | VP= ^,^,^ | | |
// --------------- ---------------
//
// Root1: VP = 3,3,3
// Root2: VP = 5,5,5
//
// Number of registered Dynamic Values: 3
// Root1: 1 => VP = Root1.V + Root1.P
// Root2: 1 => VP = Root1.V + Root2.P
// Root3: 1 => V = Root3.P
root2Collection.AddSources(root1Collection);
//
// => Add Root2 and Root3 as source of child collection
//
// ---------------
// | P = 1,1,1 | (Root1)
// | V = 2,2,2 |
// | VP = V+P |
// ---------------
// |
// --------------- ---------------
// | P = 3,3,3 | (Root2) | P = 5,5,5 | (Root3)
// | V = ^,^,^ | / | V = P |
// | VP= ^,^,^ | / | |
// --------------- / ---------------
// | /
// ---------------
// | P = ^,^,^ | (Child)
// | V = ^,^,^ |
// | VP =^,^,^ |
// ---------------
//
// Root1: VP = 3,3,3
// Root2: VP = 5,5,5
// Root3: V = 5,5,5
// Child: VP = 10,10,10
//
// Number of registered Dynamic Values: 4
// Root1: 1 => VP = Root1.V + Root1.P
// Root2: 1 => VP = Root1.V + Root2.P
// Root3: 1 => V = Root3.P
// Child: 1 => VP = Root3.V + Root3.P
var childCollection = new ParameterCollection("Child");
childCollection.AddSources(root2Collection, root3Collection);
Assert.AreEqual(childCollection.Get(paramVP), new Vector3(10, 10, 10));
//
// => Overrides P in child
//
// ---------------
// | P = 1,1,1 | (Root1)
// | V = 2,2,2 |
// | VP = V+P |
//.........这里部分代码省略.........
示例4: TestCollections1
public void TestCollections1()
{
//
// => Initialize
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | P = 3,3,3 | (Root2)
// | V = 2,2,2 | | |
// --------------- ---------------
//
// ---------------
// | | (Child)
// | |
// ---------------
var root1Collection = new ParameterCollection("Root1");
var root2Collection = new ParameterCollection("Root2");
var childCollection = new ParameterCollection("Child");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
root1Collection.Set(paramP, new Vector3(1, 1, 1));
root1Collection.Set(paramV, new Vector3(2, 2, 2));
root2Collection.Set(paramP, new Vector3(3, 3, 3));
//
// => Add source Roo1 and Root2 to Child
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | P = 3,3,3 | (Root2)
// | V = 2,2,2 | | |
// --------------- ---------------
// | /
// --------------- /
// | P = ^,^,^ | (Child) /
// | V = ^,^,^ |
// ---------------
// P = 3,3,3
// V = 2,2,2
childCollection.AddSources(root1Collection, root2Collection);
Assert.AreEqual(childCollection.Count, 2);
Assert.AreEqual(childCollection.Get(paramP), new Vector3(3, 3, 3));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));
//
// => Add source Roo1 and Root2 to Child
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | | (Root2)
// | V = 2,2,2 | | V = 3,3,3 |
// --------------- ---------------
// | /
// --------------- /
// | P = ^,^,^ | (Child) /
// | V = ^,^,^ |
// ---------------
// P = 1,1,1
// V = 3,3,3
root2Collection.Remove(paramP);
root2Collection.Set(paramV, new Vector3(3,3,3));
Assert.AreEqual(childCollection.Count, 2);
Assert.AreEqual(childCollection.Get(paramP), new Vector3(1, 1, 1));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
//
// => Remove source Root1 for Child
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | | (Root2)
// | V = 2,2,2 | | V = 3,3,3 |
// --------------- ---------------
// /
// --------------- /
// | | (Child) /
// | V = ^,^,^ |
// ---------------
// V = 3,3,3
childCollection.RemoveSource(root1Collection);
Assert.AreEqual(childCollection.Count, 1);
Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
//
// => Inherit Root1 from Child
//
// --------------- ---------------
// | | (Child) ------| | (Root2)
// | V = ^,^,^ | | V = 3,3,3 |
// --------------- ---------------
// |
// ---------------
// | P = 1,1,1 | (Root1)
// | V = 2,2,2 |
// ---------------
root1Collection.AddSources(childCollection);
Assert.AreEqual(root1Collection.Count, 2);
Assert.AreEqual(root1Collection.Get(paramP), new Vector3(1, 1, 1));
Assert.AreEqual(root1Collection.Get(paramV), new Vector3(2, 2, 2));
}
示例5: TestCollectionsBasicValues
public void TestCollectionsBasicValues()
{
//
// => Initialize
//
// ---------------
// | | (Root)
// | |
// ---------------
// |
// ---------------
// | | (Child)
// | |
// ---------------
var rootCollection = new ParameterCollection("Root");
var childCollection = new ParameterCollection("Child");
childCollection.AddSources(rootCollection);
//
// => Set P and V on Root (1,1,1)
//
// ---------------
// | V = 1,1,1 | (Root)
// | P = 1,1,1 |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// | P = ^,^,^ |
// ---------------
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
rootCollection.Set(paramV, new Vector3(1, 1, 1));
rootCollection.Set(paramP, new Vector3(1, 1, 1));
// Verify collection.Count
Assert.AreEqual(childCollection.Count, 2);
// Verify collection.Contains
Assert.AreEqual(childCollection.ContainsKey(paramV), true);
Assert.AreEqual(childCollection.ContainsKey(paramP), true);
//
// => Set V in Root, Get from Child
//
// ---------------
// | V = 2,2,2 | (Root)
// | P = 1,1,1 |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// | P = ^,^,^ |
// ---------------
// Verify the Get and returned value
Assert.AreEqual(childCollection.Get(paramV), new Vector3(1, 1, 1));
rootCollection.Set(paramV, new Vector3(2,2,2));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));
//
// => Remove P from Root
//
// ---------------
// | V = 2,2,2 | (Root)
// | |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// ---------------
rootCollection.Remove(paramP);
Assert.AreEqual(childCollection.Count, 1);
//
// => Overrides V in Child (3,3,3)
//
// ---------------
// | V = 2,2,2 | (Root)
// | |
// ---------------
// |
// ---------------
// | V = 3,3,3 | (Child)
// ---------------
childCollection.Set(paramV, new Vector3(3, 3, 3));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
Assert.AreEqual(rootCollection.Get(paramV), new Vector3(2, 2, 2));
//
// => Reset Key V on Child
//
// ---------------
// | V = 2,2,2 | (Root)
// | |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// ---------------
childCollection.Reset(paramV);
//.........这里部分代码省略.........
示例6: TestDynamicValues4
public void TestDynamicValues4()
{
//
// => Set P and V on Root (1,1,1)
//
// ---------------
// | V = 1,2,3 | (Root)
// | P = 0,1,0 |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child 0..10000)
// | P = ^,^,^ |
// | VP = V + P|
// ---------------
var collection = new ParameterCollection("Root");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
// Set paramV and paramP
collection.Set(paramV, new Vector3(1, 2, 3));
collection.Set(paramP, new Vector3(0, 1, 0));
var paramViewProjDyn1 = new ParameterKey<Vector3>("ViewProjDyn1");
var valueViewProjDyn1 = ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg);
var childsCollection = new ParameterCollection[10000];
for (int i = 0; i < childsCollection.Length; i++)
{
var childCollection = new ParameterCollection("Child " + i);
childCollection.AddSources(collection);
childCollection.AddDynamic(paramViewProjDyn1, valueViewProjDyn1);
childsCollection[i] = childCollection;
}
for (int i = 0; i < childsCollection.Length; i++)
Assert.AreEqual(childsCollection[i].Get(paramViewProjDyn1), new Vector3(1, 3, 3));
//
// => Modify P on Root
//
// ---------------
// | V = 1,2,3 | (Root)
// | P = 0,4,0 |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child 0..10000)
// | P = ^,^,^ |
// | VP = V + P|
// ---------------
collection.Set(paramP, new Vector3(0, 4, 0));
for (int i = 0; i < childsCollection.Length; i++)
Assert.AreEqual(childsCollection[i].Get(paramViewProjDyn1), new Vector3(1, 6, 3));
}
示例7: TestDynamicValues5
public void TestDynamicValues5()
{
//
// => Initialize
//
// ---------------
// | | (Root1)
// | V = 2,2,2 |
// | VP = V+P |
// ---------------
// |
// ---------------
// | | (Root2)
// | |
// | |
// ---------------
var root1Collection = new ParameterCollection("Root1");
var root2Collection = new ParameterCollection("Root2");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
var paramVP = new ParameterKey<Vector3>("ViewProj");
root1Collection.Set(paramV, new Vector3(2, 2, 2));
root1Collection.AddDynamic(paramVP, ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg));
root2Collection.AddSources(root1Collection);
// Add P = 3, 3, 3 into Root2
root2Collection.Set(paramP, new Vector3(3, 3, 3));
Assert.AreEqual(new Vector3(5, 5, 5), root2Collection.Get(paramVP));
}
示例8: TestCollectionsEngine
public void TestCollectionsEngine()
{
// RPP <- EP <- EMP
// EFPD <-/ |
// E <- EM
var paramV = new ParameterKey<Vector3>("View");
var paramV2 = new ParameterKey<Vector3>("ViewProj");
var dynV2 = ParameterDynamicValue.New(paramV, (ref Vector3 param1, ref Vector3 output) => { output = new Vector3(param1.X + 1.0f, param1.Y, param1.Z); });
var dynV3 = ParameterDynamicValue.New(paramV, (ref Vector3 param1, ref Vector3 output) => { output = new Vector3(param1.X + 4.0f, param1.Y, param1.Z); });
var renderPlugin = new ParameterCollection("RenderPlugin");
var effectPassDefault = new ParameterCollection("EffectPassDefault");
var effectPass = new ParameterCollection("EffectPass");
var effectMeshPass = new ParameterCollection("EffectMeshPass");
var renderMesh = new ParameterCollection("RenderMesh");
var effect = new ParameterCollection("Effect");
effectPassDefault.Set(paramV, new Vector3(2.0f, 2.0f, 2.0f));
effectPassDefault.AddDynamic(paramV2, dynV2);
effectPass.AddSources(effectPassDefault, renderPlugin);
renderPlugin.Set(paramV, new Vector3(1.0f, 1.0f, 1.0f));
Assert.AreEqual(new Vector3(2.0f, 1.0f, 1.0f), effectPass.Get(paramV2));
renderMesh.AddSources(effect);
effectMeshPass.AddSources(effectPass, renderMesh);
Assert.AreEqual(new Vector3(2.0f, 1.0f, 1.0f), effectMeshPass.Get(paramV2));
effect.AddDynamic(paramV2, dynV3);
effect.Set(paramV, new Vector3(3.0f, 3.0f, 3.0f));
Assert.AreEqual(new Vector3(7.0f, 3.0f, 3.0f), effectMeshPass.Get(paramV2));
}