private void Initialize(Effect effect, ParameterCollection usedParameters)
        {
            if (effect == null) throw new ArgumentNullException("effect");

            // TODO: Should we ignore various compiler keys such as CompilerParameters.GraphicsPlatformKey, CompilerParameters.GraphicsProfileKey and CompilerParameters.DebugKey?
            //       That was done previously in Effect.CompilerParameters
            // TODO: Should we clone usedParameters? Or somehow make sure it is immutable? (for now it uses the one straight from EffectCompiler, which might not be a good idea...)
            Parameters = usedParameters;
            var parameters = usedParameters;

            var internalValues = parameters.InternalValues;
            SortedKeys = new ParameterKey[internalValues.Count];
            SortedKeyHashes = new ulong[internalValues.Count];
            SortedCompilationValues = new object[internalValues.Count];
            SortedCounters = new int[internalValues.Count];

            for (int i = 0; i < internalValues.Count; ++i)
            {
                var internalValue = internalValues[i];

                SortedKeys[i] = internalValue.Key;
                SortedKeyHashes[i] = internalValue.Key.HashCode;
                SortedCompilationValues[i] = internalValue.Value.Object;
                SortedCounters[i] = internalValue.Value.Counter;
            }

            var keyMapping = new Dictionary<ParameterKey, int>();
            for (int i = 0; i < SortedKeys.Length; i++)
                keyMapping.Add(SortedKeys[i], i);
            Parameters.SetKeyMapping(keyMapping);
        }
 /// <summary>
 /// Describes a value parameter.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="offset"></param>
 /// <param name="size"></param>
 public ParameterKeyInfo(ParameterKey key, int offset, int count)
 {
     Key = key;
     Offset = offset;
     Count = count;
     BindingSlot = -1;
 }
 /// <summary>
 /// Describes a resource parameter.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="bindingSlot"></param>
 public ParameterKeyInfo(ParameterKey key, int bindingSlot)
 {
     Key = key;
     BindingSlot = bindingSlot;
     Offset = -1;
     Count = 1;
 }
        /// <summary>
        /// Gets (or creates) an entry to the DescriptorSetLayout and gets its index.
        /// </summary>
        /// <returns>The future entry index.</returns>
        public void AddBinding(ParameterKey key, string logicalGroup, EffectParameterClass @class, EffectParameterType type, int arraySize = 1, SamplerState immutableSampler = null)
        {
            hashBuilder.Write(key.Name);
            hashBuilder.Write(@class);
            hashBuilder.Write(arraySize);

            ElementCount += arraySize;
            Entries.Add(new Entry { Key = key, LogicalGroup = logicalGroup, Class = @class, Type = type, ArraySize = arraySize, ImmutableSampler = immutableSampler });
        }
        public static void RegisterParameter(this ParameterCollection parameterCollection, ParameterKey parameterKey, bool addDependencies = true)
        {
            var metaData = parameterKey.Metadatas.OfType<ParameterKeyValueMetadata>().FirstOrDefault();
            
            if (metaData == null)
                throw new ArgumentException("ParameterKey must be declared with metadata", "parameterKey");

            if (!parameterCollection.ContainsKey(parameterKey))
            {
                metaData.SetupDefaultValue(parameterCollection, parameterKey, addDependencies);
            }
        }
        public void AddLink(EffectMesh source, ParameterKey <RenderTarget> sourceKey, EffectMesh target, ParameterKey <Texture> targetKey, TextureDescription?textureDescription = null)
        {
            if (!graph.ContainsVertex(source))
            {
                graph.AddVertex(source);
            }

            if (!graph.ContainsVertex(target))
            {
                graph.AddVertex(target);
            }

            graph.AddEdge(new PostEffectEdge(source, sourceKey, target, targetKey, textureDescription));
        }
        public ParameterKey GetParameterKey(ParameterKey key)
        {
            if (key == null) throw new ArgumentNullException("key");

            var baseKey = key;
            int parameterKeyIndex;
            parameterKeyIndices.TryGetValue(baseKey, out parameterKeyIndex);

            key = parameterKeyIndex == 0 ? baseKey : baseKey.ComposeWith("i"+parameterKeyIndex.ToString(CultureInfo.InvariantCulture));

            parameterKeyIndex++;
            parameterKeyIndices[baseKey] = parameterKeyIndex;
            return key;
        }
Example #8
0
        public object GetObject(ParameterKey key)
        {
            if (key.Type != ParameterKeyType.Permutation && key.Type != ParameterKeyType.Object)
            {
                throw new InvalidOperationException("SetObject can only be used for Permutation or Object keys");
            }

            var accessor = GetObjectParameterHelper(key, false);

            if (accessor.Offset == -1)
            {
                return(null);
            }

            return(ObjectValues[accessor.Offset]);
        }
Example #9
0
        public void TestParameterKey()
        {
            var paramView1 = new ParameterKey<Vector3>("View");
            var paramView2 = new ParameterKey<Vector3>("View");
            var paramProj = new ParameterKey<Vector3>("Proj");

            Assert.Throws(typeof (ArgumentNullException), () => new ParameterKey<Vector3>(null));
            Assert.AreEqual(paramView1, paramView2);
            Assert.AreEqual(paramView1.GetHashCode(), paramView2.GetHashCode());
            Assert.AreNotEqual(paramView1, null);
            Assert.AreNotEqual(paramView1, new object());
            Assert.True(paramView1 == paramView2);
            Assert.True(paramView1 != paramProj);
            Assert.True(paramView1 == paramView2);
            Assert.True(ReferenceEquals(paramView1.Name, paramView2.Name));
        }
