private void DrawBrightness() { if (FrameworkCore.options.brightness == 5) { return; } //Ghetto Brightness settings. if (FrameworkCore.options.brightness > 5) { float adjustedBrightness = FrameworkCore.options.brightness - 5; adjustedBrightness /= 5; int alpha = (int)MathHelper.Lerp(1, 64, adjustedBrightness); FrameworkCore.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); BlendStateHelper.BeginApply(FrameworkCore.Graphics.GraphicsDevice); BlendStateHelper.SourceBlend = Blend.One; BlendStateHelper.DestinationBlend = Blend.One; BlendStateHelper.EndApply(FrameworkCore.Graphics.GraphicsDevice); FrameworkCore.SpriteBatch.Draw(FrameworkCore.hudSheet, new Rectangle(0, 0, (int)FrameworkCore.Graphics.GraphicsDevice.Viewport.Width, (int)FrameworkCore.Graphics.GraphicsDevice.Viewport.Height), sprite.blank, new Color(255, 255, 255, (byte)alpha)); FrameworkCore.SpriteBatch.End(); } else if (FrameworkCore.options.brightness < 5) { float adjustedBrightness = FrameworkCore.options.brightness; adjustedBrightness /= 4; int alpha = (int)MathHelper.Lerp(128, 32, adjustedBrightness); FrameworkCore.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied); BlendStateHelper.BeginApply(FrameworkCore.Graphics.GraphicsDevice); BlendStateHelper.SourceBlend = Blend.DestinationColor; BlendStateHelper.DestinationBlend = Blend.Zero; BlendStateHelper.EndApply(FrameworkCore.Graphics.GraphicsDevice); FrameworkCore.SpriteBatch.Draw(FrameworkCore.hudSheet, new Rectangle(0, 0, (int)FrameworkCore.Graphics.GraphicsDevice.Viewport.Width, (int)FrameworkCore.Graphics.GraphicsDevice.Viewport.Height), sprite.blank, new Color(0, 0, 0, (byte)alpha)); FrameworkCore.SpriteBatch.End(); } }
public void Draw(GameTime gameTime, Camera camera) { if (IsVisible(camera)) { float distance = (position - camera.CameraPosition).Length(); float angularSize = (float)Math.Tan((planetRadius + atmosRadius) / distance); float sizeInPixels = angularSize * GraphicsDevice.Viewport.Height / MathHelper.ToRadians(45.0f); if (sizeInPixels > 6.0f) { Matrix worldMatrix = Matrix.CreateFromYawPitchRoll(rotation.X, 0, 0); worldMatrix = worldMatrix * Matrix.CreateFromYawPitchRoll(0, 0, rotation.Y); worldMatrix.Translation = position; Vector3 lightDir = Vector3.Forward; if (atmosphereDiffuse != null) { // Draw the cloud layer. atmosWorldMatrix.SetValue(worldMatrix); atmosViewMatrix.SetValue(camera.View); atmosProjectionMatrix.SetValue(camera.Projection); atmosDiffuseTexture.SetValue(atmosphereDiffuse); atmosLightPosition.SetValue(lightDir); atmosLightColor.SetValue(new Vector4(1, 1, 1, 1)); atmosphereEffect.Techniques[0].Passes[0].Apply(); GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.EndApply(GraphicsDevice); GraphicsDevice.DepthStencilState = DepthStencilState.None; atmosphereMesh.Render(GraphicsDevice); GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = false; BlendStateHelper.EndApply(GraphicsDevice); GraphicsDevice.DepthStencilState = DepthStencilState.Default; } } } }
public void Draw(GameTime gameTime, Camera camera) { if (IsVisible(camera)) { float distance = (position - camera.CameraPosition).Length(); float angularSize = (float)Math.Tan(radius / distance); float sizeInPixels = angularSize * GraphicsDevice.Viewport.Height / camera.FieldOfView; if (sizeInPixels > 6.0f) { Matrix worldMatrix = Matrix.CreateFromYawPitchRoll(rotation.X, 0, 0); worldMatrix = worldMatrix * Matrix.CreateFromYawPitchRoll(0, 0, rotation.Y); worldMatrix.Translation = position; //Vector3 lightDir = Vector3.Forward; Vector3 lightDir = new Vector3(-.1f, 0, -1); planetWorldMatrix.SetValue(worldMatrix); planetViewMatrix.SetValue(camera.View); planetProjectionMatrix.SetValue(camera.Projection); planetDiffuseTexture.SetValue(planetDiffuse); planetBumpTexture.SetValue(planetBump); planetSpecTexture.SetValue(planetSpec); planetNightTexture.SetValue(planetNight); planetLightPosition.SetValue(lightDir); planetLightColor.SetValue(new Vector4(.7f, .3f, 0, 1)); planetSpecularPow.SetValue(2.0f); planetSpecularIntensity.SetValue(1f); planetCameraPos.SetValue(camera.CameraPosition); planetHazeColor.SetValue(hazeColor); planetEffect.Techniques[0].Passes[0].Apply(); GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; GraphicsDevice.DepthStencilState = DepthStencilState.Default; BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = false; BlendStateHelper.EndApply(GraphicsDevice); planet.Render(GraphicsDevice); GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; } } }
public void StartDraw(Camera camera) { GraphicsDevice device = FrameworkCore.Graphics.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; BlendStateHelper.BeginApply(device); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.EndApply(device); device.RasterizerState = RasterizerState.CullCounterClockwise; basicEffect.View = camera.View; basicEffect.Projection = camera.Projection; basicEffect.CurrentTechnique.Passes[0].Apply(); }
//initialize effect settings. public void RenderStart(ModelType model) { BlendStateHelper.BeginApply(FrameworkCore.Graphics.GraphicsDevice); if (!BlendStateHelper.AlphaBlendEnable) { BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.EndApply(FrameworkCore.Graphics.GraphicsDevice); } FrameworkCore.Graphics.GraphicsDevice.Indices = FrameworkCore.ModelArray[(int)model].Meshes[0].MeshParts[0].IndexBuffer; FrameworkCore.Graphics.GraphicsDevice.SetVertexBuffer(FrameworkCore.ModelArray[(int)model].Meshes[0].MeshParts[0].VertexBuffer); effect.Texture = FrameworkCore.TextureArray[(int)model]; effect.CurrentTechnique.Passes[0].Apply(); }
public unsafe void EndBatch(Camera camera) { if (pointCount == 0) { return; } GraphicsDevice device = FrameworkCore.Graphics.GraphicsDevice; // Update render state... BlendStateHelper.BeginApply(device); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.EndApply(device); device.DepthStencilState = DepthStencilState.Default; device.RasterizerState = RasterizerState.CullCounterClockwise; // Update vertex buffer... fixed(PointVertex *ptr = &vertices[0]) { buffer.SetDataPointerEXT( 0, (IntPtr)ptr, pointCount * vertices[0].VertexDeclaration.VertexStride, SetDataOptions.Discard ); } device.SetVertexBuffer(buffer); // Update Effect... world = Matrix.Identity; view = camera.View; projection = camera.Projection; Matrix.Multiply(ref world, ref view, out worldView); Matrix.Multiply(ref worldView, ref projection, out worldViewProj); wvpParameter.SetValue(worldViewProj); pointEffect.CurrentTechnique.Passes[0].Apply(); // Draw points, finally. device.DrawPrimitives(PrimitiveType.PointListEXT, 0, pointCount); pointCount = 0; }
/// <summary> /// Helper for setting the renderstates used to draw particles. /// </summary> void SetParticleRenderStates(GraphicsDevice device) { // Enable point sprites. PointSpriteHelper.Enable(); // renderState.PointSizeMax = 256; // FIXME: Do we care? -flibit // Set the alpha blend mode. BlendStateHelper.BeginApply(device); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = settings.SourceBlend; BlendStateHelper.DestinationBlend = settings.DestinationBlend; BlendStateHelper.EndApply(device); // Enable the depth buffer (so particles will not be visible through // solid objects like the ground plane), but disable depth writes // (so particles will not obscure other particles). device.DepthStencilState = DepthStencilState.DepthRead; }
private void StartDraw(Camera camera) { GraphicsDevice device = FrameworkCore.Graphics.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; BlendStateHelper.BeginApply(device); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.EndApply(device); device.RasterizerState = RasterizerState.CullCounterClockwise; // effect is a compiled effect created and compiled elsewhere // in the application //basicEffect.EnableDefaultLighting(); basicEffect.View = camera.View; basicEffect.Projection = camera.Projection; basicEffect.CurrentTechnique.Passes[0].Apply(); }
public void Draw(GameTime gameTime, Camera camera) { try { // First, we need to figure out which stars // are behind us and throw them out in front of us again // based on how fast the camera is moving if (!motionReady) { GenerateStars(camera); vertexBuffer.SetData <VertexPointSprite>(data); } else { MoveStars(camera); vertexBuffer.SetData <VertexPointSprite>(data); } { // // STARS // starEffect.Parameters["World"].SetValue(Matrix.Identity); starEffect.Parameters["View"].SetValue(camera.View); starEffect.Parameters["Projection"].SetValue(camera.Projection); starEffect.Parameters["Texture"].SetValue(starTexture); starEffect.Parameters["ViewportHeight"].SetValue(GraphicsDevice.Viewport.Height); GraphicsDevice.SetVertexBuffer(vertexBuffer); PointSpriteHelper.Enable(); // Set the alpha blend mode. BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.EndApply(GraphicsDevice); // Enable the depth buffer (so particles will not be visible through // solid objects like the space ship), but disable depth writes // (so particles will not obscure other particles). GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; for (int i = 0; i < starEffect.CurrentTechnique.Passes.Count; ++i) { starEffect.CurrentTechnique.Passes[i].Apply(); #if SDL2 GraphicsDevice.DrawPrimitives(PrimitiveType.PointListEXT, 0, starCount); #endif } PointSpriteHelper.Disable(); GraphicsDevice.SetVertexBuffer(null); BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = false; BlendStateHelper.EndApply(GraphicsDevice); if (GraphicsDevice.DepthStencilState.DepthBufferEnable) { GraphicsDevice.DepthStencilState = DepthStencilState.Default; } else { GraphicsDevice.DepthStencilState = Helpers.DepthWrite; } } base.Draw(gameTime); } catch { } }