Exemplo n.º 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();
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
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.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();
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        /// <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();
        }
Exemplo n.º 10
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;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Crea todos los modulos necesarios de la aplicacion
        /// </summary>
        internal void initGraphics(MainForm mainForm, Control panel3d)
        {
            this.mainForm        = mainForm;
            this.panel3d         = panel3d;
            this.fullScreenPanel = new FullScreenPanel();
            panel3d.Focus();

            //Iniciar graficos
            this.tgcD3dDevice    = new TgcD3dDevice(panel3d);
            this.texturesManager = new TgcTexture.Manager();
            this.tgcD3dDevice.OnResetDevice(tgcD3dDevice.D3dDevice, null);

            //Iniciar otras herramientas
            this.texturesPool      = new TgcTexture.Pool();
            this.logger            = new Logger(mainForm.LogConsole);
            this.text3d            = new TgcDrawText(tgcD3dDevice.D3dDevice);
            this.tgcD3dInput       = new TgcD3dInput(mainForm, panel3d);
            this.fpsCamera         = new TgcFpsCamera();
            this.rotCamera         = new TgcRotationalCamera();
            this.thirdPersonCamera = new TgcThirdPersonCamera();
            this.axisLines         = new TgcAxisLines(tgcD3dDevice.D3dDevice);
            this.userVars          = new TgcUserVars(mainForm.getDataGridUserVars());
            this.modifiers         = new TgcModifiers(mainForm.getModifiersPanel());
            this.elapsedTime       = -1;
            this.frustum           = new TgcFrustum();
            this.mp3Player         = new TgcMp3Player();
            this.directSound       = new TgcDirectSound();
            this.fog                 = new TgcFog();
            this.currentCamera       = this.rotCamera;
            this.customRenderEnabled = false;
            this.drawer2D            = new TgcDrawer2D();
            this.shaders             = new TgcShaders();

            //toogles
            this.rotCamera.Enable         = true;
            this.fpsCamera.Enable         = false;
            this.thirdPersonCamera.Enable = false;
            this.fpsCounterEnable         = true;
            this.axisLines.Enable         = true;

            //Cargar algoritmos
            exampleLoader          = new ExampleLoader();
            examplesDir            = System.Environment.CurrentDirectory + "\\" + ExampleLoader.EXAMPLES_DIR + "\\";
            examplesMediaDir       = examplesDir + "Media" + "\\";
            alumnoEjemplosDir      = System.Environment.CurrentDirectory + "\\" + "AlumnoEjemplos" + "\\";
            alumnoEjemplosMediaDir = alumnoEjemplosDir + "AlumnoMedia" + "\\";
            exampleLoader.loadExamplesInGui(mainForm.TreeViewExamples, new string[] { examplesDir, alumnoEjemplosDir });

            //Cargar shaders del framework
            this.shaders.loadCommonShaders();

            //Cargar ejemplo default
            TgcExample defaultExample = exampleLoader.getExampleByName(mainForm.Config.defaultExampleName, mainForm.Config.defaultExampleCategory);

            executeExample(defaultExample);
        }
        /// <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();
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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();
        }
        /// <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);
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
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();
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
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();
        }
Exemplo n.º 23
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;
            }
        }
Exemplo n.º 24
0
        /*
         * public MyMesh createMeshInstance(string name)
         * {
         *  return createMeshInstance(name, Vector3.Empty, Vector3.Empty, new Vector3(1, 1, 1));
         * }
         *
         */
        /// <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()
        {
            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);
            }
            device.Transform.World = this.transform;
            if (parentInstance != null)
            {
                effect = ((MyMesh)parentInstance).effect;
            }


            // incializacion standard para hacer la proyeccion
            effect.SetValue("matWorld", device.Transform.World);
            effect.SetValue("matWorldView", device.Transform.World * device.Transform.View);
            effect.SetValue("matWorldViewProj", device.Transform.World * device.Transform.View * device.Transform.Projection);

            // es usual en los shaders pasar directamente la matrix total de transformacion
            // matWorldViewProj = World*View*Proj
            // para hacer una sola multiplicacion.

            // Detalle para las normales
            // Transformar una normal es un poco diferente a transformar una coordenada
            // en general hay que usar la inversa transpuesta. Salvo el caso que la escala
            // sea uniforme, en ese caso es la misma matriz de transformacion.
            Matrix WorldInverse = device.Transform.World;

            WorldInverse.Invert();
            Matrix WorldInverseTranspose = Matrix.TransposeMatrix(WorldInverse);

            WorldInverseTranspose.M14 = 0;
            WorldInverseTranspose.M24 = 0;
            WorldInverseTranspose.M34 = 0;
            WorldInverseTranspose.M44 = 0;
            //effect.SetValue("matWorldInverseTranspose", WorldInverseTranspose);

            //Cargar VertexDeclaration
            device.VertexDeclaration = vertexDeclaration;
            // dibujo a traves del effect
            // itero por material, en cada material,
            // El SetTexture(0,diffuseMaps[i].D3dTexture) del fixed pipeline
            // se reemplaza por
            // effect.SetValue("base_Tex", diffuseMaps[i].D3dTexture);
            // Una tecnica esta compuesta por una o mas pasadas.
            // Esta es la estructura habitual para dibujar una primitiva mesh en un shader
            // iterar por pasasdas, y dentro de cada pasada por material.
            int numPasses = effect.Begin(0);

            for (int n = 0; n < numPasses; n++)
            {
                for (int i = 0; i < materials.Length; i++)
                {
                    // effect.SetValue("base_Tex", diffuseMaps[i].D3dTexture);
                    // 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();
                }
            }
            effect.End();
        }
Exemplo n.º 25
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();
            }
        }
Exemplo n.º 26
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();
        }
Exemplo n.º 27
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();
        }
Exemplo n.º 28
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;
        }
        /// <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;
            }
        }