Example #10
0
        /// <summary>
        /// Creates the key with specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static ParameterKey <T> IndexedKey <T>(ParameterKey <T> key, int index)
        {
            if (index == 0)
            {
                return(key);
            }

            string keyName;

            if (key.Name[key.Name.Length - 1] == '0')
            {
                keyName = key.Name.Substring(0, key.Name.Length - 1) + index;
            }
            else
            {
                keyName = key.Name + index;
            }

            return(New <T>(default(T), keyName));
        }
Example #11
0
        public void SetObject(ParameterKey key, object value)
        {
            if (key.Type != ParameterKeyType.Permutation && key.Type != ParameterKeyType.Object)
            {
                throw new InvalidOperationException("SetObject can only be used for Permutation or Object keys");
            }

            var accessor = GetObjectParameterHelper(key);

            if (key.Type == ParameterKeyType.Permutation)
            {
                var oldValue = ObjectValues[accessor.Offset];
                if (oldValue != null && (value == null || !oldValue.Equals(value)) || // oldValue non null => check equality
                    (oldValue == null && value != null))    // oldValue null => check if value too
                {
                    PermutationCounter++;
                }
            }
            ObjectValues[accessor.Offset] = value;
        }
Example #12
0
        public override void Serialize(ref ParameterKey <T> obj, ArchiveMode mode, SerializationStream stream)
        {
            if (mode == ArchiveMode.Serialize)
            {
                stream.Write(obj.Name);
                stream.Write(obj.Length);
            }
            else
            {
                var parameterName   = stream.ReadString();
                var parameterLength = stream.ReadInt32();
                obj = (ParameterKey <T>)ParameterKeys.FindByName(parameterName);

                // If parameter could not be found, create one matching this type.
                if (obj == null)
                {
                    var metadata = new ParameterKeyValueMetadata <T>();
                    obj = new ParameterKey <T>(parameterName, parameterLength, metadata);
                    ParameterKeys.Merge(obj, null, parameterName);
                }
            }
        }
Example #13
0
        private void Initialize(Effect effect, ParameterCollection usedParameters)
        {
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }

            // TODO: Should we ignore various compiler keys such as CompilerParameters.GraphicsPlatformKey, CompilerParameters.GraphicsProfileKey and CompilerParameters.DebugKey?
            //       That was done previously in Effect.CompilerParameters
            // TODO: Should we clone usedParameters? Or somehow make sure it is immutable? (for now it uses the one straight from EffectCompiler, which might not be a good idea...)
            Parameters = usedParameters;
            var parameters = usedParameters;

            var internalValues = parameters.InternalValues;

            SortedKeys              = new ParameterKey[internalValues.Count];
            SortedKeyHashes         = new ulong[internalValues.Count];
            SortedCompilationValues = new object[internalValues.Count];
            SortedCounters          = new int[internalValues.Count];

            for (int i = 0; i < internalValues.Count; ++i)
            {
                var internalValue = internalValues[i];

                SortedKeys[i]              = internalValue.Key;
                SortedKeyHashes[i]         = internalValue.Key.HashCode;
                SortedCompilationValues[i] = internalValue.Value.Object;
                SortedCounters[i]          = internalValue.Value.Counter;
            }

            var keyMapping = new Dictionary <ParameterKey, int>();

            for (int i = 0; i < SortedKeys.Length; i++)
            {
                keyMapping.Add(SortedKeys[i], i);
            }
            Parameters.SetKeyMapping(keyMapping);
        }
Example #14
0
 public EffectParameterEntry(ParameterKey key, object value)
 {
     Key   = key;
     Value = value;
 }
Example #15
0
 public PostEffectEdge(EffectMesh source, ParameterKey <RenderTarget> sourceKey, EffectMesh target, ParameterKey <Texture> targetKey, RenderTarget texture)
 {
     Source          = source;
     Target          = target;
     SourceKey       = sourceKey;
     TargetKey       = targetKey;
     ProvidedTexture = texture;
 }
