Esempio n. 1
0
        void UpdateAnchor(Node node, ARAnchor anchor)
        {
            var planeAnchor = anchor as ARPlaneAnchor;

            if (planeAnchor == null)
            {
                return;
            }

            Material tileMaterial = null;
            Node     planeNode    = null;

            if (node == null)
            {
                var id = planeAnchor.Identifier.ToString();
                node      = anchorsNode.CreateChild(id);
                planeNode = node.CreateChild("SubPlane");
                var plane = planeNode.CreateComponent <StaticModel>();
                planeNode.Position = new Vector3();
                plane.Model        = CoreAssets.Models.Plane;

                tileMaterial = new Material();
                tileMaterial.SetTexture(TextureUnit.Diffuse, ResourceCache.GetTexture2D("Textures/PlaneTile.png"));
                var tech = new Technique();
                var pass = tech.CreatePass("alpha");
                pass.DepthWrite   = false;
                pass.BlendMode    = BlendMode.Alpha;
                pass.PixelShader  = "PlaneTile";
                pass.VertexShader = "PlaneTile";
                tileMaterial.SetTechnique(0, tech);
                tileMaterial.SetShaderParameter("MeshColor", new Color(Randoms.Next(), 1, Randoms.Next()));
                tileMaterial.SetShaderParameter("MeshAlpha", 0.75f);                 // set 0.0f if you want to hide them
                tileMaterial.SetShaderParameter("MeshScale", 32.0f);

                var planeRb = planeNode.CreateComponent <RigidBody>();
                planeRb.Friction = 1.5f;
                CollisionShape shape = planeNode.CreateComponent <CollisionShape>();
                shape.SetBox(Vector3.One, Vector3.Zero, Quaternion.Identity);

                plane.Material = tileMaterial;
            }
            else
            {
                planeNode    = node.GetChild("SubPlane");
                tileMaterial = planeNode.GetComponent <StaticModel>().Material;
            }

            arkitComponent.ApplyOpenTkTransform(node, planeAnchor.Transform, true);

            planeNode.Scale    = new Vector3(planeAnchor.Extent.X, 0.1f, planeAnchor.Extent.Z);
            planeNode.Position = new Vector3(planeAnchor.Center.X, planeAnchor.Center.Y, -planeAnchor.Center.Z);

            //var animation = new ValueAnimation();
            //animation.SetKeyFrame(0.0f, 0.3f);
            //animation.SetKeyFrame(0.5f, 0.0f);
            //tileMaterial.SetShaderParameterAnimation("MeshAlpha", animation, WrapMode.Once, 1.0f);

            //Debug.WriteLine($"ARPlaneAnchor  Extent({planeAnchor.Extent}), Center({planeAnchor.Center}), Position({planeAnchor.Transform.Row3}");
        }
        void CreateFixedPipelineTechnique()
        {
            Technique tecnhique = BaseMaterial.CreateTechnique();
            Pass      pass      = tecnhique.CreatePass();

            pass.NormalizeNormals = true;

            pass.CreateTextureUnitState(ConvertToFullPath(DiffuseMap));
        }
Esempio n. 3
0
        public void BuildMaterialPasses(PageDecalInfo pageInfo)
        {
            Technique t = FindPageTechnique(pageInfo.Coord);

            if (t != null)
            {
                float pageX = pageInfo.Coord.X * TerrainManager.Instance.PageSize * TerrainManager.oneMeter;
                float pageZ = pageInfo.Coord.Z * TerrainManager.Instance.PageSize * TerrainManager.oneMeter;

                int availableTexUnits = 0;
                int curTexUnit        = 0;
                int texUnitsPerPass   = 8;

                Pass p = null;

                foreach (DecalElement element in pageInfo.Decals)
                {
                    // if there are no texture units available, allocate a new pass
                    if (availableTexUnits == 0)
                    {
                        p = t.CreatePass();
                        pageInfo.Passes.Add(p);

                        p.SetSceneBlending(SceneBlendType.TransparentAlpha);
                        // TODO: Unclear what should happen here.  The new Ogre interface
                        // supports SetDepthBias(constantBias, slopeBias), but the units are
                        // different.  Ask Jeff.
                        p.DepthBias = 1;

                        curTexUnit        = 0;
                        availableTexUnits = texUnitsPerPass;
                    }

                    TextureUnitState texUnit = p.CreateTextureUnitState(element.ImageName, 0);

                    if (curTexUnit == 0)
                    {
                        texUnit.SetColorOperation(LayerBlendOperation.Replace);
                        texUnit.SetAlphaOperation(LayerBlendOperationEx.Source1, LayerBlendSource.Texture, LayerBlendSource.Current, 0, 0, 0);
                    }
                    else
                    {
                        texUnit.SetColorOperation(LayerBlendOperation.AlphaBlend);
                        texUnit.SetAlphaOperation(LayerBlendOperationEx.AddSmooth, LayerBlendSource.Texture, LayerBlendSource.Current, 0, 0, 0);
                    }
                    texUnit.TextureAddressing  = TextureAddressing.Border;
                    texUnit.TextureBorderColor = new ColorEx(0, 0, 0, 0);

                    element.UpdateTextureTransform(texUnit, pageX, pageZ);

                    // bump the counts
                    curTexUnit++;
                    availableTexUnits--;
                }
            }
        }
