コード例 #1
0
        /// <summary>
        /// Renderizar la línea
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            texturesManager.clear(1);

            GuiController.Instance.Shaders.setShaderMatrixIdentity(this.effect);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColored;
            effect.Technique            = this.technique;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);
            effect.EndPass();
            effect.End();
        }
コード例 #2
0
        /// <summary>
        /// Dibujar batch de triangulos hasta donde se haya cargado
        /// </summary>
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            texturesManager.clear(1);

            Effect effect = GuiController.Instance.Shaders.VariosShader;

            GuiController.Instance.Shaders.setShaderMatrixIdentity(effect);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColored;
            effect.Technique            = TgcShaders.T_POSITION_COLORED;

            //Alpha blend on
            d3dDevice.RenderState.AlphaTestEnable  = true;
            d3dDevice.RenderState.AlphaBlendEnable = true;

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, idx / 3, vertices);
            effect.EndPass();
            effect.End();

            //Alpha blend off
            d3dDevice.RenderState.AlphaTestEnable  = false;
            d3dDevice.RenderState.AlphaBlendEnable = false;
        }
コード例 #3
0
        /// <summary>
        /// Renderizar BoundingBox
        /// </summary>
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            texturesManager.clear(1);

            //Cargar shader si es la primera vez
            if (this.effect == null)
            {
                this.effect    = GuiController.Instance.Shaders.VariosShader;
                this.technique = TgcShaders.T_POSITION_COLORED;
            }

            //Actualizar vertices de BoundingBox solo si hubo una modificación
            if (dirtyValues)
            {
                updateValues();
                dirtyValues = false;
            }

            GuiController.Instance.Shaders.setShaderMatrixIdentity(this.effect);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColored;
            effect.Technique            = this.technique;

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
            effect.EndPass();
            effect.End();
        }
コード例 #4
0
        /// <summary>
        /// Dibujar mesh debug del Frustum.
        /// Antes se debe llamar a updateMesh()
        /// Setear el effect para el shader antes
        /// </summary>
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;
            texturesManager.clear(0);
            texturesManager.clear(1);

            //Cargar shader si es la primera vez
            if (this.effect == null)
            {
                this.effect    = GuiController.Instance.Shaders.VariosShader;
                this.technique = TgcShaders.T_POSITION_COLORED_ALPHA;
            }

            GuiController.Instance.Shaders.setShaderMatrixIdentity(this.effect);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColored;
            effect.Technique            = this.technique;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);

            //transparencia
            effect.SetValue("alphaValue", alphaBlendingValue);
            d3dDevice.RenderState.AlphaTestEnable  = true;
            d3dDevice.RenderState.AlphaBlendEnable = true;

            //Draw shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);
            effect.EndPass();
            effect.End();

            d3dDevice.RenderState.AlphaTestEnable  = false;
            d3dDevice.RenderState.AlphaBlendEnable = false;
        }
コード例 #5
0
        /// <summary>
        /// Renderiza la malla, si esta habilitada.
        /// Para que haya animacion se tiene que haber seteado una y haber
        /// llamado previamente al metodo updateAnimation()
        /// Sino se renderiza la pose fija de la malla
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device device = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Aplicar transformaciones
            updateMeshTransform();

            //Cargar VertexDeclaration
            device.VertexDeclaration = vertexDeclaration;

            //Activar AlphaBlending si corresponde
            activateAlphaBlend();


            //Renderizar segun el tipo de render de la malla
            switch (renderType)
            {
            case MeshRenderType.VERTEX_COLOR:

                //Hacer reset de texturas y materiales
                texturesManager.clear(0);
                texturesManager.clear(1);
                device.Material = TgcD3dDevice.DEFAULT_MATERIAL;

                //Dibujar mesh
                d3dMesh.DrawSubset(0);
                break;

            case MeshRenderType.DIFFUSE_MAP:

                //Hacer reset de Lightmap
                texturesManager.clear(1);

                //Dibujar cada subset con su Material y DiffuseMap correspondiente
                for (int i = 0; i < materials.Length; i++)
                {
                    device.Material = materials[i];
                    texturesManager.set(0, diffuseMaps[i]);
                    d3dMesh.DrawSubset(i);
                }
                break;
            }

            //Desactivar alphaBlend
            resetAlphaBlend();
        }