Example #16
0
        public void TestBasicValues()
        {
            //
            // => Initialize, Set V (1,1,1)
            //
            // ---------------
            // |  V = 1,1,1  | (Test)
            // |             |
            // ---------------
            var collection = new ParameterCollection("Test");

            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");
            collection.Set(paramV, new Vector3(1, 1, 1));

            // Verify collection.Count
            Assert.AreEqual(collection.Count, 1);

            // Verify collection.Contains
            Assert.AreEqual(collection.ContainsKey(paramV), true);

            // Verify collection.Keys Enumerator
            int count = 0;
            foreach(var key in collection.Keys)
            {
                Assert.AreEqual(key, paramV);
                count++;
            }
            Assert.AreEqual(count, 1);

            // Verify the Get and returned value
            var value = collection.Get(paramV);
            Assert.AreEqual(value, new Vector3(1,1,1));

            //
            // => Set P (2,2,2)
            //
            // ---------------
            // |  V = 1,1,1  | (Test)
            // |  P = 2,2,2  |
            // ---------------
            collection.Set(paramP, new Vector3(2,2,2));
            Assert.AreEqual(collection.Count, 2);
            Assert.AreEqual(collection.Get(paramP), new Vector3(2, 2, 2));

            //
            // => Remove param V
            //
            // ---------------
            // |             | (Test)
            // |  P = 2,2,2  |
            // ---------------
            collection.Remove(paramV);
            Assert.AreEqual(collection.Count, 1);

            // Check that param
            Assert.AreEqual(collection.Get(paramP), new Vector3(2, 2, 2));

            //
            // => Remove param P
            //
            // ---------------
            // |             | (Test)
            // |             |
            // ---------------
            collection.Remove(paramP);
            Assert.AreEqual(collection.Count, 0);

            //
            // => Set param V
            //
            // ---------------
            // |  V = 2,2,2  | (Test)
            // |             |
            // ---------------
            // Just add same key to test that everything is going fine
            collection.Set(paramV, new Vector3(2, 2, 2));
            Assert.AreEqual(collection.Count, 1);
            Assert.AreEqual(collection.Get(paramV), new Vector3(2, 2, 2));
        }
Example #17
0
        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   |                
            // ---------------                
            //        |
            // ---------------           ---------------
            // |  P = 3,3,3  | (Root2)   |  P = 5,5,5  | (Root3)    
            // |  V = ^,^,^  |         / |  V = P      |
            // |  VP= ^,^,^  |        /  |             |
            // ---------------       /   ---------------
            //        |             /
            // ---------------
            // |  P = 4,4,4  | (Child)    
            // |  V = ^,^,^  |
            // |  VP =^,^,^  |
            // ---------------
            //
            // Root1: VP = 3,3,3
            // Root2: VP = 5,5,5
            // Root3: V = 5,5,5
            // Child: VP = 8,8,8
            //
            // Number of registered Dynamic Values: 5
            // Root1: 1 => VP = Root1.V + Root1.P 
            // Root2: 1 => VP = Root1.V + Root2.P
            // Root3: 1 => V = Root3.P
            // Child: 2 => V = Child.P, VP = Child.V + Child.P
            childCollection.Set(paramP, new Vector3(4, 4, 4));
            Assert.AreEqual(childCollection.Get(paramVP), new Vector3(8, 8, 8));

            //
            // => Overrides P in child
            //
            // ---------------                
            // |  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 = 4,4,4  | (Child)    
            // |  V = ^,^,^  |
            // |  VP = V-P   |
            // ---------------
            //
            // Root1: VP = 3,3,3
            // Root2: VP = 5,5,5
            // Root3: V = 5,5,5
            // Child: VP = 8,8,8
            //
            // Number of registered Dynamic Values: 5
            // Root1: 1 => VP = Root1.V + Root1.P 
            // Root2: 1 => VP = Root1.V + Root2.P
            // Root3: 1 => V = Root3.P
            // Child: 2 => V = Child.P, VP = Child.V - Child.P
            childCollection.AddDynamic(paramVP, ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg - paramPArg));
            Assert.AreEqual(root1Collection.Get(paramVP), new Vector3(3, 3, 3));
            Assert.AreEqual(root2Collection.Get(paramVP), new Vector3(5, 5, 5));
            Assert.AreEqual(root3Collection.Get(paramV), new Vector3(5, 5, 5));
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(4, 4, 4));
            Assert.AreEqual(childCollection.Get(paramVP), new Vector3(0, 0, 0));
        }
        public static void RegisterParameter(this ParameterCollection parameterCollection, ParameterKey parameterKey, bool addDependencies = true)
        {
            var metaData = parameterKey.Metadatas.OfType <ParameterKeyValueMetadata>().FirstOrDefault();

            if (metaData == null)
            {
                throw new ArgumentException("ParameterKey must be declared with metadata", "parameterKey");
            }

            if (!parameterCollection.ContainsKey(parameterKey))
            {
                metaData.SetupDefaultValue(parameterCollection, parameterKey, addDependencies);
            }
        }
Example #19
0
        public void TestDynamicArrayValues1()
        {
            //
            // => Initialize, set V and P
            //
            // -------------------------------
            // |  VArray = {1,2,3}           | (Test)
            // |  PArray = {0,1,0}           |
            // -------------------------------
            var collection = new ParameterCollection("Test");
            var paramVArray = new ParameterKey<float[]>("VArray",3);
            var paramPArray = new ParameterKey<float[]>("PArray",3);

            // Set paramV and paramP
            collection.SetArray(paramVArray, new float[] { 1, 2, 3 });
            collection.SetArray(paramPArray, new float[] { 0, 1, 0 });

            //
            // => Set VDyn1 and VDyn2
            //
            // -------------------------------
            // |  VArray = {1,2,3}           | (Test)
            // |  PArray = {0,1,0}           |
            // |  VPDynArray = VArray+PArray |
            // -------------------------------
            var paramVPDynArray = new ParameterKey<float[]>("VPDynArray", 3);
            // paramViewProjDyn2 = paramV - paramP
            collection.AddDynamic(paramVPDynArray, ParameterDynamicValue.New(paramVArray, paramPArray, 
                (ref float[] paramVArg, ref float[] paramPArg, ref float[] output) =>
                    {
                        for (int i = 0; i < 3; i++)
                            output[i] = paramVArg[i] + paramPArg[i];
                    }));


            float[] result;
            collection.Get(paramVPDynArray, out result);
            Assert.AreEqual(new Vector3(result), new Vector3(1, 3, 3));

            // Remove value from array
            collection.Remove(paramVPDynArray);
        }
