Exemplo n.º 1
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            GorgonVertexShader       vertexShader   = Interlocked.Exchange(ref _vertexDeferShader, null);
            GorgonPixelShader        deferredShader = Interlocked.Exchange(ref _pixelDeferShader, null);
            GorgonPixelShader        lightShader    = Interlocked.Exchange(ref _pixelLitShader, null);
            GorgonConstantBufferView lightData      = Interlocked.Exchange(ref _lightData, null);
            GorgonConstantBufferView globalData     = Interlocked.Exchange(ref _globalData, null);

            GorgonRenderTargetView[] targets     = Interlocked.Exchange(ref _gbufferTargets, null);
            GorgonTexture2DView      textureView = Interlocked.Exchange(ref _gbufferTexture, null);

            textureView?.Dispose();

            for (int i = 0; i < targets.Length; ++i)
            {
                targets[i]?.Dispose();
            }

            globalData?.Dispose();
            lightData?.Dispose();
            lightShader?.Dispose();
            deferredShader?.Dispose();
            vertexShader?.Dispose();
        }
Exemplo n.º 2
0
        /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
        public void Dispose()
        {
            for (int i = 0; i < _volumeRtSections.Length; ++i)
            {
                _volumeSections[i]?.Dispose();
                _volumeRtSections[i]?.Dispose();
            }
            _textureView = null;

            _cube?.Dispose();
            _volumeScaleFactor?.Dispose();
            _volumeRayParams?.Dispose();
            _cubeTransform?.Dispose();
            _cubePosShader?.Dispose();
            _cubeDirShader?.Dispose();
            _cubeVs?.Dispose();
            _inputLayout?.Dispose();

            _cubeTransform     = null;
            _inputLayout       = null;
            _cube              = null;
            _volumeScaleFactor = null;
            _volumeRayParams   = null;
            _cubePosShader     = null;
            _cubeDirShader     = null;
            _cubeVs            = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Function to create a new vertex and pixel shader for use when rendering our triangle.
        /// </summary>
        private static void CreateShaders()
        {
            // We compile the vertex shader program into byte code for use by the GPU.  When we do this we have to provide the shader source code, and the name of the function
            // that represents the entry point for the vertex shader.
            _vertexShader = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, Resources.MiniTriShaders, "MiniTriVS");

            // Next, we'll compile the pixel shader.
            _pixelShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.MiniTriShaders, "MiniTriPS");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Function to load the shaders for the application.
        /// </summary>
        private static void LoadShaders()
        {
            string shaderCode = Resources.Shaders;

            _bufferless     = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, shaderCode, "BufferlessVs", Debugger.IsAttached);
            _vertexShader   = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, shaderCode, "VsMain", Debugger.IsAttached);
            _pixelShader    = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, shaderCode, "PsMain", Debugger.IsAttached);
            _geometryShader = GorgonShaderFactory.Compile <GorgonGeometryShader>(_graphics, shaderCode, "GsMain", Debugger.IsAttached);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Function to load the resources for the layer.
        /// </summary>
        public override void LoadResources()
        {
            _drawCalls = new List <GorgonDrawIndexCall>();
            BuildConstantBuffers();

            for (int i = 0; i < Planets.Count; ++i)
            {
                Planet planet = Planets[i];

                for (int j = 0; j < planet.Layers.Count; ++j)
                {
                    PlanetaryLayer layer = planet.Layers[j];

                    GorgonVertexShader vertexShader = _resources.VertexShaders[layer.Mesh.Material.VertexShader];
                    GorgonPixelShader  pixelShader  = _resources.PixelShaders[layer.Mesh.Material.PixelShader];

                    // Create our vertex layout now.
                    if (_vertexLayout == null)
                    {
                        _vertexLayout = _vertexLayout = GorgonInputLayout.CreateUsingType <Vertex3D>(_graphics, vertexShader);
                    }

                    // Set up a pipeline state for the mesh.
                    GorgonPipelineState pipelineState = _stateBuilder.Clear()
                                                        .PixelShader(pixelShader)
                                                        .VertexShader(vertexShader)
                                                        .BlendState(layer.Mesh.Material.BlendState)
                                                        .PrimitiveType(PrimitiveType.TriangleList)
                                                        .Build();
                    _drawCallBuilder.Clear()
                    .PipelineState(pipelineState)
                    .IndexBuffer(layer.Mesh.IndexBuffer, 0, layer.Mesh.IndexCount)
                    .VertexBuffer(_vertexLayout, new GorgonVertexBufferBinding(layer.Mesh.VertexBuffer, Vertex3D.Size))
                    .ConstantBuffer(ShaderType.Vertex, _viewProjectionBuffer)
                    .ConstantBuffer(ShaderType.Vertex, _worldBuffer, 1)
                    .ConstantBuffer(ShaderType.Pixel, _cameraBuffer)
                    .ConstantBuffer(ShaderType.Pixel, _lightBuffer, 1)
                    .ConstantBuffer(ShaderType.Pixel, _materialBuffer, 2);

                    (int startTexture, int textureCount) = layer.Mesh.Material.Textures.GetDirtyItems();

                    for (int k = startTexture; k < startTexture + textureCount; ++k)
                    {
                        GorgonTexture2DView texture = _resources.Textures[layer.Mesh.Material.Textures[k]];
                        _drawCallBuilder.ShaderResource(ShaderType.Pixel, texture, k);
                        // We should have this in the material, but since we know what we've got here, this will be fine.
                        _drawCallBuilder.SamplerState(ShaderType.Pixel, GorgonSamplerState.Wrapping, k);
                    }

                    _drawCalls.Add(_drawCallBuilder.Build());
                }
            }

            UpdateLightTransforms();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Function called to initialize the effect.
        /// </summary>
        /// <remarks>Applications must implement this method to ensure that any required resources are created, and configured for the effect.</remarks>
        protected override void OnInitialize()
        {
            var globalData = new GlobalEffectData
            {
                CameraPosition = DX.Vector3.Zero,
                FlipYNormal    = 0
            };

            _globalData = GorgonConstantBufferView.CreateConstantBuffer(Graphics, ref globalData, "Global deferred light effect data.", ResourceUsage.Default);

            _lightData = GorgonConstantBufferView.CreateConstantBuffer(Graphics,
                                                                       new GorgonConstantBufferInfo("Deferred Lighting Light Data Buffer")
            {
                SizeInBytes = Unsafe.SizeOf <PointLightData>(),
                Usage       = ResourceUsage.Dynamic
            });

            Macros.Add(new GorgonShaderMacro("DEFERRED_LIGHTING"));
            _vertexDeferShader      = CompileShader <GorgonVertexShader>(Resources.Lighting, "GorgonVertexLightingShader");
            _vertexDeferShaderState = VertexShaderBuilder.Shader(_vertexDeferShader)
                                      .Build();

            _pixelDeferShader      = CompileShader <GorgonPixelShader>(Resources.Lighting, "GorgonPixelShaderDeferred");
            _pixelDeferShaderState = PixelShaderBuilder.Shader(_pixelDeferShader)
                                     .SamplerState(_diffuseFilter, 0)
                                     .SamplerState(_normalFilter, 1)
                                     .SamplerState(_specularFilter, 2)
                                     .Build();

            Macros.Clear();
            Macros.Add(new GorgonShaderMacro("LIGHTS"));
            _vertexLitShader      = CompileShader <GorgonVertexShader>(Resources.Lighting, "GorgonVertexLitShader");
            _vertexLitShaderState = VertexShaderBuilder.Shader(_vertexLitShader)
                                    .Build();

            _pixelLitShader      = CompileShader <GorgonPixelShader>(Resources.Lighting, "GorgonPixelShaderLighting");
            _pixelLitShaderState = PixelShaderBuilder.Shader(_pixelLitShader)
                                   .ConstantBuffer(_lightData, 1)
                                   .ConstantBuffer(_globalData, 2)
                                   .SamplerState(_diffuseFilter, 0)
                                   .SamplerState(_normalFilter, 1)
                                   .SamplerState(_specularFilter, 2)
                                   .Build();

            // Rebuild our states for the new pixel shaders.
            _lightingState = BatchStateBuilder.PixelShaderState(_pixelLitShaderState)
                             .VertexShaderState(_vertexLitShaderState)
                             .BlendState(GorgonBlendState.Additive)
                             .Build();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Function to save the state information to this object.
        /// </summary>
        private void Save()
        {
            _targets               = _graphics.Output.GetRenderTargets();
            _uavs                  = _graphics.Output.GetUnorderedAccessViews();
            _indexBuffer           = _graphics.Input.IndexBuffer;
            _vertexBuffer          = _graphics.Input.VertexBuffers[0];
            _inputLayout           = _graphics.Input.Layout;
            _primitiveType         = _graphics.Input.PrimitiveType;
            _pixelShader           = _graphics.Shaders.PixelShader.Current;
            _vertexShader          = _graphics.Shaders.VertexShader.Current;
            _blendStates           = _graphics.Output.BlendingState.States;
            _blendFactor           = _graphics.Output.BlendingState.BlendFactor;
            _blendSampleMask       = _graphics.Output.BlendingState.BlendSampleMask;
            _rasterStates          = _graphics.Rasterizer.States;
            _samplerState          = _graphics.Shaders.PixelShader.TextureSamplers[0];
            _resource              = _graphics.Shaders.PixelShader.Resources[0];
            _depthStencilState     = _graphics.Output.DepthStencilState.States;
            _depthStencilReference = _graphics.Output.DepthStencilState.StencilReference;
            _rasterStates.IsScissorTestingEnabled = false;
            _depthStencil = _graphics.Output.DepthStencilView;
            _viewports    = _graphics.Rasterizer.GetViewports();
            _scissorTests = _graphics.Rasterizer.GetScissorRectangles();
            _alphaTest    = new Gorgon2DAlphaTest(Gorgon2D.IsAlphaTestEnabled, GorgonRangeF.Empty);

            _vsConstantBuffers = new Dictionary <int, GorgonConstantBuffer>();
            _psConstantBuffers = new Dictionary <int, GorgonConstantBuffer>();

            // Only store the constant buffers that we were using.
            // We need to store all the constant buffers because the effects
            // make use of multiple constant slots.  Unlike the resource views,
            // where we know that we're only using the first item (all bets are
            // off if a user decides to use another resource view slot), there's no
            // guarantee that we'll be only using 1 or 2 constant buffer slots.
            for (int i = 0; i < _graphics.Shaders.VertexShader.ConstantBuffers.Count; i++)
            {
                if (_graphics.Shaders.VertexShader.ConstantBuffers[i] != null)
                {
                    _vsConstantBuffers[i] = _graphics.Shaders.VertexShader.ConstantBuffers[i];
                }
            }

            for (int i = 0; i < _graphics.Shaders.PixelShader.ConstantBuffers.Count; i++)
            {
                if (_graphics.Shaders.PixelShader.ConstantBuffers[i] != null)
                {
                    _psConstantBuffers[i] = _graphics.Shaders.PixelShader.ConstantBuffers[i];
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Function called before a pass is rendered.
        /// </summary>
        /// <param name="pass">Pass to render.</param>
        /// <returns>
        /// TRUE to continue rendering, FALSE to stop.
        /// </returns>
        protected override bool OnBeforePassRender(GorgonEffectPass pass)
        {
            if (pass.RenderAction == null)
            {
                return(false);
            }

            _prevPixelShader  = Gorgon2D.PixelShader.Current;
            _prevVertexShader = Gorgon2D.VertexShader.Current;

            Gorgon2D.PixelShader.Current  = pass.PixelShader;
            Gorgon2D.VertexShader.Current = pass.VertexShader;

            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Function to initialize the blitter.
        /// </summary>
        public void Initialize()
        {
            try
            {
                // We've been initialized, so leave.
                if ((_vertexShader != null) || (Interlocked.Increment(ref _initializedFlag) > 1))
                {
                    // Trap other threads until we're done initializing and then release them.
                    while ((_vertexShader == null) && (_initializedFlag > 0))
                    {
                        var wait = new SpinWait();
                        wait.SpinOnce();
                    }

                    return;
                }


                _vertexShader = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics,
                                                                                 Resources.GraphicsShaders,
                                                                                 "GorgonBltVertexShader",
                                                                                 GorgonGraphics.IsDebugEnabled);
                _pixelShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics,
                                                                               Resources.GraphicsShaders,
                                                                               "GorgonBltPixelShader",
                                                                               GorgonGraphics.IsDebugEnabled);

                _inputLayout = GorgonInputLayout.CreateUsingType <BltVertex>(_graphics, _vertexShader);

                _vertexBufferBindings = new GorgonVertexBufferBindings(_inputLayout)
                {
                    [0] = GorgonVertexBufferBinding.CreateVertexBuffer <BltVertex>(_graphics,
                                                                                   4,
                                                                                   ResourceUsage.Dynamic,
                                                                                   bufferName: "Gorgon Blitter Vertex Buffer")
                };

                _wvpBuffer = GorgonConstantBufferView.CreateConstantBuffer(_graphics,
                                                                           new GorgonConstantBufferInfo("Gorgon Blitter WVP Buffer")
                {
                    Usage       = ResourceUsage.Dynamic,
                    SizeInBytes = DX.Matrix.SizeInBytes
                });

                // Finish initalizing the draw call.
                _pipelineState = _pipeStateBuilder.VertexShader(_vertexShader)
                                 .BlendState(GorgonBlendState.NoBlending)
                                 .DepthStencilState(GorgonDepthStencilState.Default)
                                 .PrimitiveType(PrimitiveType.TriangleStrip)
                                 .RasterState(GorgonRasterState.Default)
                                 .PixelShader(_pixelShader)
                                 .Build();

                _drawCallBuilder.VertexBuffers(_inputLayout, _vertexBufferBindings)
                .VertexRange(0, 4)
                .SamplerState(ShaderType.Pixel, GorgonSamplerState.Default)
                .PipelineState(_pipelineState)
                .ConstantBuffer(ShaderType.Vertex, _wvpBuffer);


                _defaultTexture = Resources.White_2x2.ToTexture2D(_graphics,
                                                                  new GorgonTexture2DLoadOptions
                {
                    Name    = "Gorgon_Default_White_Texture",
                    Usage   = ResourceUsage.Immutable,
                    Binding = TextureBinding.ShaderResource
                }).GetShaderResourceView();
            }
            finally
            {
                Interlocked.Decrement(ref _initializedFlag);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Function to initialize the GPU resource objects.
        /// </summary>
        private static void InitializeGpuResources()
        {
            _graphics = CreateGraphicsInterface();

            // If we couldn't create the graphics interface, then leave.
            if (_graphics == null)
            {
                return;
            }

            // Create a 1280x800 window with a depth buffer.
            // We can modify the resolution in the config file for the application, but like other Gorgon examples, the default is 1280x800.
            _swap = new GorgonSwapChain(_graphics,
                                        _mainForm,
                                        new GorgonSwapChainInfo("Main")
            {
                // Set up for 32 bit RGBA normalized display.
                Format = BufferFormat.R8G8B8A8_UNorm,
                Width  = Settings.Default.Resolution.Width,
                Height = Settings.Default.Resolution.Height
            });

            // Build the depth buffer for our swap chain.
            BuildDepthBuffer(_swap.Width, _swap.Height);


            if (!Settings.Default.IsWindowed)
            {
                // Get the output for the main window.
                var currentScreen             = Screen.FromControl(_mainForm);
                IGorgonVideoOutputInfo output = _graphics.VideoAdapter.Outputs[currentScreen.DeviceName];

                // If we've asked for full screen mode, then locate the correct video mode and set us up.
                _selectedVideoMode = new GorgonVideoMode(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height, BufferFormat.R8G8B8A8_UNorm);
                _swap.EnterFullScreen(in _selectedVideoMode, output);
            }

            // Handle resizing because the projection matrix and depth buffer needs to be updated to reflect the new view size.
            _swap.BeforeSwapChainResized += Swap_BeforeResized;
            _swap.AfterSwapChainResized  += Swap_AfterResized;

            // Set the current render target output so we can see something.
            _graphics.SetRenderTarget(_swap.RenderTargetView, _depthBuffer);

            // Create our shaders.
            // Our vertex shader.  This is a simple shader, it just processes a vertex by multiplying it against
            // the world/view/projection matrix and spits it back out.
            _vertexShader = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, Resources.Shader, "BoingerVS");

            // Our main pixel shader.  This is a very simple shader, it just reads a texture and spits it back out.  Has no
            // diffuse capability.
            _pixelShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.Shader, "BoingerPS");

            // Create the vertex input layout.
            // We need to create a layout for our vertex type because the shader won't know how to interpret the data we're sending it otherwise.
            // This is why we need a vertex shader before we even create the layout.
            _inputLayout = GorgonInputLayout.CreateUsingType <BoingerVertex>(_graphics, _vertexShader);

            // Resources are stored as System.Drawing.Bitmap files, so we need to convert into an IGorgonImage so we can upload it to a texture.
            // We also will generate mip-map levels for this image so that scaling the texture will look better.
            using (IGorgonImage image = Resources.Texture.ToGorgonImage())
            {
                _texture = image.ToTexture2D(_graphics,
                                             new GorgonTexture2DLoadOptions
                {
                    Usage = ResourceUsage.Immutable,
                    Name  = "Texture"
                })
                           .GetShaderResourceView();
            }

            // Create our constant buffer.
            // Our constant buffers are how we send data to our shaders.  This one in particular will be responsible for sending our world/view/projection matrix
            // to the vertex shader.
            _wvpBuffer = GorgonConstantBufferView.CreateConstantBuffer(_graphics,
                                                                       new GorgonConstantBufferInfo("WVPBuffer")
            {
                Usage       = ResourceUsage.Dynamic,
                SizeInBytes = DX.Matrix.SizeInBytes
            });
            // This one will hold our material information.
            _materialBuffer = GorgonConstantBufferView.CreateConstantBuffer(_graphics,
                                                                            new GorgonConstantBufferInfo("MaterialBuffer")
            {
                Usage       = ResourceUsage.Dynamic,
                SizeInBytes = Unsafe.SizeOf <GorgonColor>()
            });
            GorgonColor defaultMaterialColor = GorgonColor.White;

            _materialBuffer.Buffer.SetData(ref defaultMaterialColor);

            GorgonExample.LoadResources(_graphics);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Function used to build the resources required by the volume renderer.
        /// </summary>
        public void CreateResources()
        {
            _cubeVs        = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, Resources.VolumeRenderShaders, "VolumeVS", true);
            _cubePosShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.VolumeRenderShaders, "VolumePositionPS", true);
            _cubeDirShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.VolumeRenderShaders, "VolumeRayCastPS", true);
            _inputLayout   = GorgonInputLayout.CreateUsingType <CubeVertex>(_graphics, _cubeVs);
            _cube          = new Cube(_graphics, _inputLayout);

            _cubeTransform = new GorgonConstantBuffer(_graphics, new GorgonConstantBufferInfo
            {
                SizeInBytes = DX.Matrix.SizeInBytes
            });

            _volumeRayParams = new GorgonConstantBuffer(_graphics, new GorgonConstantBufferInfo
            {
                SizeInBytes = Unsafe.SizeOf <VolumeRayParameters>()
            });

            _volumeScaleFactor = new GorgonConstantBuffer(_graphics, new GorgonConstantBufferInfo
            {
                SizeInBytes = DX.Vector4.SizeInBytes
            });

            // Our camera is never changing, so we only need to define it here.
            DX.Matrix.Translation(0, 0, 1.5f, out _view);
            ResizeRenderRegion();

            UpdateCubeTransform();

            var pipelineBuilder = new GorgonPipelineStateBuilder(_graphics);
            var drawBuilder     = new GorgonDrawIndexCallBuilder();

            pipelineBuilder
            .PixelShader(_cubePosShader)
            .VertexShader(_cubeVs);

            // Position draw calls.
            _cubePosDrawCull = drawBuilder
                               .ConstantBuffer(ShaderType.Vertex, _cubeTransform.GetView())
                               .ConstantBuffer(ShaderType.Vertex, _volumeScaleFactor.GetView(), 1)
                               .PipelineState(pipelineBuilder)
                               .IndexBuffer(_cube.IndexBuffer, indexCount: _cube.IndexBuffer.IndexCount)
                               .VertexBuffer(_inputLayout, _cube.VertexBuffer[0])
                               .Build();

            pipelineBuilder
            .RasterState(GorgonRasterState.CullFrontFace);

            _cubePosDrawFrontCull = drawBuilder
                                    .PipelineState(pipelineBuilder)
                                    .Build();

            // Raycasting draw call.
            pipelineBuilder
            .PixelShader(_cubeDirShader)
            .RasterState(GorgonRasterState.Default);

            _cubeDirDrawCall = drawBuilder
                               .ConstantBuffer(ShaderType.Pixel, _volumeRayParams.GetView(), 0)
                               .PipelineState(pipelineBuilder)
                               .Build();
        }
Exemplo n.º 12
0
        public void Init()
        {
            _form = new TestForm
            {
                ShowTestPanel = true,
                ClientSize    = new Size(1280, 800)
            };
            _form.WindowState = FormWindowState.Minimized;
            _form.Show();
            _form.WindowState = FormWindowState.Normal;

            _graphics = new GorgonGraphics();
            _swap     = _graphics.Output.CreateSwapChain("Screen", new GorgonSwapChainSettings()
            {
                Window             = _form.panelDisplay,
                DepthStencilFormat = BufferFormat.D24_UIntNormal_S8_UInt
            });

            _swap.AfterSwapChainResized += (sender, args) =>
            {
                var currentMatrix = new MatrixBuffer();

                _graphics.Rasterizer.SetViewport(_swap.Viewport);
                _aspect = (_swap.Settings.VideoMode.Width) / (float)(_swap.Settings.VideoMode.Height);
                currentMatrix.Projection = Matrix.PerspectiveFovLH(100.39f.Radians(), _aspect, 0.1f, 1000.0f);
                currentMatrix.View       = Matrix.LookAtLH(new Vector3(0, 0, -0.75f), new Vector3(0, 0, 1.0f), Vector3.UnitY);

                _graphics.Output.SetRenderTarget(_swap, _swap.DepthStencilBuffer);

                pvw = currentMatrix.View * currentMatrix.Projection;
            };

            _swap.AfterStateTransition += (sender, args) =>
            {
                var currentMatrix = new MatrixBuffer();

                _graphics.Rasterizer.SetViewport(_swap.Viewport);
                _aspect = (_swap.Settings.VideoMode.Width) / (float)(_swap.Settings.VideoMode.Height);
                currentMatrix.Projection = Matrix.PerspectiveFovLH(100.39f.Radians(), _aspect, 0.1f, 1000.0f);
                currentMatrix.View       = Matrix.LookAtLH(new Vector3(0, 0, -0.75f), new Vector3(0, 0, 1.0f), Vector3.UnitY);

                _graphics.Output.SetRenderTarget(_swap, _swap.DepthStencilBuffer);

                pvw = currentMatrix.View * currentMatrix.Projection;
            };

            var button = new Button()
            {
                Text     = "3D",
                Location = new Point(90, 3)
            };

            button.Click += (sender, args) =>
            {
                _3d = !_3d;
                Matrix currentMatrix = Matrix.LookAtLH(new Vector3(0, 0, _camPos), new Vector3(0, 0, 1.0f), Vector3.UnitY);
                Matrix projection    = Matrix.PerspectiveFovLH(100.39f.Radians(), _aspect, 0.1f,
                                                               1000.0f);
                pvw = currentMatrix * projection;
            };

            _form.panelInput.Controls.Add(button);

            _sprite = new vertex[Count * 4];

            for (int i = 0; i < Count; i++)
            {
                _balls[i].Scale       = 1.0f;
                _balls[i].ScaleDelta  = (GorgonRandom.RandomSingle() * 1.5f) + 0.25f;
                _balls[i].AlphaBounce = _balls[i].ScaleBouce = false;
                _balls[i].XBounce     = GorgonRandom.RandomInt32(0, 100) > 50;
                _balls[i].YBounce     = GorgonRandom.RandomInt32(0, 100) > 50;
                _balls[i].ZBounce     = GorgonRandom.RandomInt32(0, 100) > 50;
                _balls[i].Velocity    = new Vector3((GorgonRandom.RandomSingle() * 0.5f), (GorgonRandom.RandomSingle() * 0.5f), (GorgonRandom.RandomSingle() * 0.5f));
                _balls[i].Angle       = 0.0f;
                _balls[i].AngleDelta  = 1.0f;
                _balls[i].Color       = new Vector4(1.0f);
                _balls[i].AlphaDelta  = GorgonRandom.RandomSingle() * 0.5f;
                _balls[i].Checkered   = true;          // GorgonRandom.RandomInt32(0, 100) > 50;
                _balls[i].Position    = new Vector3((GorgonRandom.RandomSingle() * 2.0f) - 1.0f, (GorgonRandom.RandomSingle() * 2.0f) - 1.0f, GorgonRandom.RandomSingle());
            }

            _vs = _graphics.Shaders.CreateShader <GorgonVertexShader>("TestVShader", "VS", _shader, null, true);
            _ps = _graphics.Shaders.CreateShader <GorgonPixelShader>("TestPShader", "PS", _shader, null, true);

            _layout = _graphics.Input.CreateInputLayout("Input", typeof(vertex), _vs);

            int vertexSize = _layout.Size;
            int index      = 0;
            var indices    = new int[Count * 6 * sizeof(int)];

            for (int i = 0; i < indices.Length; i += 6)
            {
                indices[i]     = index;
                indices[i + 1] = index + 1;
                indices[i + 2] = index + 2;
                indices[i + 3] = index + 1;
                indices[i + 4] = index + 3;
                indices[i + 5] = index + 2;
                index         += 4;
            }

            _vertices = _graphics.Buffers.CreateVertexBuffer("Vertex", new GorgonBufferSettings()
            {
                SizeInBytes = 4 * vertexSize * Count,
                Usage       = BufferUsage.Dynamic
            });
            _index = _graphics.Buffers.CreateIndexBuffer("Index", indices, BufferUsage.Immutable);

            _texture  = _graphics.Textures.FromFile <GorgonTexture2D>("Balls", @"..\..\..\..\Resources\BallDemo\BallDemo.png", new GorgonCodecPNG());
            _texture2 = _graphics.Textures.FromFile <GorgonTexture2D>("VBBack", @"..\..\..\..\Resources\Images\VBback.jpg", new GorgonCodecJPEG());

            var matrix = new MatrixBuffer();

            _aspect = _swap.Settings.VideoMode.Width / (float)(_swap.Settings.VideoMode.Height);

            matrix.Projection = Matrix.PerspectiveFovLH(100.39f.Radians(), _aspect, 0.1f,
                                                        1000.0f);
            matrix.View      = Matrix.LookAtLH(new Vector3(0, 0, _camPos), new Vector3(0, 0, 1.0f), Vector3.UnitY);
            matrix.Array     = new Vector4[3];
            matrix.Array[0]  = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            matrix.Array[1]  = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            matrix.Array[2]  = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            matrix.valueType = new TEMPGUY
            {
                value2    = matrix.View,
                tempArray = new Vector4[3]
            };

            _depthStateAlpha.IsDepthEnabled      = false;
            _depthStateAlpha.IsDepthWriteEnabled = false;

            _graphics.Input.Layout = _layout;
            _graphics.Shaders.VertexShader.Current = _vs;
            _graphics.Shaders.PixelShader.Current  = _ps;

            _graphics.Shaders.PixelShader.TextureSamplers.SetRange(0, new[] { GorgonTextureSamplerStates.LinearFilter, GorgonTextureSamplerStates.LinearFilter });

            _graphics.Rasterizer.SetViewport(_swap.Viewport);
            _graphics.Output.DepthStencilState.States = _depthStateAlpha;
            _graphics.Output.SetRenderTarget(_swap, _swap.DepthStencilBuffer);
            _graphics.Input.VertexBuffers[0] = new GorgonVertexBufferBinding(_vertices, vertexSize);
            _graphics.Input.IndexBuffer      = _index;
            _graphics.Shaders.PixelShader.Resources.SetRange(0, new GorgonShaderView[] { _texture, _texture2 });
            _graphics.Output.BlendingState.States = GorgonBlendStates.ModulatedBlending;
            pvw = matrix.valueType.value2 * matrix.Projection;

            _tempStream = new GorgonDataStream(_sprite.Length * vertexSize);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Function to initialize the application.
        /// </summary>
        private static void Initialize()
        {
            _form = new FormMain();

            _graphics  = new GorgonGraphics();
            _swapChain = _graphics.Output.CreateSwapChain("Swap",
                                                          new GorgonSwapChainSettings
            {
                Window             = _form,
                IsWindowed         = true,
                DepthStencilFormat = BufferFormat.D24_UIntNormal_S8_UInt,
                Format             = BufferFormat.R8G8B8A8_UIntNormal
            });

            _renderer2D = _graphics.Output.Create2DRenderer(_swapChain);

            _font = _graphics.Fonts.CreateFont("AppFont",
                                               new GorgonFontSettings
            {
                FontFamilyName   = "Calibri",
                FontStyle        = FontStyle.Bold,
                FontHeightMode   = FontHeightMode.Pixels,
                AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                OutlineSize      = 1,
                OutlineColor1    = Color.Black,
                Size             = 16.0f
            });

            _vertexShader       = _graphics.Shaders.CreateShader <GorgonVertexShader>("VertexShader", "PrimVS", Resources.Shaders);
            _pixelShader        = _graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "PrimPS", Resources.Shaders);
            _bumpShader         = _graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "PrimPSBump", Resources.Shaders);
            _waterShader        = _graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "PrimPSWaterBump", Resources.Shaders);
            _normalVertexShader = _graphics.Shaders.CreateShader <GorgonVertexShader>("NormalVertexShader", "NormalVS", Resources.Shaders);
            _normalPixelShader  = _graphics.Shaders.CreateShader <GorgonPixelShader>("NormalPixelShader", "NormalPS", Resources.Shaders);
            _vertexLayout       = _graphics.Input.CreateInputLayout("Vertex3D", typeof(Vertex3D), _vertexShader);
            _normalVertexLayout = _graphics.Input.CreateInputLayout("NormalVertex",
                                                                    new[]
            {
                new GorgonInputElement("SV_POSITION",
                                       BufferFormat.R32G32B32A32_Float,
                                       0,
                                       0,
                                       0,
                                       false,
                                       0),
            },
                                                                    _normalVertexShader);

            _graphics.Shaders.VertexShader.Current = _vertexShader;
            _graphics.Shaders.PixelShader.Current  = _pixelShader;
            _graphics.Input.Layout        = _vertexLayout;
            _graphics.Input.PrimitiveType = PrimitiveType.TriangleList;

            _texture       = _graphics.Textures.CreateTexture <GorgonTexture2D>("UVTexture", Resources.UV);
            _earf          = _graphics.Textures.CreateTexture <GorgonTexture2D>("Earf", Resources.earthmap1k);
            _normalMap     = _graphics.Textures.FromMemory <GorgonTexture2D>("RainNRM", Resources.Rain_Height_NRM, new GorgonCodecDDS());
            _normalEarfMap = _graphics.Textures.FromMemory <GorgonTexture2D>("EarfNRM", Resources.earthbump1k_NRM, new GorgonCodecDDS());
            _specMap       = _graphics.Textures.FromMemory <GorgonTexture2D>("RainSPC", Resources.Rain_Height_SPEC, new GorgonCodecDDS());
            _specEarfMap   = _graphics.Textures.CreateTexture <GorgonTexture2D>("EarfSPC", Resources.earthspec1k);
            _cloudMap      = _graphics.Textures.CreateTexture <GorgonTexture2D>("EarfClouds", Resources.earthcloudmap);
            _gorgNrm       = _graphics.Textures.CreateTexture <GorgonTexture2D>("EarfClouds", Resources.normalmap);

            var depth = new GorgonDepthStencilStates
            {
                DepthComparison     = ComparisonOperator.LessEqual,
                IsDepthEnabled      = true,
                IsDepthWriteEnabled = true
            };

            _graphics.Output.DepthStencilState.States = depth;
            _graphics.Output.SetRenderTarget(_swapChain, _swapChain.DepthStencilBuffer);
            _graphics.Rasterizer.States = GorgonRasterizerStates.CullBackFace;
            _graphics.Rasterizer.SetViewport(new GorgonViewport(0, 0, _form.ClientSize.Width, _form.ClientSize.Height, 0, 1.0f));
            _graphics.Shaders.PixelShader.TextureSamplers[0] = GorgonTextureSamplerStates.LinearFilter;

            _wvp = new WorldViewProjection(_graphics);
            _wvp.UpdateProjection(75.0f, _form.ClientSize.Width, _form.ClientSize.Height);

            // When we resize, update the projection and viewport to match our client size.
            _form.Resize += (sender, args) =>
            {
                _graphics.Rasterizer.SetViewport(new GorgonViewport(0, 0, _form.ClientSize.Width, _form.ClientSize.Height, 0, 1.0f));
                _wvp.UpdateProjection(75.0f, _form.ClientSize.Width, _form.ClientSize.Height);
            };

            var     fnU = new Vector3(0.5f, 1.0f, 0);
            var     fnV = new Vector3(1.0f, 1.0f, 0);
            Vector3 faceNormal;

            Vector3.Cross(ref fnU, ref fnV, out faceNormal);
            faceNormal.Normalize();

            _triangle = new Triangle(_graphics, new Vertex3D
            {
                Position = new Vector4(-12.5f, -1.5f, 12.5f, 1),
                Normal   = faceNormal,
                UV       = new Vector2(0, 1.0f)
            }, new Vertex3D
            {
                Position = new Vector4(0, 24.5f, 12.5f, 1),
                Normal   = faceNormal,
                UV       = new Vector2(0.5f, 0.0f)
            }, new Vertex3D
            {
                Position = new Vector4(12.5f, -1.5f, 12.5f, 1),
                Normal   = faceNormal,
                UV       = new Vector2(1.0f, 1.0f)
            })
            {
                Texture  = _texture,
                Position = new Vector3(0, 0, 1.0f)
            };

            _plane = new Plane(_graphics, new Vector2(25.0f, 25.0f), new RectangleF(0, 0, 1.0f, 1.0f), new Vector3(90, 0, 0), 32, 32)
            {
                Position = new Vector3(0, -1.5f, 1.0f),
                Texture  = _texture
            };

            _cube = new Cube(_graphics, new Vector3(1, 1, 1), new RectangleF(0, 0, 1.0f, 1.0f), new Vector3(45.0f, 0, 0), 1, 1)
            {
                Position = new Vector3(0, 0, 1.5f),
                Texture  = _texture
            };

            _sphere = new Sphere(_graphics, 1.0f, new RectangleF(0.0f, 0.0f, 1.0f, 1.0f), Vector3.Zero, 64, 64)
            {
                Position = new Vector3(-2.0f, 1.0f, 0.75f),
                Texture  = _earf
            };

            _clouds = new Sphere(_graphics, 5.175f, new RectangleF(0.0f, 0.0f, 1.0f, 1.0f), Vector3.Zero, 16, 16)
            {
                Position = new Vector3(10, 2, 9.5f),
                Texture  = _cloudMap
            };

            _icoSphere = new IcoSphere(_graphics, 5.0f, new RectangleF(0, 0, 1, 1), Vector3.Zero, 3)
            {
                Rotation = new Vector3(0, -45.0f, 0),
                Position = new Vector3(10, 2, 9.5f),
                Texture  = _earf
            };

            _graphics.Shaders.PixelShader.TextureSamplers[0] = new GorgonTextureSamplerStates
            {
                TextureFilter        = TextureFilter.Linear,
                HorizontalAddressing = TextureAddressing.Wrap,
                VerticalAddressing   = TextureAddressing.Wrap,
                DepthAddressing      = TextureAddressing.Wrap,
                ComparisonFunction   = ComparisonOperator.Always
            };
            _graphics.Shaders.PixelShader.TextureSamplers[2] = new GorgonTextureSamplerStates
            {
                TextureFilter        = TextureFilter.Linear,
                HorizontalAddressing = TextureAddressing.Wrap,
                VerticalAddressing   = TextureAddressing.Wrap,
                DepthAddressing      = TextureAddressing.Wrap,
                ComparisonFunction   = ComparisonOperator.Always
            };

            _graphics.Shaders.PixelShader.TextureSamplers[1] = new GorgonTextureSamplerStates
            {
                TextureFilter        = TextureFilter.Linear,
                HorizontalAddressing = TextureAddressing.Wrap,
                VerticalAddressing   = TextureAddressing.Wrap,
                DepthAddressing      = TextureAddressing.Wrap,
                ComparisonFunction   = ComparisonOperator.Always
            };

            _material = new Material
            {
                UVOffset      = Vector2.Zero,
                SpecularPower = 1.0f
            };

            _materialBuffer = _graphics.Buffers.CreateConstantBuffer("uvOffset", ref _material, BufferUsage.Default);

            _graphics.Shaders.PixelShader.ConstantBuffers[2] = _materialBuffer;

            _light = new Light(_graphics);
            var lightPosition = new Vector3(1.0f, 1.0f, -1.0f);

            _light.UpdateLightPosition(ref lightPosition, 0);
            GorgonColor color = GorgonColor.White;

            _light.UpdateSpecular(ref color, 256.0f, 0);

            lightPosition = new Vector3(-5.0f, 5.0f, 8.0f);
            _light.UpdateLightPosition(ref lightPosition, 1);
            color = Color.Yellow;
            _light.UpdateColor(ref color, 1);
            _light.UpdateSpecular(ref color, 2048.0f, 1);
            _light.UpdateAttenuation(10.0f, 1);

            lightPosition = new Vector3(5.0f, 3.0f, 10.0f);
            _light.UpdateLightPosition(ref lightPosition, 2);
            color = Color.Red;
            _light.UpdateColor(ref color, 2);
            _light.UpdateAttenuation(16.0f, 2);

            var eye    = Vector3.Zero;
            var lookAt = Vector3.UnitZ;
            var up     = Vector3.UnitY;

            _wvp.UpdateViewMatrix(ref eye, ref lookAt, ref up);

            _cameraRotation = Vector2.Zero;

            Gorgon.PlugIns.LoadPlugInAssembly(Application.StartupPath + @"\Gorgon.Input.Raw.dll");

            _input    = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonRawPlugIn");
            _keyboard = _input.CreateKeyboard(_form);
            _mouse    = _input.CreatePointingDevice(_form);

            _keyboard.KeyDown += (sender, args) =>
            {
                if (args.Key == KeyboardKeys.L)
                {
                    _lock = !_lock;
                }
            };

            _mouse.PointingDeviceDown      += Mouse_Down;
            _mouse.PointingDeviceUp        += Mouse_Up;
            _mouse.PointingDeviceWheelMove += (sender, args) =>
            {
                if (args.WheelDelta < 0)
                {
                    _sensitivity -= 0.05f;

                    if (_sensitivity < 0.05f)
                    {
                        _sensitivity = 0.05f;
                    }
                }
                else if (args.WheelDelta > 0)
                {
                    _sensitivity += 0.05f;

                    if (_sensitivity > 2.0f)
                    {
                        _sensitivity = 2.0f;
                    }
                }
            };
            _mouse.PointingDeviceMove += (sender, args) =>
            {
                if (!_mouse.Exclusive)
                {
                    return;
                }

                var delta = args.RelativePosition;
                _cameraRotation.Y      += delta.Y * _sensitivity;                                        //((360.0f * 0.002f) * delta.Y.Sign());
                _cameraRotation.X      += delta.X * _sensitivity;                                        //((360.0f * 0.002f) * delta.X.Sign());
                _mouseStart             = _mouse.Position;
                _mouse.RelativePosition = PointF.Empty;
            };
        }
