Example #1
0
    /// <summary>
    /// Assembles and creates a file-based vertex shader
    /// </summary>
    public static VertexShader CreateVertexShader(Device device, string filename)
    {
        GraphicsStream code = null;
        string         path = null;

        // Get the path to the vertex shader file
        path = DXUtil.FindMediaFile(null, filename);

        // Assemble the vertex shader file
        code = ShaderLoader.FromFile(path, null, 0);

        // Create the vertex shader
        return(new VertexShader(device, code));
    }
Example #2
0
        private static unsafe void LoadPixelsShaders()
        {
            var shaderNormalPath    = Settings.ShadersPath + "normal.ps";
            var shaderGrayScalePath = Settings.ShadersPath + "grayscale.ps";
            var shaderMagicPath     = Settings.ShadersPath + "magic.ps";

            if (System.IO.File.Exists(shaderNormalPath))
            {
                using (var gs = ShaderLoader.FromFile(shaderNormalPath, null, ShaderFlags.None))
                    NormalPixelShader = new PixelShader(Device, gs);
            }
            if (System.IO.File.Exists(shaderGrayScalePath))
            {
                using (var gs = ShaderLoader.FromFile(shaderGrayScalePath, null, ShaderFlags.None))
                    GrayScalePixelShader = new PixelShader(Device, gs);
            }
            if (System.IO.File.Exists(shaderMagicPath))
            {
                using (var gs = ShaderLoader.FromFile(shaderMagicPath, null, ShaderFlags.None))
                    MagicPixelShader = new PixelShader(Device, gs);
            }
        }
Example #3
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Setup render states
            device.RenderState.Lighting = false;
            device.RenderState.CullMode = Cull.None;

            // Create index buffer

            indexBuffer = new IndexBuffer(typeof(short), numberIndices, device, 0, Pool.Default);

            short[] indices = (short[])indexBuffer.Lock(0, 0);

            int count = 0;

            for (int y = 1; y < m_Size; y++)
            {
                for (int x = 1; x < m_Size; x++)
                {
                    indices[count++] = (short)((y - 1) * m_Size + (x - 1));
                    indices[count++] = (short)((y - 0) * m_Size + (x - 1));
                    indices[count++] = (short)((y - 1) * m_Size + (x - 0));

                    indices[count++] = (short)((y - 1) * m_Size + (x - 0));
                    indices[count++] = (short)((y - 0) * m_Size + (x - 1));
                    indices[count++] = (short)((y - 0) * m_Size + (x - 0));
                }
            }

            indexBuffer.Unlock();


            // Create vertex buffer
            vertexBuffer = new VertexBuffer(typeof(Vector2), numberVertices, device, Usage.WriteOnly, 0, Pool.Default);

            Vector2[] vertices = (Vector2[])vertexBuffer.Lock(0, 0);

            count = 0;
            for (int y = 0; y < m_Size; y++)
            {
                for (int x = 0; x < m_Size; x++)
                {
                    vertices[count++] = new Vector2(((float)x / (float)(m_Size - 1) - 0.5f) * (float)Math.PI,
                                                    ((float)y / (float)(m_Size - 1) - 0.5f) * (float)Math.PI);
                }
            }

            vertexBuffer.Unlock();
            // Create vertex shader
            string         shaderPath = null;
            GraphicsStream code       = null;

            // Create our declaration
            VertexElement[] decl = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.Position, 0), VertexElement.VertexDeclarationEnd };
            ourDeclaration = new VertexDeclaration(device, decl);

            // Find the vertex shader file
            shaderPath = DXUtil.FindMediaFile(null, "Ripple.vsh");

            // Assemble the vertex shader from the file
            code = ShaderLoader.FromFile(shaderPath, null, 0);
            // Create the vertex shader
            ourShader = new VertexShader(device, code);
            code.Close();

            // Set up the projection matrix
            float fAspectRatio = (float)device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            projectionMatrix            = Matrix.PerspectiveFovRH(Geometry.DegreeToRadian(60.0f), fAspectRatio, 0.1f, 100.0f);
            device.Transform.Projection = projectionMatrix;
        }