예제 #1
0
        /// <summary>
        /// Function to update the blur kernel.
        /// </summary>
        /// <remarks>This implementation is ported from the Java code appearing in "Filthy Rich Clients: Developing Animated and Graphical Effects for Desktop Java".</remarks>
        private void UpdateKernel()
        {
            float sigma          = _blurRadius / _blurAmount;
            float sqSigmaDouble  = 2.0f * sigma * sigma;
            float sigmaRoot      = (sqSigmaDouble * (float)System.Math.PI).Sqrt();
            float total          = 0.0f;
            int   blurKernelSize = (_blurRadius * 2) + 1;

            for (int i = -_blurRadius, index = 0; i <= _blurRadius; ++i, ++index)
            {
                float distance = i * i;
                _kernel[index] = (-distance / sqSigmaDouble).Exp() / sigmaRoot;
                total         += _kernel[index];
            }

            _blurKernelStream.Position = 0;
            _blurKernelStream.Write(_blurRadius);

            for (int i = 0; i < blurKernelSize; i++)
            {
                _blurKernelStream.Write(new Vector4(0, 0, 0, _kernel[i] / total));
            }

            // Send to constant buffer.
            _blurKernelStream.Position = 0;
            _blurStaticBuffer.Update(_blurKernelStream);
        }
예제 #2
0
파일: Program.cs 프로젝트: tmp7701/Gorgon
        /// <summary>
        /// Function to update the world/view/projection matrix.
        /// </summary>
        /// <param name="world">The world matrix to update.</param>
        public static void UpdateWVP(ref Matrix world)
        {
            Matrix temp;
            Matrix wvp;

            // Build our world/view/projection matrix to send to
            // the shader.
            Matrix.Multiply(ref world, ref _viewMatrix, out temp);
            Matrix.Multiply(ref temp, ref _projMatrix, out wvp);

            // Direct 3D 11 requires that we transpose our matrix
            // before sending it to the shader.
            Matrix.Transpose(ref wvp, out wvp);

            // Update the constant buffer.
            _wvpBufferStream.Write(wvp);
            _wvpBufferStream.Position = 0;
            _wvpBuffer.Update(_wvpBufferStream);
        }
예제 #3
0
        public void BindStructBuffer()
        {
            _framework.CreateTestScene(_sbShaders, _sbShaders, false);

            using (var buffer = _framework.Graphics.Buffers.CreateStructuredBuffer("SB", new GorgonStructuredBufferSettings
            {
                SizeInBytes = 48,
                StructureSize = 12
            }))
            {
                _bufferStream = new GorgonDataStream(48);

                _framework.Graphics.Shaders.VertexShader.Resources[0] = buffer;

                _framework.MaxTimeout = 10000;

                _framework.IdleFunc = () =>
                {
                    for (int i = 0; i < 4; i++)
                    {
                        var rnd = new Vector3(GorgonRandom.RandomSingle() * GorgonTiming.Delta,
                                              GorgonRandom.RandomSingle() * GorgonTiming.Delta,
                                              GorgonRandom.RandomSingle() * GorgonTiming.Delta);

                        _bufferStream.Write(rnd);
                    }

                    _bufferStream.Position = 0;
                    // ReSharper disable AccessToDisposedClosure
                    buffer.Update(_bufferStream);
                    // ReSharper restore AccessToDisposedClosure

                    return(false);
                };

                _framework.Run();
            }
        }