Example #20
0
        public void TestDynamicValues2()
        {
            //
            // => Initialize
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  VDyn = V + (1,1,1)  |
            // ------------------------
            // VDyn = (2,3,4)
            var collection = new ParameterCollection("Test");
            var paramV = new ParameterKey<Vector3>("View");
            var paramViewDyn = new ParameterKey<Vector3>("ViewDyn");

            // Set paramV and paramViewDyn1
            collection.Set(paramV, new Vector3(1,2,3));
            collection.AddDynamic(paramViewDyn, ParameterDynamicValue.New(paramV, (ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg + new Vector3(1, 1, 1)));

            // Check that value is correctly updated
            Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(2, 3, 4));

            //
            // => Set V to (3, 2, 1)
            //
            // ------------------------
            // |  V = 3,2,1           | (Test)
            // |  VDyn = V + (1,1,1)  |
            // ------------------------
            // VDyn = (4,3,2)
            collection.Set(paramV, new Vector3(3, 2, 1));
            Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(4, 3, 2));

            //
            // => Set VDyn = V + (2,2,2)
            //
            // ------------------------
            // |  V = 3,2,1           | (Test)
            // |  VDyn = V + (2,2,2)  |
            // ------------------------
            // VDyn = (5,4,3)
            collection.AddDynamic(paramViewDyn, ParameterDynamicValue.New(paramV, (ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg + new Vector3(2, 2, 2)));

            Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(5, 4, 3));

            // Should throw an InvalidOperationException, as paramV is used by paramViewDyn and
            // cannot be removed
            //Assert.Throws(typeof(InvalidOperationException), () => collection.Remove(paramV));

            // Remove all variables
            collection.Remove(paramViewDyn);
            collection.Remove(paramV);

            //
            // => Remove V and VDyn
            //
            // ------------------------
            // |                      | (Test)
            // |                      |
            // ------------------------
            Assert.AreEqual(collection.Count, 0);
        }
Example #21
0
        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));
        }
 public abstract void SetupDefaultValue(ParameterCollection parameterCollection, ParameterKey parameterKey, bool addDependencies);
Example #23
0
        private static bool ArePropertyValuesEqual(ParameterKey propertyKey, object propertyValue1, object propertyValue2)
        {
            var propertyType = propertyKey.PropertyType;

            if (!propertyType.GetTypeInfo().IsValueType && propertyType != typeof(string))
            {
                return object.ReferenceEquals(propertyValue1, propertyValue2);
            }

            return object.Equals(propertyValue1, propertyValue2);
        }
Example #24
0
 /// <summary>
 /// Sets a resizable resource for the specified key.
 /// </summary>
 /// <typeparam name="T">Type must be a <see cref="IReferencable"/></typeparam>
 /// <param name="parameterCollection">The parameter collection.</param>
 /// <param name="context">The context.</param>
 /// <param name="key">The key.</param>
 /// <param name="resourceValue">The resource value.</param>
 public static void SetWithResize <T>(this ParameterCollection parameterCollection, GraphicsResizeContext context, ParameterKey <T> key, T resourceValue) where T : IReferencable
 {
     context.SetWithResize(parameterCollection, key, resourceValue);
 }
Example #25
0
        public void TestGraphicsResource1()
        {
            //
            // => Removes P from Root5 and removes source from Root5
            //
            // -------------------              -------------------            
            // |  Tx = Texture2  | (Root0)      |  Tx = Texture1  | (Root1)    
            // |                 |              |                 |            
            // |                 |              |                 |            
            // -------------------              -------------------            
            //        |
            // -------------------                
            // |  Tx = ^         | (Root2)        
            // |                 |                
            // |                 |                
            // -------------------                
            //        
            var paramTx = new ParameterKey<MyGraphicsResource>("Tx");
            var roots = new ParameterCollection[4];
            for (int i = 0; i < roots.Length; i++)
            {
                roots[i] = new ParameterCollection("Root" + i);
            }
            roots[2].AddSources(roots[0]);

            var instanceTx2 = new MyGraphicsResource("Tx2");
            roots[0].Set(paramTx, instanceTx2);
            // Check that setting it twice is not going to add reference more than once
            roots[0].Set(paramTx, instanceTx2);

            var instanceTx1 = new MyGraphicsResource("Tx1");
            roots[1].Set(paramTx, instanceTx1);

            Assert.AreEqual(roots[2].Get(paramTx), instanceTx2);


            //
            // => Adds T1 on Root0 and removes it immediately
            //
            // -------------------              -------------------            
            // |  Tx = Texture2  | (Root0)      |  Tx = Texture1  | (Root1)    
            // |                 |              |                 |            
            // |                 |              |                 |            
            // -------------------              -------------------            
            //        |
            // -------------------                
            // |  Tx = ^         | (Root2)        
            // |                 |                
            // |                 |                
            // -------------------                
            //        
            var paramT1 = new ParameterKey<MyGraphicsResource>("T1");
            var instanceT1 = new MyGraphicsResource("T1");
            roots[0].Set(paramT1, instanceT1);
            roots[0].Remove(paramT1);
            Assert.AreEqual(instanceT1.DisposeCounter, 0);

            // Set paramT1 = Tx1 and after paramT2 = Tx2
            roots[0].Set(paramT1, instanceTx1);
            roots[0].Set(paramT1, instanceTx2);
            //
            // => Add source Root2 to Root1
            //
            // -------------------              -------------------            
            // |  Tx = Texture2  | (Root0)      |  Tx = Texture1  | (Root1)    
            // |                 |             /|                 |            
            // |                 |           /  |                 |            
            // -------------------         /    -------------------            
            //        |                  /
            // -------------------                
            // |  Tx = ^         | (Root2)        
            // |                 |                
            // |                 |                
            // -------------------                
            //        
            roots[2].AddSources(roots[1]);
            Assert.AreEqual(roots[1].Get(paramTx), instanceTx1);

            // Assert that graphics resource are disposed
            Assert.AreEqual(instanceTx1.DisposeCounter, 0);
            Assert.AreEqual(instanceTx2.DisposeCounter, 0);
        }
