コード例 #1
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();
        }
コード例 #2
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;
                }
            }
        }
コード例 #3
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;
        }
コード例 #4
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);
        }
コード例 #5
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();
        }
コード例 #6
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;
        }
コード例 #7
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();
            }
        }
コード例 #8
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();
        }
コード例 #9
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 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:

                throw new Exception("Caso no contemplado para BumpMapping");

            case MeshRenderType.DIFFUSE_MAP:

                //Iniciar Shader e iterar sobre sus Render Passes
                for (int n = 0; n < numPasses; 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, "texDiffuseMap", diffuseMaps[i]);

                        //Setear normalMap en shader
                        texturesManager.shaderSet(effect, "texNormalMap", normalMaps[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 para BumpMappingo");
            }

            //Finalizar shader
            effect.End();

            //Activar AlphaBlending
            resetAlphaBlend();
        }
コード例 #10
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();
        }
コード例 #11
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;
        }