コード例 #6
0
        /// <summary>
        /// Dibujar recuadro
        /// </summary>
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            texturesManager.clear(1);
            d3dDevice.Material        = TgcD3dDevice.DEFAULT_MATERIAL;
            d3dDevice.Transform.World = Matrix.Identity;

            d3dDevice.VertexFormat = CustomVertex.TransformedColored.Format;
            d3dDevice.DrawUserPrimitives(PrimitiveType.LineList, 4, vertices);
        }
コード例 #7
0
        /// <summary>
        /// Renderizar la caja
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //transformacion
            if (autoTransformEnable)
            {
                this.transform = Matrix.Scaling(scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }

            //Activar AlphaBlending
            activateAlphaBlend();

            //renderizar
            if (texture != null)
            {
                texturesManager.shaderSet(effect, "texDiffuseMap", texture);
            }
            else
            {
                texturesManager.clear(0);
            }

            texturesManager.clear(1);

            GuiController.Instance.Shaders.setShaderMatrix(this.effect, this.transform);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionTextured;
            effect.Technique            = this.technique;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);


            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 32);
            effect.EndPass();
            effect.End();

            //Desactivar AlphaBlend
            resetAlphaBlend();
        }
コード例 #8
0
        public void Render()
        {
            if (!Enabled)
            {
                return;
            }
            if (_OldValues)
            {
                _UpdateValues();
                _OldValues = false;
            }
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;
            _SetAlphaBlend(IsAlphaBlendEnabled);
            texturesManager.shaderSet(Shader, "texDiffuseMap", _Texture);
            texturesManager.clear(1);
            GuiController.Instance.Shaders.setShaderMatrixIdentity(this.Shader);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionTextured;
            Shader.Technique            = Technique;
            //Render con shader
            Shader.Begin(0);
            Shader.BeginPass(0);
            d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, _Vertices);
            Shader.EndPass();
            Shader.End();
            _SetAlphaBlend(false);
        }
コード例 #9
0
        /// <summary>
        /// Renderiza el terreno
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Textura
            effect.SetValue("texDiffuseMap", terrainTexture);
            texturesManager.clear(1);

            GuiController.Instance.Shaders.setShaderMatrix(this.effect, Matrix.Identity);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionTextured;
            effect.Technique            = this.technique;
            d3dDevice.SetStreamSource(0, vbTerrain, 0);

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, totalVertices / 3);
            effect.EndPass();
            effect.End();
        }
コード例 #10
0
ファイル: QuadConTextura.cs プロジェクト: JuanchiRios/TGC
        /// <summary>
        /// Renderizar la pared
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            activateAlphaBlend();

            texturesManager.shaderSet(effect, "texDiffuseMap", texture);
            texturesManager.clear(1);
            GuiController.Instance.Shaders.setShaderMatrixIdentity(this.effect);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionTextured;
            effect.Technique            = this.technique;

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertices);
            effect.EndPass();
            effect.End();

            resetAlphaBlend();
        }
コード例 #11
0
        public void renderPasto(float tLeftMoved, float tRightMoved, int parte)
        {
            if ((CustomFpsCamera.Instance.eye - partePasto[parte].Origin).Length() < CustomFpsCamera.FAR_PLANE / 4.5)
            {
                TgcCollisionUtils.FrustumResult result = TgcCollisionUtils.classifyFrustumAABB(GuiController.Instance.Frustum, partePasto[parte].BoundingBox);
                if (result != TgcCollisionUtils.FrustumResult.OUTSIDE)
                {
                    Device             d3dDevice       = GuiController.Instance.D3dDevice;
                    TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

                    d3dDevice.RenderState.AlphaTestEnable  = true;
                    d3dDevice.RenderState.AlphaBlendEnable = true;

                    TgcPlaneWall pastoWall = partePasto[parte];
                    texturesManager.shaderSet(pastoWall.Effect, "texDiffuseMap", pastoWall.Texture);
                    texturesManager.clear(1);
                    GuiController.Instance.Shaders.setShaderMatrixIdentity(pastoWall.Effect);
                    d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionTextured;
                    pastoWall.Effect.Technique  = pastoWall.Technique;

                    //Render con shader
                    pastoWall.Effect.Begin(0);
                    pastoWall.Effect.BeginPass(0);

                    d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, actualizarPasto(tLeftMoved, tRightMoved, parte, pastoWall));

                    pastoWall.Effect.EndPass();
                    pastoWall.Effect.End();

                    d3dDevice.RenderState.AlphaTestEnable  = false;
                    d3dDevice.RenderState.AlphaBlendEnable = false;
                }
            }
        }
コード例 #12
0
ファイル: SmartTerrain.cs プロジェクト: nicoschtein/TGC2014
        /// <summary>
        /// Renderiza el terreno
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;
            Matrix             transform       = Matrix.Translation(traslation) * Matrix.Scaling(ScaleXZ, ScaleY, ScaleXZ);

            //Textura
            effect.SetValue("texDiffuseMap", terrainTexture);


            texturesManager.clear(1);

            GuiController.Instance.Shaders.setShaderMatrix(this.effect, transform);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColoredTextured;
            effect.Technique            = this.technique;
            d3dDevice.SetStreamSource(0, vbTerrain, 0);

            //Render con shader
            int p = effect.Begin(0);

            for (int i = 0; i < p; i++)
            {
                effect.BeginPass(i);
                d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, totalVertices / 3);
                effect.EndPass();
            }
            effect.End();
        }
コード例 #13
0
        public void renderFlash()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            animateTexture();
            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            d3dDevice.RenderState.AlphaTestEnable  = true;
            d3dDevice.RenderState.AlphaBlendEnable = true;

            texturesManager.shaderSet(muzzleFlash.Effect, "texDiffuseMap", muzzleFlash.Texture);
            texturesManager.clear(1);
            GuiController.Instance.Shaders.setShaderMatrixIdentity(muzzleFlash.Effect);
            d3dDevice.VertexDeclaration  = GuiController.Instance.Shaders.VdecPositionTextured;
            muzzleFlash.Effect.Technique = muzzleFlash.Technique;

            //Render con shader
            muzzleFlash.Effect.Begin(0);
            muzzleFlash.Effect.BeginPass(0);

            d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, actualizarFlash());

            muzzleFlash.Effect.EndPass();
            muzzleFlash.Effect.End();

            d3dDevice.RenderState.AlphaTestEnable  = false;
            d3dDevice.RenderState.AlphaBlendEnable = false;
        }
コード例 #14
0
        /// <summary>
        /// Renderizar ejes segun posicion actual de la camara
        /// </summary>
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Obtener World coordinate de la esquina inferior de la pantalla
            int   w  = d3dDevice.Viewport.Width;
            int   h  = d3dDevice.Viewport.Height;
            float sx = AXIS_POS_OFFSET;
            float sy = h - AXIS_POS_OFFSET;

            Matrix  matProj = d3dDevice.Transform.Projection;
            Vector3 v       = new Vector3();

            v.X = (((2.0f * sx) / w) - 1) / matProj.M11;
            v.Y = -(((2.0f * sy) / h) - 1) / matProj.M22;
            v.Z = 1.0f;

            //Transform the screen space into 3D space
            Matrix  m      = Matrix.Invert(d3dDevice.Transform.View);
            Vector3 rayDir = new Vector3(
                v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31,
                v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32,
                v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33
                );
            Vector3 rayOrig       = new Vector3(m.M41, m.M42, m.M43);
            Vector3 worldCoordPos = rayOrig + AXIS_POS_DISTANCE * rayDir;


            //Renderizar
            texturesManager.clear(0);
            texturesManager.clear(1);
            d3dDevice.Material        = TgcD3dDevice.DEFAULT_MATERIAL;
            d3dDevice.Transform.World = Matrix.Translation(worldCoordPos);

            d3dDevice.VertexFormat = CustomVertex.PositionColored.Format;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);
            d3dDevice.DrawPrimitives(PrimitiveType.LineList, 0, 3);

            d3dDevice.Transform.World = Matrix.Identity;
        }
コード例 #15
0
        /// <summary>
        /// Renderizar la caja
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //transformacion
            if (autoTransformEnable)
            {
                this.transform = Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }
            d3dDevice.Transform.World = this.transform;

            //Activar AlphaBlending
            activateAlphaBlend();

            //renderizar
            if (texture != null)
            {
                texturesManager.set(0, texture);
            }
            else
            {
                texturesManager.clear(0);
            }

            texturesManager.clear(1);
            d3dDevice.Material = TgcD3dDevice.DEFAULT_MATERIAL;

            d3dDevice.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);

            //Desactivar AlphaBlend
            resetAlphaBlend();
        }