Example #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParameterDynamicValue{T,T1}"/> class.
 /// </summary>
 /// <param name="param1">The param1.</param>
 /// <param name="update">The update.</param>
 public ParameterDynamicValue1(ParameterKey <T1> param1, ParameterUpdateDelegate1 <TCast1, TCast> update, bool autoCheckDependencies)
 {
     AutoCheckDependencies = autoCheckDependencies;
     Dependencies          = new ParameterKey[] { param1, };
     Update = update;
 }
Example #27
0
        public void TestDynamicValues1()
        {
            //
            // => Trying to initialize VDyn = V + (1,1,1)
            //
            // ------------------------
            // |                      | (Test)
            // |                      |
            // ------------------------
            var collection = new ParameterCollection("Test");
            var paramV = new ParameterKey<Vector3>("View");
            var paramViewDyn = new ParameterKey<Vector3>("ViewDyn");

            // Should throw an InvalidOperationException, as paramV is not present in the collection
            collection.AddDynamic(paramViewDyn,
                            ParameterDynamicValue.New(paramV,
                                                        (ref Vector3 paramVArg, ref Vector3 output) =>
                                                        output = paramVArg + new Vector3(1, 1, 1)));
        }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParameterDynamicValue{T,T1}"/> class.
 /// </summary>
 /// <param name="param1">The param1.</param>
 /// <param name="update">The update.</param>
 public ParameterDynamicValue3(ParameterKey <T1> param1, ParameterKey <T2> param2, ParameterKey <T3> param3, ParameterUpdateDelegate3 <TCast1, TCast2, TCast3, TCast> update, bool autoCheckDependencies)
 {
     AutoCheckDependencies = autoCheckDependencies;
     Dependencies          = new ParameterKey[] { param1, param2, param3, };
     Update = update;
 }
Example #29
0
        public void TestDynamicValues3()
        {
            //
            // => Initialize, set V and P
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  P = 0,1,0           |
            // ------------------------
            var collection = new ParameterCollection("Test");
            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));

            //
            // => Set VDyn1 and VDyn2
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  P = 0,1,0           |
            // |  VDyn1 = V + P       |
            // |  VDyn2 = V - P       |
            // ------------------------
            // VDyn1 = (1,3,3)
            // VDyn2 = (1,1,3)
            var paramViewProjDyn1 = new ParameterKey<Vector3>("ViewProjDyn1");
            var paramViewProjDyn2 = new ParameterKey<Vector3>("ViewProjDyn2");
            var valueViewProjDyn1 = ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg);
            collection.AddDynamic(paramViewProjDyn1, valueViewProjDyn1);

            // paramViewProjDyn2 = paramV - paramP
            collection.AddDynamic(paramViewProjDyn2, ParameterDynamicValue.New(paramP, paramV, (ref Vector3 paramPArg, ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg - paramPArg));

            Assert.AreEqual(collection.Get(paramViewProjDyn1), new Vector3(1, 3, 3));
            Assert.AreEqual(collection.Get(paramViewProjDyn2), new Vector3(1, 1, 3));

            //
            // => Set VDyn1 and VDyn2
            //
            // ------------------------
            // |  V = 1,2,3           | (Test)
            // |  P = 0,1,0           |
            // |  VDyn1 = V + P       |
            // |  VDyn2 = V + P       |
            // ------------------------
            // VDyn1 = (1,3,3)
            // VDyn2 = (1,3,3)
            collection.AddDynamic(paramViewProjDyn2, valueViewProjDyn1);
            Assert.AreEqual(collection.Get(paramViewProjDyn2), new Vector3(1, 3, 3));

            //
            // => Remove all variables
            //
            // ------------------------
            // |                      | (Test)
            // |                      |
            // ------------------------
            collection.Remove(paramViewProjDyn1);
            collection.Remove(paramViewProjDyn2);
            collection.Remove(paramV);
            collection.Remove(paramP);

            Assert.AreEqual(collection.Count, 0);
        }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParameterDynamicValue{T,T1}"/> class.
 /// </summary>
 /// <param name="param1">The param1.</param>
 /// <param name="update">The update.</param>
 public ParameterDynamicValue6(ParameterKey <T1> param1, ParameterKey <T2> param2, ParameterKey <T3> param3, ParameterKey <T4> param4, ParameterKey <T5> param5, ParameterKey <T6> param6, ParameterUpdateDelegate6 <TCast1, TCast2, TCast3, TCast4, TCast5, TCast6, TCast> update, bool autoCheckDependencies)
 {
     AutoCheckDependencies = autoCheckDependencies;
     Dependencies          = new ParameterKey[] { param1, param2, param3, param4, param5, param6, };
     Update = update;
 }
