Exemplo 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);
        }
Exemplo n.º 2
0
        public void Construct(Vector3 center)
        {
            this._position = center;
            this._rotation = (float)Globals.random.NextDouble();

            this.mesh = new Mesh();
            this.mesh.Model = AssetLoader.mdl_weapon_depot;
            this.mesh.Transform = Matrix.CreateTranslation(_position);

            this.gunindex = -1;
            this.gunmesh = null;
            this.gunmeshReceipt = null;

            Globals.gameInstance.sceneGraph.Setup(this.mesh);
            Globals.gameInstance.sceneGraph.Add(this.mesh);

            this.light = new Light();
            this.light.LightType = Light.Type.Point;
            this.light.Radius = 3;
            this.light.Intensity = 0.4f;
            this.light.Color = Color.White;
            this.light.Transform = Matrix.CreateTranslation(this._position + Vector3.Up * 2);
            this.light.Enabled = false;

            Globals.gameInstance.sceneGraph.Setup(this.light);
            Globals.gameInstance.sceneGraph.Add(this.light);

        }
Exemplo n.º 3
0
        public Door(Vector3 position)
        {
            this.position = position;

            doorBaseMesh = new Mesh();
            doorBaseMesh.Model = AssetLoader.mdl_doorBase;
            doorBaseMesh.Transform = FLIP90Y * Matrix.CreateTranslation(position);

            doorLeftMesh = new Mesh();
            doorLeftMesh.Model = AssetLoader.mdl_doorPanel;
            doorLeftMesh.Transform = FLIP90Y * Matrix.CreateTranslation(position);

            doorRightMesh = new Mesh();
            doorRightMesh.Model = AssetLoader.mdl_doorPanel;
            doorRightMesh.Transform = FLIP180X * FLIP90Y * Matrix.CreateTranslation(position + new Vector3(0, 2.5f, 0));

            Globals.gameInstance.sceneGraph.Setup(doorBaseMesh);
            Globals.gameInstance.sceneGraph.Add(doorBaseMesh);
            Globals.gameInstance.sceneGraph.Setup(doorLeftMesh);
            Globals.gameInstance.sceneGraph.Add(doorLeftMesh);
            Globals.gameInstance.sceneGraph.Setup(doorRightMesh);
            Globals.gameInstance.sceneGraph.Add(doorRightMesh);

            lightLeft = new Light();
            lightLeft.LightType = Light.Type.Point;
            lightLeft.Color = Color.Red;
            lightLeft.Radius = 2;
            lightLeft.Transform = Matrix.CreateTranslation(position + new Vector3(-0.6f, 1.5f, -1.4f));

            lightRight = new Light();
            lightRight.LightType = Light.Type.Point;
            lightRight.Color = Color.Red;
            lightRight.Radius = 2;
            lightRight.Transform = Matrix.CreateTranslation(position + new Vector3(-0.6f, 1.5f, 1.4f));

            Globals.gameInstance.sceneGraph.Add(lightRight);
            Globals.gameInstance.sceneGraph.Add(lightLeft);

            state = DoorState.CLOSED;
            openPercent = MINOPEN;
            UpdatePanelPositions();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public void AddOverheadLight(Light o)
 {
     _overheadLights.Add(o);
 }
Exemplo n.º 6
0
        public void SetupLights()
        {

            torchlight = new Light();
            torchlight.LightType = Light.Type.Spot;
            torchlight.ShadowDepthBias = 0.002f;
            torchlight.Radius = 15;
            torchlight.SpotAngle = TORCH_ANGLE;
            torchlight.Intensity = 1.0f;
            torchlight.SpotExponent = 6;
            torchlight.Color = color*1.1f;
            torchlight.CastShadows = true;
            torchlight.Transform = Matrix.Identity;

            halolight = new Light();
            halolight.LightType = Light.Type.Spot;
            halolight.ShadowDepthBias = 0.001f;
            halolight.Radius = HALO_HEIGHT+1;
            halolight.SpotAngle = 35;
            halolight.SpotExponent = 0.6f;
            halolight.Intensity = 0.8f;
            halolight.Color = color;
            halolight.CastShadows = true;
            halolight.Transform = Matrix.Identity;

            haloemitlight = new Light();
            haloemitlight.LightType = Light.Type.Point;
            haloemitlight.Intensity = 0.6f;
            haloemitlight.Radius = 3;
            haloemitlight.Color = color * 1.4f;
            haloemitlight.Transform = Matrix.Identity;
            haloemitlight.SpecularIntensity = 3;

        }
Exemplo n.º 7
0
        public static Light SpawnOverheadLight(Vector3 position)
        {
            Mesh m = new Mesh();
            m.Model = AssetLoader.mdl_ceilinglight;
            m.Transform = Matrix.CreateTranslation(position + Vector3.Up * 4);
            Globals.gameInstance.sceneGraph.Add(m);

            Light l = new Light();
            l.LightType = Light.Type.Point;
            l.Radius = 7;
            l.Intensity = 0.4f;
            l.Enabled = false;
            
            l.Transform = Matrix.CreateTranslation(position + Vector3.Up * 4);
            Globals.gameInstance.sceneGraph.Add(l);

            return l;
        }