Exemplo n.º 1
0
        /// <summary>
        /// Assign the Keys to the textures in the tree.
        /// </summary>
        /// <param name="node">The node to look into.</param>
        /// <param name="getTextureKey">The delegate function to get the correct key.</param>
        private void AssignParameterKeys(IMaterialNode node, TextureKeyGetter getTextureKey)
        {
            var allTextures = GatherTextureValues(node).Distinct().ToList();
            var textureKeys = new Dictionary <string, ParameterKey <Graphics.Texture> >();

            foreach (var texSlot in allTextures)
            {
                //TODO: compare texture sampling method
                ParameterKey <Graphics.Texture> pk;
                var textureName = texSlot.TextureName;
                if (textureName == null || !textureKeys.TryGetValue(textureName, out pk))
                {
                    pk = getTextureKey(this);
                    if (textureName != null)
                    {
                        textureKeys.Add(textureName, pk);
                    }
                }

                texSlot.UsedParameterKey            = pk;
                texSlot.Sampler.SamplerParameterKey = TexturingKeys.Sampler;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Assign the Keys to the textures and the samplers in the list.
        /// </summary>
        /// <param name="nodes">List of nodes.</param>
        /// <param name="samplers">The list of sampler existing outside of MaterialTextureNode</param>
        /// <param name="getTextureKey">The delegate function to get the correct key.</param>
        private void AssignParameterKeys(IEnumerable <MaterialTextureNode> nodes, IEnumerable <NodeParameterSampler> samplers, TextureKeyGetter getTextureKey)
        {
            var textureKeys  = new Dictionary <IMaterialNode, ParameterKey <Graphics.Texture> >();
            var samplerKeys  = new Dictionary <SamplerDescription, ParameterKey <SamplerState> >();
            int samplerIndex = 0;

            // assign the predefined keys
            foreach (var texSlot in nodes.Distinct())
            {
                if (!texSlot.AutoAssignKey && texSlot.Key != null)
                {
                    texSlot.UsedParameterKey = (ParameterKey <Graphics.Texture>)texSlot.Key;
                    textureKeys.Add(texSlot, texSlot.UsedParameterKey);
                    usedTextureKeys.Add(texSlot.UsedParameterKey);
                }
            }

            // assign/generate all the keys
            foreach (var texSlot in nodes.Distinct())
            {
                ParameterKey <Graphics.Texture> textureParameterKey;
                if (!textureKeys.TryGetValue(texSlot, out textureParameterKey))
                {
                    textureParameterKey = getTextureKey(this);
                    textureKeys.Add(texSlot, textureParameterKey);
                }
                texSlot.UsedParameterKey = textureParameterKey;

                SetSamplerKey(texSlot.Sampler, samplerKeys, ref samplerIndex);
            }

            if (samplers != null)
            {
                foreach (var gen in samplers)
                {
                    SetSamplerKey(gen, samplerKeys, ref samplerIndex);
                }
            }
        }