コード例 #16
0
        /// <summary>
        /// Renderizar el BoundingSphere
        /// </summary>
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            texturesManager.clear(1);
            d3dDevice.Material        = TgcD3dDevice.DEFAULT_MATERIAL;
            d3dDevice.Transform.World = Matrix.Identity;

            //Actualizar vertices de BoundingSphere solo si hubo una modificación
            if (dirtyValues)
            {
                updateValues();
                dirtyValues = false;
            }

            d3dDevice.VertexFormat = CustomVertex.PositionColored.Format;
            d3dDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices.Length / 2, vertices);
        }
コード例 #17
0
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            texturesManager.clear(1);

            Effect effect = GuiController.Instance.Shaders.VariosShader;

            effect.Technique = TgcShaders.T_POSITION_COLORED;
            GuiController.Instance.Shaders.setShaderMatrixIdentity(effect);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColored;

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawUserPrimitives(PrimitiveType.LineList, 22, vertices);
            effect.EndPass();
            effect.End();
        }
コード例 #18
0
        public void render()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            if (this.AlphaBlendEnable)
            {
                d3dDevice.RenderState.AlphaBlendEnable = true;
                d3dDevice.RenderState.AlphaTestEnable  = true;
            }

            if (texture != null)
            {
                texturesManager.shaderSet(effect, "texDiffuseMap", texture);
            }
            else
            {
                texturesManager.clear(0);
            }
            texturesManager.clear(1);

            GuiController.Instance.Shaders.setShaderMatrix(this.effect, this.Transform);
            d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionColoredTextured;
            effect.Technique            = this.technique;

            int capsResolution = END_CAPS_RESOLUTION;

            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2 * capsResolution, this.sideTrianglesVertices);
            effect.EndPass();
            effect.End();

            d3dDevice.RenderState.AlphaTestEnable  = false;
            d3dDevice.RenderState.AlphaBlendEnable = false;
        }
コード例 #19
0
        /// <summary>
        /// Renderizar la caja
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            texturesManager.clear(0);
            d3dDevice.Material        = TgcD3dDevice.DEFAULT_MATERIAL;
            d3dDevice.Transform.World = Matrix.Identity;

            d3dDevice.VertexFormat = CustomVertex.PositionColored.Format;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, TRIANGLES_COUNT);
        }
コード例 #20
0
        /// <summary>
        /// Renderizar la pared
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            activateAlphaBlend();

            texturesManager.set(0, texture);
            texturesManager.clear(1);
            d3dDevice.Material        = TgcD3dDevice.DEFAULT_MATERIAL;
            d3dDevice.Transform.World = Matrix.Identity;

            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertices);

            resetAlphaBlend();
        }
コード例 #21
0
        /// <summary>
        /// Renderiza la malla, si esta habilitada.
        /// Para que haya animacion se tiene que haber seteado una y haber
        /// llamado previamente al metodo updateAnimation()
        /// Sino se renderiza la pose fija de la malla
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device device = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Aplicar transformaciones
            updateMeshTransform();

            //Cargar VertexDeclaration
            device.VertexDeclaration = vertexDeclaration;

            //Activar AlphaBlending si corresponde
            activateAlphaBlend();

            //Cargar matrices para el shader
            setShaderMatrix();

            //Renderizar segun el tipo de render de la malla
            effect.Technique = this.technique;
            int numPasses = effect.Begin(0);

            switch (renderType)
            {
            case MeshRenderType.VERTEX_COLOR:

                //Hacer reset de texturas
                texturesManager.clear(0);
                texturesManager.clear(1);

                //Iniciar Shader e iterar sobre sus Render Passes
                for (int n = 0; n < numPasses; n++)
                {
                    //Iniciar pasada de shader
                    effect.BeginPass(n);
                    d3dMesh.DrawSubset(0);
                    effect.EndPass();
                }
                break;

            case MeshRenderType.DIFFUSE_MAP:

                //Hacer reset de Lightmap
                texturesManager.clear(1);

                //Iniciar Shader e iterar sobre sus Render Passes
                for (int n = 0; n < numPasses; n++)
                {
                    //Dibujar cada subset con su DiffuseMap correspondiente
                    for (int i = 0; i < materials.Length; i++)
                    {
                        //Setear textura en shader
                        texturesManager.shaderSet(effect, "texDiffuseMap", diffuseMaps[i]);

                        //Iniciar pasada de shader
                        effect.BeginPass(n);
                        d3dMesh.DrawSubset(i);
                        effect.EndPass();
                    }
                }
                break;
            }

            //Finalizar shader
            effect.End();

            //Desactivar alphaBlend
            resetAlphaBlend();
        }