Example #31
0
        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));
        }
Example #32
0
        public static ParameterDynamicValue <T> New <T, T1, T2, T3, T4>(ParameterKey <T1> param1, ParameterKey <T2> param2, ParameterKey <T3> param3, ParameterKey <T4> param4, ParameterUpdateDelegate4 <T1, T2, T3, T4, T> update, bool autoCheckDependencies = true)

/*            where T : struct
 *          where T1 : struct
 *          where T2 : struct
 *          where T3 : struct
 *          where T4 : struct
 */
        {
            return(new ParameterDynamicValue4 <T, T1, T2, T3, T4, T, T1, T2, T3, T4>(param1, param2, param3, param4, update, autoCheckDependencies));
        }
Example #33
0
        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);
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));
            Assert.AreEqual(rootCollection.Get(paramV), new Vector3(2, 2, 2));

            // Check that we cannot dipose a collction used as a source
            //Assert.Throws(typeof (InvalidOperationException), () => rootCollection.Release() );
            
            //
            // => Remove Root source from Child
            //
            // ---------------
            // |   V = 2,2,2 | (Root)  
            // |             |
            // ---------------
            //
            // ---------------
            // |             | (Child)    
            // ---------------            
            // Remove child using root and verify collection.Count
            childCollection.RemoveSource(rootCollection);
            Assert.AreEqual(childCollection.Count, 0);
        }
 public abstract void SetupDefaultValue(ParameterCollection parameterCollection, ParameterKey parameterKey, bool addDependencies);
Example #35
0
        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));
        }
Example #36
0
 public PostEffectEdge(EffectMesh source, ParameterKey <RenderTarget> sourceKey, EffectMesh target, ParameterKey <Texture> targetKey, TextureDescription?textureDescription = null)
 {
     Source             = source;
     Target             = target;
     SourceKey          = sourceKey;
     TargetKey          = targetKey;
     TextureDescription = textureDescription;
 }
