예제 #1
0
        public void CreateDifferentRasteriserStatesWithNinjectUsingNamedBindings()
        {
            //Given
            SharpDX.Toolkit.Graphics.GraphicsDevice device = SharpDX.Toolkit.Graphics.GraphicsDevice.New(DeviceCreationFlags.Debug);
            IKernel kernal = new StandardKernel();

            kernal.Bind <SharpDXGraphicsDevice>().ToSelf().InSingletonScope();
            kernal.Bind <DefaultRasteriserState>().ToSelf().InSingletonScope();
            kernal.Bind <ShadowBiasedDepthRasteriserState>().ToSelf().InSingletonScope();

            kernal.Bind <FearGraphicsDevice>().ToConstant <SharpDXGraphicsDevice>(new SharpDXGraphicsDevice(GraphicsDevice.New(DeviceCreationFlags.Debug)));
            kernal.Bind <RasteriserState>().To <DefaultRasteriserState>().Named("Default");
            kernal.Bind <RasteriserState>().To <ShadowBiasedDepthRasteriserState>().Named("ShadowBiasedDepth");

            //When
            RasteriserState state = kernal.Get <RasteriserState>("Default");

            //Then
            Assert.IsTrue(state.GetType() == typeof(DefaultRasteriserState));

            //When
            state = kernal.Get <RasteriserState>("ShadowBiasedDepth");

            //Then
            Assert.IsTrue(state.GetType() == typeof(ShadowBiasedDepthRasteriserState));
        }
예제 #2
0
        public BasicShadowTechnique(FearGraphicsDevice dev,
                                    FearResourceManager resMan,
                                    [Named("ShadowBiasedDepth")] RasteriserState depthRasState,
                                    [Named("ShadowMapComparison")] FearEngine.DeviceState.SamplerStates.SamplerState samp)
        {
            device = dev.Device;

            depthMaterial = resMan.GetMaterial("DepthWrite");

            depthRS = depthRasState;

            sampler = samp;
        }
예제 #3
0
        public void CreateRasteriserStateWithNinject()
        {
            //Given
            IKernel kernal = new StandardKernel();

            kernal.Bind <SharpDXGraphicsDevice>().ToSelf().InSingletonScope();
            kernal.Bind <DefaultRasteriserState>().ToSelf().InSingletonScope();

            kernal.Bind <FearGraphicsDevice>().ToConstant <SharpDXGraphicsDevice>(new SharpDXGraphicsDevice(GraphicsDevice.New(DeviceCreationFlags.Debug)));
            kernal.Bind <RasteriserState>().To <DefaultRasteriserState>();

            //When
            RasteriserState state = kernal.Get <RasteriserState>();

            //Then
            Assert.IsTrue(state.GetType() == typeof(DefaultRasteriserState));
        }
예제 #4
0
        static void Main(string[] args)
        {
            var canvas = new ExampleBase.GraphicsCanvas();

            // Create the renderer
            var renderer = new Fe.Renderer();

            // Set the handle from our form so we let Fe create context/devices as appropriate.
            renderer.SetWindowHandle(canvas.Handle);

            // Initialise the renderer
            renderer.Init();

            // Create geometry layer command bucker
            var geometryBucket = renderer.AddCommandBucket(UInt16.MaxValue);

            // Create the shaders
            Fe.Shader vertexShader, fragmentShader;
            switch (renderer.GetRendererType())
            {
            case Fe.RendererType.OpenGL:
                vertexShader   = new Fe.Shader(Fe.ShaderType.Vertex, File.ReadAllText("default.vert"));
                fragmentShader = new Fe.Shader(Fe.ShaderType.Fragment, File.ReadAllText("default.frag"));
                break;

            default:
                throw new Exception("Unknown backend renderer type");
            }

            Fe.ShaderProgram program = new ShaderProgram(vertexShader, fragmentShader);

            // Build plane data
            var plane = new Fe.Extra.Geometry.Plane(30, 30, 30, 30);

            PosColorVertex[] vertices = new PosColorVertex[plane.Vertices.Length / 3];

            Random rand   = new Random();
            int    i      = 0;
            int    offset = 0;

            for (i = 0; i < vertices.Length; i++)
            {
                vertices[i].x    = plane.Vertices[offset];
                vertices[i].y    = plane.Vertices[offset + 1];
                vertices[i].z    = plane.Vertices[offset + 2];
                vertices[i].abgr = (uint)(rand.Next(1 << 30)) << 2 | (uint)(rand.Next(1 << 2));;

                offset += 3;
            }

            // Create vertex buffer for our cube
            var vb = new Fe.VertexBuffer <PosColorVertex>(vertices, true);
            var ib = new Fe.IndexBuffer(plane.Indices);

            // Create shared uniforms
            Fe.Uniform projectionUniform = new Fe.Uniform("projectionMatrix", Fe.UniformType.Matrix4x4f);

            Fe.UniformBuffer sharedUniforms = new Fe.UniformBuffer();

            // Turn off face culling.
            var rs = new RasteriserState(CullMode.None);

            Stopwatch frameTimer = Stopwatch.StartNew();
            double    frameTime  = 0;
            float     rotTime    = 0.0f;
            float     waveyTime  = 0.0f;

            canvas.Title = "Dynamic vertex buffer update example";

            void Resize(int width, int height)
            {
                // Set up a projection matrix
                var projectionMatrix = Nml.Matrix4x4.PerspectiveProjectionRH(Nml.Common.Pi / 4, (float)width / (float)height, 0.1f, 100.0f);

                projectionMatrix *= Nml.Matrix4x4.Translate(0, 0, -50.0f);
                sharedUniforms.Set(projectionUniform, projectionMatrix.ToArray());

                renderer.Reset(width, height);
            }

            // Force an Initial resize, you could handle this with some event on your window if you wanted.
            Resize(canvas.Width, canvas.Height);

            void Cleanup()
            {
                // Kill off the renderer and clean up all underlying resources.
                renderer.Dispose();
            }

            void Update()
            {
                frameTime = frameTimer.Elapsed.TotalMilliseconds;
                frameTimer.Restart();

                // Increase the animation
                rotTime   += (float)frameTime * 0.0010f;
                waveyTime += (float)frameTime * 0.01f;

                var cubeCommand = geometryBucket.AddCommand(1);

                cubeCommand.SetShaderProgram(program);
                cubeCommand.SetVertexBuffer(vb);
                cubeCommand.SetIndexBuffer(ib);
                cubeCommand.SetSharedUniforms(sharedUniforms);
                cubeCommand.SetRasteriserState(rs);

                // Generate new vertice positionsd
                for (i = 0; i < vertices.Length; i++)
                {
                    float newPos = (float)Math.Sin(waveyTime + i) * 1.5f;
                    vertices[i].z = newPos;
                }

                // Update the buffer
                vb.SetData(vertices);

                Nml.Matrix4x4 planeTransform = Nml.Matrix4x4.Identity;
                // Rotate it to make look pretty
                Nml.Quaternion rotQuat;
                Nml.Quaternion.RotateEuler(0, rotTime * 0.37f, rotTime * 0.13f, out rotQuat);
                Nml.Quaternion.GetMatrix4x4(ref rotQuat, out planeTransform);

                cubeCommand.SetTransform(planeTransform.ToArray());

                // Submit current commands queued to the renderer for rendering.
                renderer.EndFrame();
            }

            canvas.Resize += () =>
            {
                Resize(canvas.Width, canvas.Height);
            };

            canvas.Closing += () =>
            {
                Cleanup();
            };

            ExampleBase.Application.Run(canvas, () =>
            {
                Update();
            });
        }