Esempio n. 1
0
        /// <summary>
        /// Generate the shadow map for a given spot light
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="meshes"></param>
        /// <param name="light"></param>
        /// <param name="shadowMap"></param>
        public void GenerateShadowTextureSpotLight(Renderer renderer, BaseSceneGraph renderWorld, Light light, SpotShadowMapEntry shadowMap)
        {
            //bind the render target
            renderer.GraphicsDevice.SetRenderTarget(shadowMap.Texture);
            //clear it to white, ie, far far away
            renderer.GraphicsDevice.Clear(Color.White);
            renderer.GraphicsDevice.BlendState = BlendState.Opaque;
            renderer.GraphicsDevice.DepthStencilState = DepthStencilState.Default;


            Matrix viewProj = light.ViewProjection;
            shadowMap.LightViewProjection = viewProj;

            BoundingFrustum frustum = light.Frustum;

            _visibleMeshes.Clear();
            //cull meshes outside the light volume
            renderWorld.GetShadowCasters(frustum, _visibleMeshes);

            renderer.InstancingGroupManager.Reset();
            for (int index = 0; index < _visibleMeshes.Count; index++)
            {
                Mesh.SubMesh subMesh = _visibleMeshes[index];
                //render it
                if (!subMesh.InstanceEnabled)
                    subMesh.RenderShadowMap(ref viewProj, renderer.GraphicsDevice);
                else
                    renderer.InstancingGroupManager.AddInstancedSubMesh(subMesh);
            }
            renderer.InstancingGroupManager.GenerateInstanceInfo(renderer.GraphicsDevice);
            renderer.InstancingGroupManager.RenderShadowMap(ref viewProj, renderer.GraphicsDevice);
        }
        public void RenderEffect(Renderer renderer, GraphicsDevice device)
        {
            RenderTarget2D half0 = renderer.HalfDepth;
            //render to a half-res buffer
            device.SetRenderTarget(half0);

            Apply();

            device.BlendState = BlendState.Opaque;
            device.DepthStencilState = DepthStencilState.None;
            _quadRenderer.RenderQuad(device, -Vector2.One, Vector2.One);

        }
Esempio n. 3
0
 public ShadowRenderer(Renderer renderer)
 {
     //create the render targets
     for (int i = 0; i < NUM_SPOT_SHADOWS; i++)
     {
         SpotShadowMapEntry entry = new SpotShadowMapEntry();
         //we store the linear depth, in a float render target. We need also the HW zbuffer
         entry.Texture = new RenderTarget2D(renderer.GraphicsDevice, SPOT_SHADOW_RESOLUTION,
                                            SPOT_SHADOW_RESOLUTION, false, SurfaceFormat.Single,
                                            DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);
         entry.LightViewProjection = Matrix.Identity;
         _spotShadowMaps.Add(entry);
     }
 }
Esempio n. 4
0
        //players = 1 or 2
        //sections = 1,2 or 3 (small, medium, long) ---> has scaling factor. default set to 6
        //difficulty = 1, 2, or 3 (easy, medium, hard)
        public GameLayer(int players, int numSections, int difficulty) : base()
        {
            cooloffBlue = 2000;
            cooloffGreen = 2000;
            // Screen layer attributes
            numPlayers = players;
            numSectionScalingFactor = 6;
            isTransparent = false;
            transitionOnTime = TimeSpan.FromSeconds(0.6);
            transitionOffTime = TimeSpan.FromSeconds(0.5);

            // 3D view vars
            viewport = Globals.graphics.GraphicsDevice.Viewport;

            // drawable layers
            canvas = new SpriteBatch(Globals.graphics.GraphicsDevice);
            game3DLayer = new RenderTarget2D(
                Globals.graphics.GraphicsDevice,
                viewport.Width,
                viewport.Height,
                false,
                SurfaceFormat.Color,
                DepthFormat.Depth24,
                0,
                RenderTargetUsage.DiscardContents);

            // Create the renderer, this renderer binds to the graphics device and with the given width and height, is used to 
            // draw everything on each frame
            renderer = new Renderer(Globals.graphics.GraphicsDevice, Globals.content, viewport.Width, viewport.Height);

            // The light and mesh container is used to store mesh and light obejcts. This is just for RENDERING. Not for DRAWING
            sceneGraph = new BlockBasedSceneGraph(numSections * numSectionScalingFactor);
            sceneGraph.SetSubMeshDelegate(delegate(Mesh.SubMesh subMesh) 
            {                
                renderer.SetupSubMesh(subMesh);
                subMesh.RenderEffect.AmbientParameter.SetValue(Vector4.Zero);
            });
            sceneGraph.SetLightDelegate(delegate(Light l) { });

            // Load the Game
            //second number is number of players
            
            Globals.gameInstance = new RealGame(numSections * numSectionScalingFactor, numPlayers, sceneGraph);

            cameraController = new CameraController(viewport, Matrix.Identity);
            cameraController.Fit(Globals.gameInstance.GetCriticalPoints());
            cameraController.MoveToTarget();            
        }
        public void Init(ContentManager contentManager, Renderer renderer)
        {
            try
            {
                _effect = contentManager.Load<Effect>("shaders/DownsampleDepth");
                ExtractParameters();
                Vector2 pixelSize = new Vector2(1.0f / (float)renderer.DepthBuffer.Width, 1.0f / (float)renderer.DepthBuffer.Height);
                PixelSize.SetValue(pixelSize);
                HalfPixel.SetValue(pixelSize * 0.5f);
                DepthBuffer.SetValue(renderer.DepthBuffer);

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error loading downsample depth efect: " + ex.ToString());
            }
        }
Esempio n. 6
0
        //construct
        public MenuBackground()
        {
            viewport = Globals.graphics.GraphicsDevice.Viewport;

            // Create the renderer, this renderer binds to the graphics device and with the given width and height, is used to 
            // draw everything on each frame
            renderer = new Renderer(Globals.graphics.GraphicsDevice, Globals.content, viewport.Width, viewport.Height);

            // The light and mesh container is used to store mesh and light obejcts. This is just for RENDERING. Not for DRAWING
            lightAndMeshContainer = new SimpleSceneGraph(); 
            lightAndMeshContainer.SetSubMeshDelegate(delegate(Mesh.SubMesh subMesh)
            {
                renderer.SetupSubMesh(subMesh);
                subMesh.RenderEffect.AmbientParameter.SetValue(Vector4.Zero);
            });
            lightAndMeshContainer.SetLightDelegate(delegate(Light l) { });

            camera = new Camera();
            camera.Aspect = viewport.AspectRatio;
            camera.NearClip = 0.1f;
            camera.FarClip = 1000;
            camera.Viewport = viewport;
            camera.Transform = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(170),-0.3f,0) * Matrix.CreateTranslation(2,5f,-4);

            Mesh m = new Mesh();
            m.Model = AssetLoader.mdl_menuscene;
            m.Transform = Matrix.Identity;
            lightAndMeshContainer.AddMesh(m);

            Light mainlight = new Light();
            mainlight.LightType = Light.Type.Spot;
            mainlight.Color = Color.AntiqueWhite;
            mainlight.Transform = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(170),-0.7f,0) * Matrix.CreateTranslation(0, 5f, -4);
            mainlight.SpotAngle = 50;
            mainlight.SpotExponent = 1;
            mainlight.Radius = 13;
            mainlight.Intensity = 2f;
            lightAndMeshContainer.AddLight(mainlight);
        }