private MaterialPtr createFromDescription(MaterialDescription description, bool alpha)
        {
            String name = description.Name;

            if (description.CreateAlphaMaterial && alpha) //Is this an automatic alpha material?
            {
                name += "Alpha";
            }
            MaterialPtr material = MaterialManager.getInstance().create(name, GroupName, false, null);

            CreateMaterial createMaterial = createUnifiedMaterial;

            if (description.IsSpecialMaterial && !specialMaterialFuncs.TryGetValue(description.SpecialMaterial, out createMaterial))
            {
                Logging.Log.Error("Could not find special material creation function {0} for material {1} in {2}.", description.SpecialMaterial, description.Name, description.SourceFile);
                createMaterial = createUnifiedMaterial; //Attempt to create something, out above clears this variable
            }

            IndirectionTexture indirectionTex = createMaterial(material.Value.getTechnique(0), description, alpha, true);

            if (alpha)
            {
                //Create no depth check technique
                Technique technique = material.Value.createTechnique();
                technique.setLodIndex(1);
                technique.createPass();
                createMaterial(technique, description, alpha, false);
            }

            //If we have an indirection texture we need to seup the virtual texturing, if not no additional techniques will be created and the
            //entity must disable itself for feedback buffer rendering somehow (likely visibility mask).
            if (indirectionTex != null)
            {
                String vertexShaderName   = shaderFactory.createFeedbackVertexProgram(indirectionTex.FeedbackBufferVPName, description.NumHardwareBones, description.NumHardwarePoses);
                String fragmentShaderName = shaderFactory.createFeedbackBufferFP(indirectionTex.FeedbackBufferFPName);
                indirectionTex.setupFeedbackBufferTechnique(material.Value, vertexShaderName);

                int count = 0;
                if (!indirectionTextureUsageCounts.TryGetValue(indirectionTex.Id, out count))
                {
                    indirectionTextureUsageCounts.Add(indirectionTex.Id, 0);
                }
                else
                {
                    indirectionTextureUsageCounts[indirectionTex.Id] = count + 1;
                }
            }

            material.Value.compile();
            material.Value.load();

            createdMaterials.Add(material.Value, new MaterialInfo(material.Value, indirectionTex));

            return(material);
        }
        private Pass createDepthPass(Technique technique, MaterialDescription description, bool alpha, bool depthCheck)
        {
            var pass = technique.getPass(0); //Make sure technique has one pass already defined

            if ((alpha || description.HasOpacityValue) && depthCheck)
            {
                //Setup depth check pass
                pass.setColorWriteEnabled(false);
                pass.setDepthBias(-1.0f);
                pass.setSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);

                pass.setVertexProgram(shaderFactory.createDepthCheckVertexProgram("DepthCheckVP", description.NumHardwareBones, description.NumHardwarePoses));
                pass.setFragmentProgram(shaderFactory.createHiddenFP("HiddenFP"));

                pass = technique.createPass(); //Get another pass
            }
            return(pass);
        }