Exemplo n.º 14
0
        /// <summary>
        /// Function to initialize the application.
        /// </summary>
        private static void Initialize()
        {
            var depthFormat = BufferFormat.D24_UIntNormal_S8_UInt;                              // Depth buffer format.

            // Create our form.
            _mainForm = new formMain();

            // Add a keybinding to switch to full screen or windowed.
            _mainForm.KeyDown += _mainForm_KeyDown;

            // Create the main graphics interface.
            Graphics = new GorgonGraphics();

            // Validate depth buffer for this device.
            // Odds are good that if this fails, you should probably invest in a
            // better video card.  Preferably something created after 2005.
            if (!Graphics.VideoDevice.SupportsDepthFormat(depthFormat))
            {
                depthFormat = BufferFormat.D16_UIntNormal;

                if (Graphics.VideoDevice.SupportsDepthFormat(depthFormat))
                {
                    return;
                }

                GorgonDialogs.ErrorBox(_mainForm, "Video device does not support a 24 or 16 bit depth buffer.");
                return;
            }

            // Create a 1280x800 window with a depth buffer.
            // We can modify the resolution in the config file for the application, but
            // like other Gorgon examples, the default is 1280x800.
            _swap = Graphics.Output.CreateSwapChain("Main", new GorgonSwapChainSettings
            {
                Window             = _mainForm,                                         // Assign to our form.
                Format             = BufferFormat.R8G8B8A8_UIntNormal,                  // Set up for 32 bit RGBA normalized display.
                Size               = Settings.Default.Resolution,                       // Get the resolution from the config file.
                DepthStencilFormat = depthFormat,                                       // Get our depth format.
                IsWindowed         = Settings.Default.IsWindowed                        // Set up for windowed or full screen (depending on config file).
            });

            // Center on the primary monitor.
            // This is necessary because we already created the window, so it'll be off center at this point.
            _mainForm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - _mainForm.Width / 2,
                                           Screen.PrimaryScreen.WorkingArea.Height / 2 - _mainForm.Height / 2);

            // Handle any resizing.
            // This is here because the base graphics library will NOT handle state loss due to resizing.
            // This is up to the developer to handle.
            _swap.AfterSwapChainResized += _swap_Resized;

            // Create the 2D interface for our text.
            _2D = Graphics.Output.Create2DRenderer(_swap);

            // Create our shaders.
            // Our vertex shader.  This is a simple shader, it just processes a vertex by multiplying it against
            // the world/view/projection matrix and spits it back out.
            _vertexShader = Graphics.Shaders.CreateShader <GorgonVertexShader>("VertexShader", "BoingerVS", Resources.Shader);
            // Our main pixel shader.  This is a very simple shader, it just reads a texture and spits it back out.  Has no
            // diffuse capability.
            _pixelShader = Graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "BoingerPS", Resources.Shader);
            // Our shadow shader for our ball "shadow".  This is hard coded to send back black (R:0, G:0, B:0) at 50% opacity (A: 0.5).
            _pixelShaderShadow = Graphics.Shaders.CreateShader <GorgonPixelShader>("ShadowShader", "BoingerShadowPS", Resources.Shader);

            // Create the vertex input layout.
            // We need to create a layout for our vertex type because the shader won't know
            // how to interpret the data we're sending it otherwise.  This is why we need a
            // vertex shader before we even create the layout.
            _inputLayout = Graphics.Input.CreateInputLayout("InputLayout", typeof(BoingerVertex), _vertexShader);

            // Create the view port.
            // This just tells the renderer how big our display is.
            var view = new GorgonViewport(0, 0, _mainForm.ClientSize.Width, _mainForm.ClientSize.Height, 0.0f, 1.0f);

            // Load our textures from the resources.
            // This contains our textures for the walls and ball.
            _texture = Graphics.Textures.CreateTexture <GorgonTexture2D>("PlaneTexture", Resources.Texture);

            // Set up our view matrix.
            // Move the camera (view matrix) back 2.2 units.  This will give us enough room to see what's
            // going on.
            Matrix.Translation(0, 0, 2.2f, out _viewMatrix);

            // Set up our projection matrix.
            // This matrix is probably the cause of almost EVERY problem you'll ever run into in 3D programming.
            // Basically we're telling the renderer that we want to have a vertical FOV of 75 degrees, with the aspect ratio
            // based on our form width and height.  The final values indicate how to distribute Z values across depth (tip:
            // it's not linear).
            _projMatrix = Matrix.PerspectiveFovLH((75.0f).Radians(), _mainForm.Width / (float)_mainForm.Height, 0.125f, 500.0f);

            // Create our constant buffer and backing store.
            // Our constant buffers are how we send data to our shaders.  This one in particular will be responsible
            // for sending our world/view/projection matrix to the vertex shader.  The stream we're creating after
            // the constant buffer is our system memory store for the data.  Basically we write to the system
            // memory and then upload that data to the video card.  This is very different from how things used to
            // work, but allows a lot more flexibility.
            _wvpBuffer = Graphics.Buffers.CreateConstantBuffer("WVPBuffer", new GorgonConstantBufferSettings
            {
                SizeInBytes = Matrix.SizeInBytes
            });
            _wvpBufferStream = new GorgonDataStream(_wvpBuffer.SizeInBytes);

            // Create our planes.
            // Here's where we create the 2 planes for our rear wall and floor.  We set the texture size to texel units
            // because that's how the video card expects them.  However, it's a little hard to eyeball 0.67798223f by looking
            // at the texture image display, so we use the ToTexel function to determine our texel size.
            var textureSize = _texture.ToTexel(new Vector2(500, 500));

            _planes = new[] {
                new Plane(new Vector2(3.5f), new RectangleF(Vector2.Zero, textureSize)),
                new Plane(new Vector2(3.5f), new RectangleF(Vector2.Zero, textureSize))
            };

            // Set up default positions and orientations.
            _planes[0].Position = new Vector3(0, 0, 3.0f);
            _planes[1].Position = new Vector3(0, -3.5f, 3.5f);
            _planes[1].Rotation = new Vector3(90.0f, 0, 0);

            // Create our sphere.
            // Again, here we're using texels to align the texture coordinates to the other image
            // packed into the texture (atlasing).
            var textureOffset = _texture.ToTexel(new Vector2(516, 0));

            // This is to scale our texture coordinates because the actual image is much smaller
            // (256x256) than the full texture (1024x512).
            textureSize.X = 0.245f;
            textureSize.Y = 0.5f;
            // Give the sphere a place to live.
            _sphere = new Sphere(1.0f, textureOffset, textureSize)
            {
                Position = new Vector3(2.2f, 1.5f, 2.5f)
            };


            // Bind our objects to the pipeline and set default states.
            // At this point we need to give the graphics card a bunch of things
            // it needs to do its job.

            // Give our current input layout.
            Graphics.Input.Layout = _inputLayout;
            // We're drawing individual triangles for this (and this is usyally the case).
            Graphics.Input.PrimitiveType = PrimitiveType.TriangleList;

            // Bind our current vertex shader and send over our world/view/projection matrix
            // constant buffer.
            Graphics.Shaders.VertexShader.Current            = _vertexShader;
            Graphics.Shaders.VertexShader.ConstantBuffers[0] = _wvpBuffer;

            // Do the same with the pixel shader, only we're binding our texture to it as well.
            // We also need to bind a sampler to the texture because without it, the shader won't
            // know how to interpret the texture data (e.g. how will the shader know if the texture
            // is supposed to be bilinear filtered or point filtered?)
            Graphics.Shaders.PixelShader.Current            = _pixelShader;
            Graphics.Shaders.PixelShader.Resources[0]       = _texture;
            Graphics.Shaders.PixelShader.TextureSamplers[0] = GorgonTextureSamplerStates.LinearFilter;

            // Turn on alpha blending.
            Graphics.Output.BlendingState.States = GorgonBlendStates.ModulatedBlending;

            // Turn on depth writing.
            // This is our depth writing state.  When this is on, all polygon data sent to the card
            // will write to our depth buffer.  Normally we want this, but for translucent objects, it's
            // problematic....
            _depth = new GorgonDepthStencilStates
            {
                DepthComparison     = ComparisonOperator.LessEqual,
                IsDepthEnabled      = true,
                IsDepthWriteEnabled = true,
                IsStencilEnabled    = false
            };

            // Turn off depth writing.
            // So, we copy the depth state and turn off depth writing so that translucent objects
            // won't write to the depth buffer but can still read it.
            _noDepth = _depth;
            _noDepth.IsDepthWriteEnabled             = false;
            Graphics.Output.DepthStencilState.States = _depth;

            // Bind our swap chain and set up the default rasterizer states.
            Graphics.Output.SetRenderTarget(_swap, _swap.DepthStencilBuffer);
            Graphics.Rasterizer.States = GorgonRasterizerStates.CullBackFace;
            Graphics.Rasterizer.SetViewport(view);

            // I know, there's a lot in here.  Thing is, if this were Direct 3D 11 code, it'd probably MUCH
            // more code and that's even before creating our planes and sphere.
        }