Esempio n. 4
0
        private void PreparePass()
        {
            Technique technique = this.materialPtr.CreateTechnique();            ///UNDONE setShadowCasterMaterial

            this.Pass                   = technique.CreatePass();
            this.Pass.CullingMode       = CullingMode.CULL_NONE;
            this.Pass.DepthCheckEnabled = false;
            this.Pass.DepthWriteEnabled = false;
            this.Pass.LightingEnabled   = false;

            this.Pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);

            TextureUnitState tus = this.Pass.CreateTextureUnitState();

            tus.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP);
        }
Esempio n. 5
0
        public static void CreateEditNode(string key, Vector3 position, Quaternion orientation)
        {
            WorldEntity worldEntity = Engine.World.GetWorldEntity(key);
            SceneNode   sceneNode   = worldEntity.CreateSceneNode(position, orientation);

            if (sceneNode != null)
            {
                EditNode editNode    = new EditNode(key, worldEntity, sceneNode);
                ushort   numObjects  = sceneNode.NumAttachedObjects();
                ushort   numEntities = 0;

                for (ushort i = 0; i < numObjects; i++)
                {
                    Entity entity = sceneNode.GetAttachedObject(i) as Entity;

                    // if we haven't found an entity by now we need to make one ourselves
                    if (entity == null && i == numObjects - 1 && numEntities == 0)
                    {
                        entity = Engine.Graphics.SceneManager.CreateEntity("ball.mesh");
                        sceneNode.AttachObject(entity);
                    }

                    // setup special material scheme used in the editor only
                    if (entity != null)
                    {
                        for (uint j = 0; j < entity.NumSubEntities; j++)
                        {
                            Technique technique = entity.GetSubEntity(j).GetMaterial().CreateTechnique();
                            technique.SchemeName = "WireframeScheme";
                            Pass pass = technique.CreatePass();
                            pass.LightingEnabled = false;
                            TextureUnitState textureUnit = pass.CreateTextureUnitState();
                            textureUnit.SetColourOperationEx(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_CURRENT,
                                                             new ColourValue(
                                                                 0.5f + Mogre.Math.RangeRandom(0, 0.5f),
                                                                 0.5f + Mogre.Math.RangeRandom(0, 0.5f),
                                                                 0.5f + Mogre.Math.RangeRandom(0, 0.5f)));
                        }

                        entity.UserObject = editNode;
                        numEntities++;
                    }
                }

                Editor.editNodes.Add(editNode);
            }
        }
