コード例 #1
0
            public void Render()
            {
                angle += MathHelper.Pi * game.Elapsed;
                point.LightPosition = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2);

                ctx.ClearState();
                combineFinal.SetLightAccumulationStates();
                combineFinal.ClearLightAccumulation();
                point.Draw();

                ctx.ClearState();
                game.SetBackbuffer();
                ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300));

                combineFinal.DrawCombined();


                game.SetBackbuffer();
                GBufferTest.DrawGBuffer(game, buffer);
            }
コード例 #2
0
        private void drawLights(CombineFinalRenderer finalRenderer)
        {
            finalRenderer.ClearLightAccumulation();

            // Possibly do all shadowmap up front, even cache some shadow maps.

            for (int i = 0; i < directionalLights.Count; i++)
            {
                var l = directionalLights[i];
                var r = directionalLightRenderer;
                setDirectionalLightToRenderer(r, l);

                if (l.ShadowsEnabled)
                {
                    updateDirectionalShadows(r, l.ShadowViews);
                }
                finalRenderer.SetLightAccumulationStates();

                r.Draw();
            }


            pointLightRenderer.NextShadowUpdate--;



            for (int i = 0; i < pointLights.Count; i++)
            {
                var l = pointLights[i];
                var r = pointLightRenderer;
                setPointLightToRenderer(r, l);


                if (pointLightRenderer.NextShadowUpdate <= 0)
                {
                    if (l.ShadowsEnabled)
                    {
                        updatePointShadows(r, l.Views);
                    }
                }

                finalRenderer.SetLightAccumulationStates();

                r.Draw();
            }
            if (pointLightRenderer.NextShadowUpdate <= 0)
            {
                pointLightRenderer.NextShadowUpdate = pointLightRenderer.ShadowUpdateInterval;
            }

            for (int i = 0; i < spotLights.Count; i++)
            {
                var l = spotLights[i];
                var r = spotLightRenderer;
                setSpotLightToRenderer(r, l);

                if (l.ShadowsEnabled)
                {
                    updateSpotShadows(r, l.ShadowView);
                }

                finalRenderer.SetLightAccumulationStates();

                r.Draw();
            }
        }
コード例 #3
0
        public void drawMeshTest(IMesh mesh, Matrix worldMatrix)
        {
            var game = createGame();


            var pool = createTexturePool(game);

            var worldMesh = new WorldMesh {
                Mesh = mesh, WorldMatrix = worldMatrix
            };

            var meshes = new MeshesRenderer(new RendererResourcePool(new MeshRenderDataFactory(game, null, pool), pool, game), game);


            var ctx = game.Device.ImmediateContext;

            var gBuffer = createGBuffer(game);
            var scene   = new RenderingTestsHelper.SimpleLightedScene(game, gBuffer);


            var list = new List <WorldMesh>();

            list.Add(worldMesh);

            var buffer = gBuffer;

            ctx = game.Device.ImmediateContext;
            // Non-related init code

            var point = new PointLightRenderer(game, buffer);

            point.LightRadius    = 3;
            point.LightIntensity = 1;
            point.ShadowsEnabled = false;

            var angle = 0f;

            var combineFinal = new CombineFinalRenderer(game, buffer);

            var raster = new RasterizerStateDescription()
            {
                CullMode = CullMode.Front,
                FillMode = FillMode.Solid
            };

            var state = RasterizerState.FromDescription(game.Device, raster);

            point.LightRadius = 10;

            game.GameLoopEvent += delegate
            {
                ctx.ClearState();
                ctx.Rasterizer.State = state;
                gBuffer.Clear();
                gBuffer.SetTargetsToOutputMerger();

                meshes.DrawMeshes(list, game.Camera);

                angle += MathHelper.Pi * game.Elapsed;

                var alpha = 0.99f * game.Elapsed * 20000;

                var cam  = game.Camera.ViewInverse.GetTranslation();
                var diff = cam - point.LightPosition;
                diff.Normalize();


                point.LightPosition += diff * game.Elapsed * 2;// new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2);

                ctx.ClearState();
                combineFinal.SetLightAccumulationStates();
                combineFinal.ClearLightAccumulation();
                point.Draw();

                ctx.ClearState();
                game.SetBackbuffer();
                ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300));

                combineFinal.DrawCombined();


                game.SetBackbuffer();
                GBufferTest.DrawGBuffer(game, buffer);
            };

            game.Run();
        }
コード例 #4
0
            public void DrawUpdatedDeferredRendering()
            {
                FilledGBuffer.DrawUpdatedGBuffer();


                if (game.Keyboard.IsKeyPressed(Key.D1))
                {
                    state = 0;
                }
                if (game.Keyboard.IsKeyPressed(Key.D2))
                {
                    state = 1;
                }
                if (game.Keyboard.IsKeyPressed(Key.D3))
                {
                    state = 2;
                }
                if (game.Keyboard.IsKeyPressed(Key.D4))
                {
                    state = 3;
                }

                switch (state)
                {
                case 0:
                    break;

                case 1:
                    directional.LightDirection = game.SpectaterCamera.CameraDirection;
                    break;

                case 2:
                    point.LightPosition = game.SpectaterCamera.CameraPosition;

                    break;

                case 3:
                    spot.LightPosition = game.SpectaterCamera.CameraPosition;
                    spot.SpotDirection = game.SpectaterCamera.CameraDirection;
                    break;
                }



                if (game.Keyboard.IsKeyDown(Key.I))
                {
                    context.ClearState();
                    game.SetBackbuffer();
                    GBufferTest.DrawGBuffer(game, FilledGBuffer.GBuffer);
                }
                else
                {
                    combineFinal.ClearLightAccumulation();
                    combineFinal.SetLightAccumulationStates();
                    directional.Draw();
                    spot.Draw();
                    point.Draw();



                    context.ClearState();
                    game.SetBackbuffer(); // This is to set viewport, not sure this is correct

                    context.OutputMerger.SetTargets(hdrImageRTV);
                    DrawCombined();
                }



                if (game.Keyboard.IsKeyPressed(Key.O))
                {
                    Resource.SaveTextureToFile(game.Device.ImmediateContext, hdrImage, ImageFileFormat.Dds,
                                               TWDir.Test.CreateSubdirectory("Deferred") + "\\HdrImage.dds");
                }
            }