コード例 #22
0
        /// <summary>
        /// Se redefine este método para agregar shaders.
        /// Es el mismo código del executeRender() pero con la sección de "MeshRenderType.DIFFUSE_MAP" ampliada
        /// para Shaders.
        /// </summary>
        public new void executeRender()
        {
            Device device = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Aplicar transformacion de malla
            if (autoTransformEnable)
            {
                this.transform = Matrix.Identity
                                 * Matrix.Scaling(scale)
                                 * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z)
                                 * Matrix.Translation(translation);
            }
            //estas son las matrices comunes q tienen todos los shaders que hicimos, y q tienen que ser actualizadas
            device.Transform.World = this.transform;
            effect.SetValue("xWorld", device.Transform.World);
            effect.SetValue("xWorldViewProj", device.Transform.World * device.Transform.View * device.Transform.Projection);
            effect.CommitChanges();

            //Cargar VertexDeclaration
            device.VertexDeclaration = vertexDeclaration;


            //Renderizar segun el tipo de render de la malla
            switch (renderType)
            {
            case MeshRenderType.VERTEX_COLOR:

                //Hacer reset de texturas y materiales
                texturesManager.clear(0);
                texturesManager.clear(1);
                device.Material = TgcD3dDevice.DEFAULT_MATERIAL;

                int numPasses = effect.Begin(0);
                for (int n = 0; n < numPasses; n++)
                {
                    //Iniciar pasada de shader
                    effect.BeginPass(n);
                    //Dibujar mesh
                    d3dMesh.DrawSubset(0);
                    effect.EndPass();
                }
                //Finalizar shader
                effect.End();
                break;

            case MeshRenderType.DIFFUSE_MAP:

                //Hacer reset de Lightmap
                texturesManager.clear(1);

                //Iniciar Shader e iterar sobre sus Render Passes
                int numPasses2 = effect.Begin(0);
                for (int n = 0; n < numPasses2; n++)
                {
                    //Iniciar pasada de shader
                    effect.BeginPass(n);

                    //Dibujar cada subset con su Material y DiffuseMap correspondiente
                    for (int i = 0; i < materials.Length; i++)
                    {
                        device.Material = materials[i];
                        texturesManager.set(0, diffuseMaps[i]);
                        d3dMesh.DrawSubset(i);
                    }
                    //Finalizar pasada
                    effect.EndPass();
                }
                //Finalizar shader
                effect.End();

                break;

            case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP:

                break;
            }
        }
コード例 #23
0
        /// <summary>
        /// Renderizar la esfera
        /// </summary>
        public virtual void render()
        {
            if (!enabled)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //transformacion
            if (autoTransformEnable)
            {
                this.transform = Matrix.Scaling(radius, radius, radius) * Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }

            //Activar AlphaBlending
            activateAlphaBlend();


            //renderizar
            if (texture != null)
            {
                texturesManager.shaderSet(effect, "texDiffuseMap", texture);
            }

            else
            {
                texturesManager.clear(0);
            }

            texturesManager.clear(1);


            GuiController.Instance.Shaders.setShaderMatrix(this.effect, this.transform);
            effect.Technique = this.technique;

            d3dDevice.VertexDeclaration = Vertex.PositionColoredTexturedNormal_Declaration;
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);
            IndexBuffer oldIndex = d3dDevice.Indices;

            d3dDevice.Indices = indexBuffer;

            //Render con shader
            renderWithFill(d3dDevice.RenderState.FillMode);

            if (RenderEdges)
            {
                if (texture == null)
                {
                    effect.Technique = TgcShaders.T_POSITION_TEXTURED;
                }
                else
                {
                    effect.Technique = TgcShaders.T_POSITION_COLORED;
                }

                renderWithFill(FillMode.WireFrame);
            }

            //Desactivar AlphaBlend
            resetAlphaBlend();

            d3dDevice.Indices = oldIndex;
        }