Esempio n. 6
0
        public Program(string name, HighLevelGpuProgram vs, HighLevelGpuProgram ps,
                       IEnumerable <VariableDescription> samplers)
        {
            VertexShader = vs;
            PixelShader  = ps;

            LogManager.Instance.Write("VS:");
            LogManager.Instance.Write("================================================================================");
            LogManager.Instance.Write(vs.Source);
            LogManager.Instance.Write("PS:");
            LogManager.Instance.Write("================================================================================");
            LogManager.Instance.Write(ps.Source);

            var mm = MaterialManager.Instance;

            Material = (Material)mm.Create(name, "SLSharp");
            var mat = Material;

            mat.RemoveAllTechniques();
            _tech            = mat.CreateTechnique();
            _tech.SchemeName = "SLSharp";
            _tech.RemoveAllPasses();
            Pass = _tech.CreatePass();
            if (vs != null)
            {
                Pass.SetVertexProgram(vs.Name);
            }
            if (ps != null)
            {
                Pass.SetFragmentProgram(ps.Name);
            }

            foreach (var s in samplers)
            {
                var tu = Pass.CreateTextureUnitState();
                tu.Name = s.Name;
                _textureUnits.Add(s.Name, tu);
            }

            Pass.LightingEnabled = false;
            mat.Load();

            MatToProg.Add(mat, this);
        }
        public override void OnAttachedToNode(Node node)
        {
            Application.Renderer.ReuseShadowMaps = false;
            Technique technique = new Technique();
            var       pass      = technique.CreatePass("litalpha");

            pass.DepthWrite          = false;
            pass.BlendMode           = BlendMode.Multiply;
            pass.PixelShader         = "LitSolid";
            pass.VertexShader        = "LitSolid";
            pass.VertexShaderDefines = "NOUV";
            Material material = new Material();

            material.SetTechnique(0, technique);
            material.SetShaderParameter(CoreAssets.ShaderParameters.MatDiffColor, Color.White);
            material.SetShaderParameter(CoreAssets.ShaderParameters.MatSpecColor, Color.White);
            StaticModel model = Node.CreateComponent <StaticModel>();

            model.Model    = CoreAssets.Models.Plane;
            model.Material = material;
        }