예제 #4
0
        public void TestComputeShader()
        {
            _framework.CreateTestScene(BaseShaders, BaseShaders, true, true);

            using (var compShader = _framework.Graphics.Shaders.CreateShader <GorgonComputeShader>("CompShader",
                                                                                                   "TestCS",
                                                                                                   BaseShaders))
            {
                var cbuffer = _framework.Graphics.Buffers.CreateConstantBuffer("CBuffer", new GorgonConstantBufferSettings
                {
                    SizeInBytes = 16
                });
                var cbuffer2 = _framework.Graphics.Buffers.CreateConstantBuffer("CBuffer2", new GorgonConstantBufferSettings
                {
                    SizeInBytes = 16
                });



                var view = ((GorgonTexture2D)_framework.Screen).GetUnorderedAccessView(BufferFormat.R8G8B8A8_UIntNormal);

                _framework.Screen.AfterSwapChainResized += (sender, e) =>
                {
                    view = ((GorgonTexture2D)_framework.Screen).GetUnorderedAccessView(BufferFormat.R8G8B8A8_UIntNormal);
                    using (var data = new GorgonDataStream(16))
                    {
                        data.Write(new Vector2(e.Width, e.Height));
                        data.Position = 0;
                        cbuffer.Update(data);
                    }
                };

                var texture = _framework.Graphics.Textures.CreateTexture <GorgonTexture2D>("Test", Resources.Glass,
                                                                                           new GorgonGDIOptions
                {
                    AllowUnorderedAccess = true,
                    Format =
                        BufferFormat.R8G8B8A8_UIntNormal
                });
                var test    = new Vector3(GorgonRandom.RandomSingle(0, 180.0f), GorgonRandom.RandomSingle(0, 180.0f), GorgonRandom.RandomSingle(0, 180.0f));
                var speed   = new Vector3(GorgonRandom.RandomSingle(5, 45), GorgonRandom.RandomSingle(5, 45), GorgonRandom.RandomSingle(5, 45));
                var testDir = new Vector3(1);
                _framework.IdleFunc = () =>
                {
                    //_framework.Screen.Clear(GorgonColor.White);
                    _framework.Graphics.Output.SetRenderTarget(null);
                    _framework.Graphics.Shaders.PixelShader.Resources[0] = null;

                    _framework.Graphics.Shaders.ComputeShader.Current                 = compShader;
                    _framework.Graphics.Shaders.ComputeShader.ConstantBuffers[0]      = cbuffer;
                    _framework.Graphics.Shaders.ComputeShader.ConstantBuffers[1]      = cbuffer2;
                    _framework.Graphics.Shaders.ComputeShader.UnorderedAccessViews[0] = view;
                    _framework.Graphics.Shaders.ComputeShader.Dispatch((_framework.Screen.Settings.Width + 10) / 10,
                                                                       (_framework.Screen.Settings.Height + 10) / 10, 1);

                    _framework.Graphics.Shaders.ComputeShader.UnorderedAccessViews[0] = null;
                    _framework.Graphics.Output.SetRenderTarget(_framework.Screen);

                    _framework.Graphics.Shaders.PixelShader.Resources[0] = texture;

                    test += Vector3.Modulate(testDir * GorgonTiming.Delta, speed);

                    /*if ((test >= 1.0f) || (test <= 0.0f))
                     * {
                     *      testDir *= -1.0f;
                     * }*/

                    if ((test.X > 359.9f) || (test.X <= 0.0f))
                    {
                        test.X     = test.X - 359.9f * -testDir.X;
                        speed.X    = GorgonRandom.RandomSingle(5, 180.0f);
                        testDir.X *= -1.0f;
                    }

                    if ((test.Y > 359.9f) || (test.Y <= 0.0f))
                    {
                        test.Y     = test.Y - 359.9f * -testDir.X;
                        speed.Y    = GorgonRandom.RandomSingle(5, 180);
                        testDir.Y *= -1.0f;
                    }

                    if ((test.Z > 359.9f) || (test.Z <= 0.0f))
                    {
                        test.Z     = test.Z - 359.9f * -testDir.Y;
                        speed.Z    = GorgonRandom.RandomSingle(5, 180);
                        testDir.Z *= -1.0f;
                    }

                    var animVal = new Vector3(test.X.Radians().Cos(), test.Y.Radians().Sin(), test.Z.Radians().Cos() * test.Z.Radians().Cos());
                    cbuffer2.Update(ref animVal);

                    return(false);
                };

                Assert.IsTrue(_framework.Run() == DialogResult.Yes);
            }
        }