private void RenderFrame() { //Set the render target and the depth stencil buffers //for rendering to the display just set the device default //BackBuffer and BackDepthBuffer device.SetRenderTarget(device.BackBuffer, device.BackDepthBuffer); //Set the ViewPort to used by the device during the viewport tranformation device.ViewPort = new ViewPort(0, 0, Width, Height); //Clear the render target and depth stencil buffers device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0, 0, 0, 0), 1, 0); //Set the primitive type device.PrimitiveTopology = IAPrimitive.TriangleList; //Bind the vertex buffer to slot 0 at offset 0 device.SetVertexBuffer(0, vertexBuffer, 0); //Set the index buffer device.SetIndexBuffer(indexBuffer); //Send the transformation matrices to the vertex shader input.World = Matrix.RotationY(-(float)Environment.TickCount / 5000.0f); input.View = view; input.Projection = projection; //Send the light info and other values to the pixel shader input.CameraPosition = cameraPosition; input.ReflectionRatio = 0.05f; input.SpecularRatio = 0.15f; input.SpecularStyleLerp = 0.15f; input.SpecularPower = 8; input.DirectionalLight = new DirectionalLight { Color = Color3.White, Direction = new Euler(45, 0, 0).ToDirection() }; //Bind a texture with a sampler state. As a convetion the SamplerState //in the shader must have the same name as the texture with 's' as prefix //for example in the shader the sampler state is declared //SamplerState sDiffuseTexture; input.DiffuseTexture = diffuseTexture.ToSampler(diffuseSampler); device.GetShaderStage <PixelShader>().SetResource(0, diffuseTexture); device.GetShaderStage <PixelShader>().SetSampler(0, diffuseSampler); //Bind textures with default sampler state (linear filtering and wrap TextureAddressMode). //these statements have the same behavior that calling nightTexture.ToSampler() input.NightTexture = nightTexture; input.NormalMapTexture = normalMapTexture; input.ReflectionMask = reflectionMask; //Set the shader program device.Program = shaderProgram; //Draw the geometry using the indices count, the start index an the vertex base offset device.DrawIndexed((int)indexBuffer.SizeInBytes / indexBuffer.Stride, 0, 0); //Present the render target buffer to the display. device.Present(); }