Esempio n. 8
0
        private void SetupFontMaterial()
        {
            Technique        technique    = fontMaterial.CreateTechnique();
            Pass             pass         = technique.CreatePass();
            TextureUnitState texUnitState = pass.CreateTextureUnitState();

            texUnitState.SetTextureName(font.TextureName);
            // texUnitState.SetAlphaOperation(LayerBlendOperation.AlphaBlend);
            // texUnitState.SetTextureFiltering(FilterOptions.Linear);
            texUnitState.TextureAddressing = TextureAddressing.Clamp;
            texUnitState.TextureMatrix     = Matrix4.Identity;
            texUnitState.TextureCoordSet   = 0;

//			renderSystem.SetTextureCoordCalculation( 0, TexCoordCalcMethod.None );
//			renderSystem.SetTextureUnitFiltering(0, FilterOptions.Linear, FilterOptions.Linear, FilterOptions.Point);
//			renderSystem.SetAlphaRejectSettings(0, CompareFunction.AlwaysPass, 0);
//			renderSystem.SetTextureBlendMode( 0, unitState.ColorBlendMode );
//			renderSystem.SetTextureBlendMode( 0, unitState.AlphaBlendMode );
//
//			// enable alpha blending
//			renderSystem.SetSceneBlending(SceneBlendFactor.SourceAlpha, SceneBlendFactor.OneMinusSourceAlpha);
        }
        bool CreateDefaultTechnique()
        {
            string sourceFile = "Base\\Shaders\\SimpleExample.cg_hlsl";

            string vertexSyntax;
            string fragmentSyntax;

            {
                if (RenderSystem.Instance.IsDirect3D())
                {
                    vertexSyntax   = "vs_3_0";
                    fragmentSyntax = "ps_3_0";
                }
                else if (RenderSystem.Instance.IsOpenGLES())
                {
                    vertexSyntax   = "hlsl2glsl";
                    fragmentSyntax = "hlsl2glsl";
                }
                else
                {
                    vertexSyntax   = "arbvp1";
                    fragmentSyntax = "arbfp1";
                }
            }

            //technique is supported?
            if (!GpuProgramManager.Instance.IsSyntaxSupported(fragmentSyntax))
            {
                return(false);
            }
            if (!GpuProgramManager.Instance.IsSyntaxSupported(vertexSyntax))
            {
                return(false);
            }

            BaseMaterial.ReceiveShadows = false;

            //create techniques
            foreach (MaterialSchemes materialScheme in Enum.GetValues(typeof(MaterialSchemes)))
            {
                Technique technique = BaseMaterial.CreateTechnique();
                technique.SchemeName = materialScheme.ToString();

                //pass 0: ambient pass
                //pass 1: directional light
                //pass 2: point light
                //pass 3: spot light

                for (int nPass = 0; nPass < 4; nPass++)
                {
                    //create pass
                    Pass pass = technique.CreatePass();

                    bool ambientPass = nPass <= 1;
                    bool lightPass   = nPass >= 1;

                    RenderLightType lightType = RenderLightType.Directional;

                    ambientPass = nPass == 0;
                    lightPass   = nPass != 0;

                    switch (nPass)
                    {
                    case 1: lightType = RenderLightType.Directional; break;

                    case 2: lightType = RenderLightType.Point; break;

                    case 3: lightType = RenderLightType.Spot; break;
                    }

                    if (lightPass)
                    {
                        pass.SpecialRendering = true;
                        pass.SpecialRenderingIteratePerLight = true;
                        pass.SpecialRenderingLightType       = lightType;
                    }

                    int lightCount = lightPass ? 1 : 0;

                    /////////////////////////////////////
                    //configure general pass settings
                    {
                        //disable Direct3D standard fog features
                        pass.SetFogOverride(FogMode.None, new ColorValue(0, 0, 0), 0, 0, 0);

                        //Light pass
                        if (!ambientPass)
                        {
                            pass.DepthWrite        = false;
                            pass.SourceBlendFactor = SceneBlendFactor.One;
                            pass.DestBlendFactor   = SceneBlendFactor.One;
                        }
                    }

                    /////////////////////////////////////
                    //generate general compile arguments and create texture unit states
                    StringBuilder generalArguments = new StringBuilder(256);
                    {
                        if (RenderSystem.Instance.IsDirect3D())
                        {
                            generalArguments.Append(" -DDIRECT3D");
                        }
                        if (RenderSystem.Instance.IsOpenGL())
                        {
                            generalArguments.Append(" -DOPENGL");
                        }
                        if (RenderSystem.Instance.IsOpenGLES())
                        {
                            generalArguments.Append(" -DOPENGL_ES");
                        }

                        if (ambientPass)
                        {
                            generalArguments.Append(" -DAMBIENT_PASS");
                        }
                        generalArguments.AppendFormat(" -DLIGHT_COUNT={0}", lightCount);
                        generalArguments.Append(" -DLIGHTING");

                        //DiffuseMap
                        if (!string.IsNullOrEmpty(DiffuseMap))
                        {
                            generalArguments.Append(" -DDIFFUSE_MAP");
                            pass.CreateTextureUnitState(ConvertToFullPath(DiffuseMap));
                        }
                    }

                    /////////////////////////////////////
                    //generate programs

                    //generate program for only ambient pass
                    if (ambientPass && !lightPass)
                    {
                        string error;

                        //vertex program
                        GpuProgram vertexProgram = GpuProgramCacheManager.Instance.AddProgram(
                            "SimpleExample_Vertex_", GpuProgramType.Vertex, sourceFile,
                            "main_vp", vertexSyntax, generalArguments.ToString(),
                            out error);
                        if (vertexProgram == null)
                        {
                            Log.Fatal(error);
                            return(false);
                        }

                        SetProgramAutoConstants(vertexProgram.DefaultParameters, 0);
                        pass.VertexProgramName = vertexProgram.Name;

                        //fragment program
                        GpuProgram fragmentProgram = GpuProgramCacheManager.Instance.AddProgram(
                            "SimpleExample_Fragment_", GpuProgramType.Fragment, sourceFile,
                            "main_fp", fragmentSyntax, generalArguments.ToString(),
                            out error);
                        if (fragmentProgram == null)
                        {
                            Log.Fatal(error);
                            return(false);
                        }

                        SetProgramAutoConstants(fragmentProgram.DefaultParameters, 0);
                        pass.FragmentProgramName = fragmentProgram.Name;
                    }

                    //generate program for light passes
                    if (lightPass)
                    {
                        string error;

                        StringBuilder arguments = new StringBuilder(generalArguments.Length + 100);
                        arguments.Append(generalArguments.ToString());

                        arguments.AppendFormat(" -DLIGHTTYPE_{0}", lightType.ToString().ToUpper());

                        //vertex program
                        GpuProgram vertexProgram = GpuProgramCacheManager.Instance.AddProgram(
                            "SimpleExample_Vertex_", GpuProgramType.Vertex, sourceFile,
                            "main_vp", vertexSyntax, arguments.ToString(),
                            out error);
                        if (vertexProgram == null)
                        {
                            Log.Fatal(error);
                            return(false);
                        }

                        SetProgramAutoConstants(vertexProgram.DefaultParameters, lightCount);
                        pass.VertexProgramName = vertexProgram.Name;

                        //fragment program
                        GpuProgram fragmentProgram = GpuProgramCacheManager.Instance.AddProgram(
                            "SimpleExample_Fragment_", GpuProgramType.Fragment, sourceFile,
                            "main_fp", fragmentSyntax, arguments.ToString(),
                            out error);
                        if (fragmentProgram == null)
                        {
                            Log.Fatal(error);
                            return(false);
                        }

                        SetProgramAutoConstants(fragmentProgram.DefaultParameters, lightCount);
                        pass.FragmentProgramName = fragmentProgram.Name;
                    }
                }
            }

            return(true);
        }