Example #37
0
        public void TestCollections3()
        {
            //
            // => Initialize
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |             |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |  P = 2,2,2  | (Root2)    |  P = 3,3,3  | (Root3)  
            // |             |           |             |            |             |
            // |             |           |             |            |             |
            // ---------------           ---------------            ---------------         
            //        |
            // ---------------           
            // |  P = 4,4,4  | (Root4)     
            // |             |           
            // |             |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |             |           
            // |             |           
            // ---------------       
            //        
            // ---------------           
            // |             | (Root6)     
            // |             |           
            // |             |           
            // ---------------       
            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");
            var roots = new ParameterCollection[7];
            for (int i = 0; i < roots.Length; i++)
            {
                roots[i] = new ParameterCollection("Root" + i);
                if (i < 6)
                    roots[i].Set(paramP, new Vector3(i,i,i));
            }

            roots[3].Set(paramV, new Vector3(1,1,1));

            roots[1].AddSources(roots[0]);
            roots[4].AddSources(roots[1]);
            roots[5].AddSources(roots[4]);
            Assert.AreEqual(roots[4].Get(paramP), new Vector3(4, 4, 4));

            // check that adding twice a source if handled
            roots[1].AddSources(roots[0]);
            Assert.AreEqual(roots[1].Sources.Length, 1);

            //
            // => Add T on Root0 to test cascading inheritance and removes it from Root0
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |  T = 6,6,6 |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |  P = 2,2,2  | (Root2)    |  P = 3,3,3  | (Root3)  
            // |  T = ^,^,^  |           |             |            |             |
            // |             |           |             |            |             |
            // ---------------           ---------------            ---------------         
            //        |
            // ---------------           
            // |  P = 4,4,4  | (Root4)     
            // |  T = ^,^,^  |           
            // |             |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |  T = ^,^,^  |           
            // |             |           
            // ---------------  
            var paramT = new ParameterKey<Vector3>("Temp");
            roots[0].Set(paramT, new Vector3(6,6,6));
            Assert.AreEqual(roots[4].Get(paramT), new Vector3(6, 6, 6));
            roots[0].Remove(paramT);
            Assert.False(roots[5].ContainsKey(paramT));
            
            //
            // => Reset P on Root4
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |             |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |  P = 2,2,2  | (Root2)    |  P = 3,3,3  | (Root3)  
            // |             |           |             |            |  V = 1,1,1  |
            // |             |           |             |            |             |
            // ---------------           ---------------            ---------------         
            //        |
            // ---------------           
            // |  P = ^,^,^  | (Root4)     
            // |             |           
            // |             |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |             |           
            // |             |           
            // ---------------       
            roots[4].Reset(paramP);
            Assert.AreEqual(roots[4].Get(paramP), new Vector3(1, 1, 1));

            //
            // => Adds Root2 and Root3 as sources of Root4
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |             |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |  P = 2,2,2  | (Root2)  / |  P = 3,3,3  | (Root3)  
            // |             |           |             |        /   |  V = 1,1,1  |
            // |             |        /  |             |      /     |             |
            // ---------------       /   ---------------    /       ---------------         
            //        |             /                     /
            // ---------------                          /
            // |  P = ^,^,^  | (Root4)   --------------/    
            // |  V = ^,^,^  |           
            // |             |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |  V = ^,^,^  |           
            // |             |           
            // ---------------       
            roots[4].AddSources(roots[2], roots[3]);
            Assert.AreEqual(roots[4].Get(paramP), new Vector3(3, 3, 3));
            Assert.AreEqual(roots[5].Get(paramV), new Vector3(1, 1, 1));

            //
            // => Removes P from Root2
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |             |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |             | (Root2)  / |  P = 3,3,3  | (Root3)  
            // |             |           |             |        /   |  V = 1,1,1  |
            // |             |        /  |             |      /     |             |
            // ---------------       /   ---------------    /       ---------------         
            //        |             /                     /
            // ---------------                          /
            // |  P = ^,^,^  | (Root4)   --------------/    
            // |  V = ^,^,^  |           
            // |             |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |  V = ^,^,^  |           
            // |             |           
            // ---------------       
            roots[2].Remove(paramP);
            Assert.AreEqual(roots[4].Get(paramP), new Vector3(3, 3, 3));
            Assert.AreEqual(roots[5].Get(paramV), new Vector3(1, 1, 1));

            //
            // => Add dynamic value on Root4. 
            // => Sets V locally. 
            // => Overrides VX in Root5.
            // => Add Root5 as source of Root6
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |             |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |             | (Root2)  / |  P = 3,3,3  | (Root3)  
            // |             |           |             |        /   |  V = 1,1,1  |
            // |             |        /  |             |      /     |             |
            // ---------------       /   ---------------    /       ---------------         
            //        |             /                     /
            // ---------------                          /
            // |  P = ^,^,^  | (Root4)   --------------/    
            // |  V = ^,^,^  |           
            // |  X = 9,9,9  |           
            // | VX = V + X  |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |  V = ^,^,^  |           
            // |  X = ^,^,^  |           
            // | VX = V - X  |           
            // ---------------       
            //        |
            // ---------------           
            // |  P = ^,^,^  | (Root6)     
            // |  V = ^,^,^  |           
            // |  X = ^,^,^  |           
            // | VX =   ^    |           
            // ---------------       
            var paramX = new ParameterKey<Vector3>("X");
            var paramVX = new ParameterKey<Vector3>("VX");
            roots[4].Set(paramX, new Vector3(9,9,9));
            roots[4].AddDynamic(paramVX, ParameterDynamicValue.New(paramV, paramX, (ref Vector3 paramVArg, ref Vector3 paramXArg, ref Vector3 output) => output = paramVArg + paramXArg));
            roots[5].AddDynamic(paramVX, ParameterDynamicValue.New(paramV, paramX, (ref Vector3 paramVArg, ref Vector3 paramXArg, ref Vector3 output) => output = paramVArg - paramXArg));
            roots[6].AddSources(roots[5]);
            Assert.AreEqual(roots[4].Get(paramVX), new Vector3(10,10,10));
            Assert.AreEqual(roots[5].Get(paramVX), new Vector3(-8, -8, -8));

            //
            // => Removes P from Root5 and removes source from Root5
            //
            // ---------------                
            // |  P = 0,0,0  | (Root0)        
            // |             |                
            // |             |                
            // ---------------                
            //        |
            // ---------------           ---------------            ---------------
            // |  P = 1,1,1  | (Root1)   |             | (Root2)  / |  P = 3,3,3  | (Root3)  
            // |             |           |             |        /   |  V = 1,1,1  |
            // |             |        /  |             |      /     |             |
            // ---------------       /   ---------------    /       ---------------         
            //        |             /                     /
            // ---------------                          /
            // |  P = ^,^,^  | (Root4)   --------------/    
            // |  V = ^,^,^  |           
            // |  X = 9,9,9  |           
            // | VX = V + X  |           
            // ---------------       
            //        
            // ---------------           
            // |  P = 5,5,5  | (Root5)     
            // |             |           
            // |             |           
            // |             |           
            // --------------- 
            //        |
            // ---------------           
            // |  P = ^,^,^  | (Root6)     
            // |             |           
            // |             |           
            // |             |           
            // ---------------       
            Assert.True(roots[5].RemoveSource(roots[4]));

            // try to remove it a 2nd time
            Assert.False(roots[5].RemoveSource(roots[4]));

            Assert.True(roots[5].ContainsKey(paramP));
            Assert.True(roots[6].ContainsKey(paramP));

            Assert.False(roots[5].ContainsKey(paramV));
            Assert.False(roots[5].ContainsKey(paramX));
            Assert.False(roots[6].ContainsKey(paramV));
            Assert.False(roots[6].ContainsKey(paramX));

            Assert.AreEqual(roots[5].Get(paramP), new Vector3(5, 5, 5));
            Assert.AreEqual(roots[6].Get(paramP), new Vector3(5, 5, 5));

            //
            // => Removes source Root5 from Root6
            //
            // ---------------           
            // |             | (Root5)     
            // |  V = 1,1,1  |           
            // |  X = 9,9,9  |           
            // | VX = V - X  |           
            // --------------- 
            //        
            // ---------------           
            // |             | (Root6)     
            // |             |           
            // |             |           
            // |             |           
            // ---------------       
            roots[6].RemoveSource(roots[5]);
            Assert.AreEqual(roots[6].Count, 0);
        }