コード例 #24
0
        /// <summary>
        /// Renderiza la malla, si esta habilitada.
        /// Para que haya animacion se tiene que haber seteado una y haber
        /// llamado previamente al metodo updateAnimation()
        /// Sino se renderiza la pose fija de la malla
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            Device device = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Actualizar transformacion de malla
            updateMeshTransform();

            //Cargar VertexDeclaration
            device.VertexDeclaration = vertexDeclaration;

            //Activar AlphaBlending si corresponde
            activateAlphaBlend();

            //Cargar matrices para el shader
            setShaderMatrix();

            //Enviar al shader el array de matrices de huesos para poder hacer skinning en el Vertex Shader
            effect.SetValue("bonesMatWorldArray", this.boneSpaceFinalTransforms);

            //Renderizar malla
            if (!renderSkeleton)
            {
                //Renderizar segun el tipo de render de la malla
                effect.Technique = this.technique;
                int numPasses = effect.Begin(0);
                switch (renderType)
                {
                case MeshRenderType.VERTEX_COLOR:

                    //Hacer reset de texturas
                    texturesManager.clear(0);
                    texturesManager.clear(1);

                    //Iniciar Shader e iterar sobre sus Render Passes
                    for (int n = 0; n < numPasses; n++)
                    {
                        //Iniciar pasada de shader
                        effect.BeginPass(n);
                        d3dMesh.DrawSubset(0);
                        effect.EndPass();
                    }
                    break;

                case MeshRenderType.DIFFUSE_MAP:

                    //Hacer reset de Lightmap
                    texturesManager.clear(1);

                    //Iniciar Shader e iterar sobre sus Render Passes
                    for (int n = 0; n < numPasses; n++)
                    {
                        //Dibujar cada subset con su DiffuseMap correspondiente
                        for (int i = 0; i < materials.Length; i++)
                        {
                            //Setear textura en shader
                            texturesManager.shaderSet(effect, "texDiffuseMap", diffuseMaps[i]);

                            //Iniciar pasada de shader
                            effect.BeginPass(n);
                            d3dMesh.DrawSubset(i);
                            effect.EndPass();
                        }
                    }
                    break;
                }

                //Finalizar shader
                effect.End();
            }
            //Renderizar esqueleto
            else
            {
                this.renderSkeletonMesh();
            }

            //Desactivar alphaBlend
            resetAlphaBlend();


            //Renderizar attachments
            foreach (TgcSkeletalBoneAttach attach in attachments)
            {
                attach.updateMeshTransform(this.transform);
                attach.Mesh.render();
            }
        }