Esempio n. 10
0
        protected override bool OnInitBaseMaterial()
        {
            if (!base.OnInitBaseMaterial())
            {
                return(false);
            }

            string sourceFile = "Base\\Shaders\\DefaultShadowCaster.cg_hlsl";

            string vertexSyntax;
            string fragmentSyntax;
            {
                if (RenderSystem.Instance.IsDirect3D())
                {
                    vertexSyntax   = "vs_3_0";
                    fragmentSyntax = "ps_3_0";
                }
                else if (RenderSystem.Instance.IsOpenGLES())
                {
                    vertexSyntax   = "hlsl2glsl";
                    fragmentSyntax = "hlsl2glsl";
                }
                else
                {
                    vertexSyntax   = "arbvp1";
                    fragmentSyntax = "arbfp1";
                }
            }

            Technique technique = BaseMaterial.CreateTechnique();

            Pass pass = technique.CreatePass();

            pass.SetFogOverride(FogMode.None, new ColorValue(0, 0, 0), 0, 0, 0);

            //generate general compile arguments
            StringBuilder arguments = new StringBuilder(256);

            {
                if (RenderSystem.Instance.IsDirect3D())
                {
                    arguments.Append(" -DDIRECT3D");
                }
                if (RenderSystem.Instance.IsOpenGL())
                {
                    arguments.Append(" -DOPENGL");
                }
                if (RenderSystem.Instance.IsOpenGLES())
                {
                    arguments.Append(" -DOPENGL_ES");
                }

                arguments.AppendFormat(" -DLIGHTTYPE_{0}", lightType.ToString().ToUpper());

                if (lightType == RenderLightType.Directional || lightType == RenderLightType.Spot)
                {
                    if (atiHardwareShadows)
                    {
                        arguments.Append(" -DATI_HARDWARE_SHADOWS");
                    }
                    if (nvidiaHardwareShadows)
                    {
                        arguments.Append(" -DNVIDIA_HARDWARE_SHADOWS");
                    }
                }

                //hardware instancing
                if (RenderSystem.Instance.HasShaderModel3() &&
                    RenderSystem.Instance.Capabilities.HardwareInstancing)
                {
                    pass.SupportHardwareInstancing = true;
                    arguments.Append(" -DINSTANCING");
                }
            }

            //generate programs
            {
                string error;

                //vertex program
                GpuProgram vertexProgram = GpuProgramCacheManager.Instance.AddProgram(
                    "DefaultShadowCaster_Vertex_", GpuProgramType.Vertex, sourceFile,
                    "main_vp", vertexSyntax, arguments.ToString(), out error);
                if (vertexProgram == null)
                {
                    string err = "File:" + sourceFile; //Incin
                    err += " Type Error: DefaultShadowCaster_Vertex_: Arguments: " + arguments.ToString();
                    err += " Error : " + error;
                    Log.Fatal(err);
                    return(false);
                }

                SetProgramAutoConstants(vertexProgram.DefaultParameters);
                pass.VertexProgramName = vertexProgram.Name;

                //fragment program
                GpuProgram fragmentProgram = GpuProgramCacheManager.Instance.AddProgram(
                    "DefaultShadowCaster_Fragment_", GpuProgramType.Fragment, sourceFile,
                    "main_fp", fragmentSyntax, arguments.ToString(), out error);
                if (fragmentProgram == null)
                {
                    string err = "File:" + sourceFile; //Incin
                    err += " Type Error: DefaultShadowCaster_Fragment_ Arguments: " + arguments.ToString();
                    err += " Error : " + error;
                    Log.Fatal(err);
                    return(false);
                }

                SetProgramAutoConstants(fragmentProgram.DefaultParameters);
                pass.FragmentProgramName = fragmentProgram.Name;
            }

            return(true);
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        protected void Initialize()
        {
            // Create geometry
            int nvertices = this.slices * 4;           // n+1 planes
            int elemsize  = 3 * 3;
            int dsize     = elemsize * nvertices;
            int x;

            var indexData  = new IndexData();
            var vertexData = new VertexData();
            var vertices   = new float[dsize];

            var coords = new float[4, 2]
            {
                {
                    0.0f, 0.0f
                }, {
                    0.0f, 1.0f
                }, {
                    1.0f, 0.0f
                }, {
                    1.0f, 1.0f
                }
            };

            for (x = 0; x < this.slices; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    float xcoord = coords[y, 0] - 0.5f;
                    float ycoord = coords[y, 1] - 0.5f;
                    float zcoord = -((float)x / (float)(this.slices - 1) - 0.5f);
                    // 1.0f .. a/(a+1)
                    // coordinate
                    vertices[x * 4 * elemsize + y * elemsize + 0] = xcoord * (this.size / 2.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 1] = ycoord * (this.size / 2.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 2] = zcoord * (this.size / 2.0f);
                    // normal
                    vertices[x * 4 * elemsize + y * elemsize + 3] = 0.0f;
                    vertices[x * 4 * elemsize + y * elemsize + 4] = 0.0f;
                    vertices[x * 4 * elemsize + y * elemsize + 5] = 1.0f;
                    // tex
                    vertices[x * 4 * elemsize + y * elemsize + 6] = xcoord * Utility.Sqrt(3.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 7] = ycoord * Utility.Sqrt(3.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 8] = zcoord * Utility.Sqrt(3.0f);
                }
            }

            var faces = new short[this.slices * 6];

            for (x = 0; x < this.slices; x++)
            {
                faces[x * 6 + 0] = (short)(x * 4 + 0);
                faces[x * 6 + 1] = (short)(x * 4 + 1);
                faces[x * 6 + 2] = (short)(x * 4 + 2);
                faces[x * 6 + 3] = (short)(x * 4 + 1);
                faces[x * 6 + 4] = (short)(x * 4 + 2);
                faces[x * 6 + 5] = (short)(x * 4 + 3);
            }

            //setup buffers
            vertexData.vertexStart = 0;
            vertexData.vertexCount = nvertices;

            VertexDeclaration   decl = vertexData.vertexDeclaration;
            VertexBufferBinding bind = vertexData.vertexBufferBinding;
            int offset = 0;

            offset += decl.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position).Size;
            offset += decl.AddElement(0, offset, VertexElementType.Float3, VertexElementSemantic.Normal).Size;
            offset += decl.AddElement(0, offset, VertexElementType.Float3, VertexElementSemantic.TexCoords).Size;

            HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer(decl, nvertices,
                                                                                                  BufferUsage.StaticWriteOnly);

            bind.SetBinding(0, vertexBuffer);

            HardwareIndexBuffer indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer(IndexType.Size16, this.slices * 6,
                                                                                               BufferUsage.StaticWriteOnly);

            indexData.indexBuffer = indexBuffer;
            indexData.indexCount  = this.slices * 6;
            indexData.indexStart  = 0;

            indexBuffer.WriteData(0, indexBuffer.Size, faces, true);
            vertexBuffer.WriteData(0, vertexBuffer.Size, vertices);
            vertices = null;
            faces    = null;

            // Now make the render operation
            renderOperation.operationType = OperationType.TriangleList;
            renderOperation.indexData     = indexData;
            renderOperation.vertexData    = vertexData;
            renderOperation.useIndices    = true;

            // Create a brand new private material
            if (!ResourceGroupManager.Instance.GetResourceGroups().Contains("VolumeRendable"))
            {
                ResourceGroupManager.Instance.CreateResourceGroup("VolumeRendable");
            }

            var material = (Material)MaterialManager.Instance.Create(this.texture, "VolumeRendable");

            // Remove pre-created technique from defaults
            material.RemoveAllTechniques();

            // Create a techinique and a pass and a texture unit
            Technique        technique   = material.CreateTechnique();
            Pass             pass        = technique.CreatePass();
            TextureUnitState textureUnit = pass.CreateTextureUnitState();

            // Set pass parameters
            pass.SetSceneBlending(SceneBlendType.TransparentAlpha);
            pass.DepthWrite      = false;
            pass.CullingMode     = CullingMode.None;
            pass.LightingEnabled = false;
            textureUnit.SetTextureAddressingMode(TextureAddressing.Clamp);
            textureUnit.SetTextureName(this.texture, TextureType.ThreeD);
            textureUnit.SetTextureFiltering(TextureFiltering.Trilinear);

            this.unit     = textureUnit;
            base.material = material;
        }