Example #38
0
        public void TestCollections4()
        {
            //          Root1 <- Root3
            //            |        |
            // Root0 <- Root2 <- Root4
            var paramV = new ParameterKey<Vector3>("View");
            var roots = new ParameterCollection[5];
            for (int i = 0; i < roots.Length; i++)
            {
                roots[i] = new ParameterCollection("Root" + i);
            }

            roots[0].Set(paramV, new Vector3(1.0f, 1.0f, 1.0f));
            roots[1].Set(paramV, new Vector3(2.0f, 1.0f, 1.0f));

            roots[2].AddSources(roots[1], roots[0]);
            roots[3].AddSources(roots[1]);
            roots[4].AddSources(roots[2], roots[3]);

            Assert.AreEqual(new Vector3(1.0f, 1.0f, 1.0f), roots[4].Get(paramV));
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="LightDirectionalShadowMapGroupShaderData" /> class.
            /// </summary>
            /// <param name="compositionKey">The composition key.</param>
            /// <param name="shadowType">Type of the shadow.</param>
            /// <param name="lightCountMax">The light count maximum.</param>
            public LightDirectionalShadowMapGroupShaderData(string compositionKey, LightShadowType shadowType, int lightCountMax)
            {
                this.shadowType = shadowType;
                this.cascadeCount = 1 << ((int)(shadowType & LightShadowType.CascadeMask) - 1);
                cascadeSplits = new float[cascadeCount * lightCountMax];
                worldToShadowCascadeUV = new Matrix[cascadeCount * lightCountMax];
                depthBiases = new float[lightCountMax];
                offsetScales = new float[lightCountMax];

                var mixin = new ShaderMixinSource();
                var isDepthRangeAuto = (this.shadowType & LightShadowType.DepthRangeAuto) != 0;
                mixin.Mixins.Add(new ShaderClassSource(ShaderName, cascadeCount, lightCountMax, (this.shadowType & LightShadowType.BlendCascade) != 0 && !isDepthRangeAuto, isDepthRangeAuto, (this.shadowType & LightShadowType.Debug) != 0));
                // TODO: Temporary passing filter here

                switch (shadowType & LightShadowType.FilterMask)
                {
                    case LightShadowType.PCF3x3:
                        mixin.Mixins.Add(new ShaderClassSource("ShadowMapFilterPcf", 3));
                        break;
                    case LightShadowType.PCF5x5:
                        mixin.Mixins.Add(new ShaderClassSource("ShadowMapFilterPcf", 5));
                        break;
                    case LightShadowType.PCF7x7:
                        mixin.Mixins.Add(new ShaderClassSource("ShadowMapFilterPcf", 7));
                        break;
                    default:
                        mixin.Mixins.Add(new ShaderClassSource("ShadowMapFilterDefault"));
                        break;
                }

                shadowShader = mixin;
                shadowMapTextureKey = ShadowMapKeys.Texture.ComposeWith(compositionKey);
                shadowMapTextureSizeKey = ShadowMapKeys.TextureSize.ComposeWith(compositionKey);
                shadowMapTextureTexelSizeKey = ShadowMapKeys.TextureTexelSize.ComposeWith(compositionKey);
                cascadeSplitsKey = ShadowMapReceiverDirectionalKeys.CascadeDepthSplits.ComposeWith(compositionKey);
                worldToShadowCascadeUVsKey = ShadowMapReceiverBaseKeys.WorldToShadowCascadeUV.ComposeWith(compositionKey);
                depthBiasesKey = ShadowMapReceiverBaseKeys.DepthBiases.ComposeWith(compositionKey);
                offsetScalesKey = ShadowMapReceiverBaseKeys.OffsetScales.ComposeWith(compositionKey);
            }
Example #40
0
        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));
        }
 public ParameterKey<Texture> GetTextureKey(Texture texture, ParameterKey<Texture> key, Color? defaultTextureValue = null)
 {
     var textureKey = (ParameterKey<Texture>)GetParameterKey(key);
     if (texture != null)
     {
         Parameters.Set(textureKey, texture);
     }
     else if (defaultTextureValue != null && Assets != null)
     {
         texture = GenerateTextureFromColor(defaultTextureValue.Value);
         Parameters.Set(textureKey, texture);
     }
     return textureKey;
 }
Example #42
0
 /// <summary>
 /// Creates a dynamic parameter key for texel size updated from the texture size.
 /// </summary>
 /// <param name="textureKey">Key of the texture to take the size from</param>
 /// <returns>A dynamic TexelSize parameter key updated according to the specified texture</returns>
 public static ParameterKey<Vector2> CreateDynamicTexelSizeParameterKey(ParameterKey<Texture> textureKey)
 {
     if (textureKey == null) throw new ArgumentNullException("textureKey");
     return ParameterKeys.NewDynamic(ParameterDynamicValue.New<Vector2, Texture>(textureKey, UpdateTexelSize));
 }