コード例 #25
0
        /// <summary>
        /// Se redefine este método para agregar shaders.
        /// Es el mismo código del render() pero con la sección de "MeshRenderType.DIFFUSE_MAP" ampliada
        /// para Shaders.
        /// </summary>
        public new void render()
        {
            if (!enabled)
            {
                return;
            }

            Device device = GuiController.Instance.D3dDevice;

            TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

            //Aplicar transformacion de malla
            updateMeshTransform();

            //Cargar VertexDeclaration
            device.VertexDeclaration = vertexDeclaration;

            //Activar AlphaBlending
            activateAlphaBlend();

            //Cargar valores de shader de matrices que dependen de la posición del mesh
            Matrix matWorldView     = this.transform * device.Transform.View;
            Matrix matWorldViewProj = matWorldView * device.Transform.Projection;

            effect.SetValue("matWorld", this.transform);
            effect.SetValue("matWorldView", matWorldView);
            effect.SetValue("matWorldViewProj", matWorldViewProj);

            //Renderizar segun el tipo de render de la malla
            int numPasses;

            switch (renderType)
            {
            case MeshRenderType.VERTEX_COLOR:

                //Hacer reset de texturas
                texturesManager.clear(0);
                texturesManager.clear(1);
                device.Material = TgcD3dDevice.DEFAULT_MATERIAL;

                //Llamar evento para configurar inicio del shader
                if (ShaderBegin != null)
                {
                    ShaderBegin.Invoke(this);
                }

                //Iniciar Shader e iterar sobre sus Render Passes
                numPasses = effect.Begin(0);
                for (int n = 0; n < numPasses; n++)
                {
                    //Llamar evento para configurar inicio de la pasada del shader
                    if (ShaderPassBegin != null)
                    {
                        ShaderPassBegin.Invoke(this, n);
                    }

                    //Iniciar pasada de shader
                    effect.BeginPass(n);
                    d3dMesh.DrawSubset(0);
                    effect.EndPass();
                }

                //Finalizar shader
                effect.End();

                break;

            case MeshRenderType.DIFFUSE_MAP:

                //Hacer reset de Lightmap
                texturesManager.clear(1);

                //Llamar evento para configurar inicio del shader
                if (ShaderBegin != null)
                {
                    ShaderBegin.Invoke(this);
                }

                //Iniciar Shader e iterar sobre sus Render Passes
                numPasses = effect.Begin(0);
                for (int n = 0; n < numPasses; n++)
                {
                    //Llamar evento para configurar inicio de la pasada del shader
                    if (ShaderPassBegin != null)
                    {
                        ShaderPassBegin.Invoke(this, n);
                    }

                    //Dibujar cada subset con su Material y DiffuseMap correspondiente
                    for (int i = 0; i < materials.Length; i++)
                    {
                        device.Material = materials[i];

                        //Setear textura en shader
                        texturesManager.shaderSet(effect, "diffuseMap_Tex", diffuseMaps[i]);

                        //Iniciar pasada de shader
                        // guarda: Todos los SetValue tienen que ir ANTES del beginPass.
                        // si no hay que llamar effect.CommitChanges para que tome el dato!
                        effect.BeginPass(n);
                        d3dMesh.DrawSubset(i);
                        effect.EndPass();
                    }
                }

                //Finalizar shader
                effect.End();

                break;

            case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP:

                throw new Exception("Caso no contemplado en este ejemplo");
            }


            //Activar AlphaBlending
            resetAlphaBlend();
        }
コード例 #26
0
        /// <summary>
        /// Dibujar particulas.
        /// Emite particulas a medida que avanza el tiempo.
        /// </summary>
        public void render()
        {
            if (!enabled)
            {
                return;
            }

            //Ver si hay que generar nuevas particulas
            float elapsedTime = GuiController.Instance.ElapsedTime;

            tiempoAcumulado += elapsedTime;
            if (tiempoAcumulado >= this.creationFrecuency && playing)
            {
                tiempoAcumulado = 0.0f;

                //Inicializa y agrega una particula a la lista de particulas vivas.
                this.createParticle();
            }

            //Dibujar particulas existentes
            if (this.particlesAlive.Count > 0)
            {
                Device             device          = GuiController.Instance.D3dDevice;
                TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager;

                //Cargar VertexDeclaration
                device.VertexDeclaration = vertexDeclaration;

                //Fijo la textura actual de la particula.
                texturesManager.clear(0);
                texturesManager.clear(1);
                texturesManager.set(0, texture);
                device.Material = TgcD3dDevice.DEFAULT_MATERIAL;
                device.RenderState.AlphaBlendEnable   = true;
                device.RenderState.ZBufferWriteEnable = false;
                device.Transform.World = Matrix.Identity;

                // Va recorriendo la lista de particulas vivas,
                // actualizando el tiempo de vida restante, y dibujando.
                Particle p = this.particlesAlive.peek();
                while (p != null)
                {
                    p.TimeToLive -= elapsedTime;

                    if (p.TimeToLive <= 0)
                    {
                        //Saco la particula de la lista de particulas vivas.
                        this.particlesAlive.dequeue(out p);

                        //Inserto la particula en la lista de particulas muertas.
                        this.particlesDead.Push(p);
                    }
                    else
                    {
                        //Actualizo y Dibujo la partícula
                        this.updateExistingParticle(elapsedTime, p);
                        this.renderParticle(p);
                    }

                    p = this.particlesAlive.peekNext();
                }

                //Restaurar valores de RenderState
                device.RenderState.AlphaBlendEnable   = false;
                device.RenderState.ZBufferWriteEnable = true;
            }
        }