Ejemplo n.º 1
0
        public void RenderOnScreen(Microsoft.DirectX.Direct3D.Device d3dDevice, float elapsedTime)
        {
            d3dDevice.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, screenQuadVB, 0);

            //Ver si el efecto de alarma esta activado, configurar Technique del shader segun corresponda

            //Cargamos parametros en el shader de Post-Procesado
            this.postProcessMerge.SetValue("escenaTextura", this.escena);
            if (cant_pasadas == 0)
            {
                this.postProcessMerge.SetValue("propulsoresTextura", this.propulsores);
            }
            else
            {
                this.postProcessMerge.SetValue("propulsoresTextura", this.propulsoresBlurAux2);
            }
            this.postProcessMerge.Technique = "TechniqueMerge";
            //Limiamos la pantalla y ejecutamos el render del shader
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            this.postProcessMerge.Begin(FX.None);
            this.postProcessMerge.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            this.postProcessMerge.EndPass();
            this.postProcessMerge.End();
            //DrawText.drawText("Desfase: " + TGCVector3.PrintVector3(desfase), 0, 500, Color.White);
            //Terminamos el renderizado de la escena
            RenderFPS();
            RenderAxis();
            d3dDevice.EndScene();
            d3dDevice.Present();
        }
Ejemplo n.º 2
0
        static public void LineTo(ref Microsoft.DirectX.Direct3D.Device device, Vector3 v1, Vector3 v2, Color color)
        {
            // Line #1

            verts[0].Position = v1;
            verts[0].Color    = color.ToArgb();
            verts[1].Position = v2;
            verts[1].Color    = color.ToArgb();
            lineList_VB.SetData(verts, 0, LockFlags.None);

            device.VertexFormat          = CustomVertex.PositionColored.Format;
            device.RenderState.Lighting  = false;
            device.RenderState.PointSize = 4.0f;
            device.SetStreamSource(0, lineList_VB, 0);
            device.DrawPrimitives(PrimitiveType.LineList, 0, 2);
            device.RenderState.Lighting = true;
        }
        public void PostRender(bool invisibilidadActivada, float Tiempo)
        {
            pSurf.Dispose();
            if (invisibilidadActivada)
            {
                D3DDevice.DepthStencilSurface = pOldDS;
                D3DDevice.SetRenderTarget(0, pOldRT);
                Invisibilidad.Technique = "PostProcess";
                Invisibilidad.SetValue("time", Tiempo);
                D3DDevice.VertexFormat = CustomVertex.PositionTextured.Format;
                D3DDevice.SetStreamSource(0, g_pVBV3D, 0);
                Invisibilidad.SetValue("g_RenderTarget", g_pRenderTarget);

                D3DDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                Invisibilidad.Begin(FX.None);
                Invisibilidad.BeginPass(0);
                D3DDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                Invisibilidad.EndPass();
                Invisibilidad.End();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para distorsionar la imagen
        /// </summary>
        private void drawPostProcess(Microsoft.DirectX.Direct3D.Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, screenQuadVB, 0);

            //Ver si el efecto de oscurecer esta activado, configurar Technique del shader segun corresponda

            effect.Technique = "RainTechnique";

            if (!presentacion && lloviendo)
            {
                effect.Technique = "RainTechnique";
            }
            else
            {
                effect.Technique = "DefaultTechnique";
            }

            //Cargamos parametros en el shader de Post-Procesado
            effect.SetValue("render_target2D", renderTarget2D);
            effect.SetValue("textura_alarma", lluviaTexture.D3dTexture);
            effect.SetValue("time", this.ElapsedTime);

            //Limiamos la pantalla y ejecutamos el render del shader
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();

            //Terminamos el renderizado de la escena
            d3dDevice.EndScene();
            d3dDevice.Present();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The render.
        /// </summary>
        /// <remarks></remarks>
        private void Render()
        {
            if (pause)
            {
                return;
            }

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();
            cam.move();

            SetupMatrices();

            device.Material = DefaultMaterial;

            device.Transform.World      = Matrix.Identity;
            device.RenderState.CullMode = Cull.Clockwise;

            // Raw.ParsedModel.DisplayedInfo.Draw(ref device, ref bsp.SkyBox);
            Material m = new Material();

            device.RenderState.CullMode = Cull.None;

            device.RenderState.FillMode         = FillMode.WireFrame;
            device.RenderState.AlphaBlendEnable = false;
            device.RenderState.AlphaTestEnable  = false;
            device.Material = DefaultMaterial;
            dxcoll.DrawMeshes(ref device);
            if (sphereDisplayAll)
            {
                device.Material = BlueMaterial;
                dxcoll.DrawSpheres(ref device);
                device.Transform.World = Matrix.Identity;
            }

            if (planeDisplayAll)
            {
                for (int i = 0; i < mList.Count; i++)
                {
                    m.Ambient       = Color.FromArgb(130, (24 - (i % 25)) * 10, i % 25 * 10);
                    m.Diffuse       = m.Ambient;
                    device.Material = m;

                    device.SetTexture(0, null);
                    device.RenderState.AlphaBlendEnable = true;
                    device.RenderState.AlphaTestEnable  = true;
                    device.RenderState.DestinationBlend = Blend.Zero;
                    device.RenderState.SourceBlend      = Blend.One;
                    device.RenderState.FillMode         = FillMode.Solid;
                    mList[i].DrawSubset(0);
                }

                // Draw normals
                device.SetStreamSource(0, Vb, 0);
                device.Transform.World = Matrix.Identity;
                device.VertexFormat    = CustomVertex.PositionColored.Format;
                device.DrawPrimitives(PrimitiveType.LineList, 0, normalVertices.Length / 2);
            }
            else
            {
                m.Ambient       = Color.Red;
                m.Diffuse       = Color.Red;
                device.Material = m;

                device.SetTexture(0, null);
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.AlphaTestEnable  = true;
                device.RenderState.DestinationBlend = Blend.Zero;
                device.RenderState.SourceBlend      = Blend.One;
                device.RenderState.FillMode         = FillMode.Solid;
                mList[planeDisplay].DrawSubset(0);

                // Draw normals
                device.SetStreamSource(0, Vb, 0);
                device.Transform.World = Matrix.Identity;
                device.VertexFormat    = CustomVertex.PositionColored.Format;

                int tpd  = planeDisplay;
                int mesh = 0;
                while (tpd >= coll.Meshes[mesh].SurfaceData.Length)
                {
                    tpd -= coll.Meshes[mesh++].SurfaceData.Length;
                }
                short s = (short)coll.Meshes[mesh].SurfaceData[tpd].Plane;
                if (s >= 0)
                {
                    device.DrawPrimitives(PrimitiveType.LineList, coll.Meshes[mesh].SurfaceData[tpd].Plane * 2, 1);
                }
            }

            device.EndScene();

            // Update the screen
            device.Present();
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Draw some text on the screen
    /// </summary>
    public void DrawText(float xpos, float ypos, Color color, string text, RenderFlags flags)
    {
        if (text == null)
        {
            return;
        }

        // Setup renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.SetTexture(0, fontTexture);
        device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
        device.PixelShader  = null;
        device.SetStreamSource(0, vertexBuffer, 0);

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0)
        {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        // Adjust for character spacing
        xpos -= spacingPerChar;
        float fStartX = xpos;

        // Fill vertex buffer
        int iv             = 0;
        int dwNumTriangles = 0;

        foreach (char c in text)
        {
            if (c == '\n')
            {
                xpos  = fStartX;
                ypos += (textureCoords[0, 3] - textureCoords[0, 1]) * textureHeight;
            }

            if ((c - 32) < 0 || (c - 32) >= 128 - 32)
            {
                continue;
            }

            float tx1 = textureCoords[c - 32, 0];
            float ty1 = textureCoords[c - 32, 1];
            float tx2 = textureCoords[c - 32, 2];
            float ty2 = textureCoords[c - 32, 3];

            float w = (tx2 - tx1) * textureWidth / textureScale;
            float h = (ty2 - ty1) * textureHeight / textureScale;

            int intColor = color.ToArgb();
            if (c != ' ')
            {
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + h - 0.5f, 0.9f, 1.0f), intColor, tx1, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + 0 - 0.5f, 0.9f, 1.0f), intColor, tx1, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + h - 0.5f, 0.9f, 1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + 0 - 0.5f, 0.9f, 1.0f), intColor, tx2, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + h - 0.5f, 0.9f, 1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + 0 - 0.5f, 0.9f, 1.0f), intColor, tx1, ty1);
                dwNumTriangles    += 2;

                if (dwNumTriangles * 3 > (MaxNumfontVertices - 6))
                {
                    // Set the data for the vertexbuffer
                    vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);
                    dwNumTriangles = 0;
                    iv             = 0;
                }
            }

            xpos += w - (2 * spacingPerChar);
        }

        // Set the data for the vertex buffer
        vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
        if (dwNumTriangles > 0)
        {
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);
        }

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }