コード例 #1
0
ファイル: GameScreen.cs プロジェクト: MyEyes/Igorr
        public void Initialize(GraphicsDevice Device, ScreenManager manager)
        {
            GraphicsDevice = Device;
            spriteBatch = new SpriteBatch(Device);
            cam = new Camera(new Vector2(520, 440), new Rectangle(0, 0, 800, 600));

            _lightMap = new LightMap(Device);

            MapManager.LoadMaps(Device);
            //map = MapManager.GetMapByID(0);
            objectManager = new ObjectManager(map);
            objectManager.SetLight(_lightMap);
            pm = new ParticleManager();
            TextManager.SetUp(ContentInterface.LoadFont("font"));
            Player.font = ContentInterface.LoadFont("font");
            font = ContentInterface.LoadFont("font");
            bar = ContentInterface.LoadTexture("White");
            expBorder = ContentInterface.LoadTexture("ExpBar");
            crosshair = ContentInterface.LoadTexture("Crosshair");
            _spriteEffect = ContentInterface.LoadShader("ShadowEffect");
            _spriteEffect.CurrentTechnique = _spriteEffect.Techniques["Sprite"];
            _manager = manager;

            _mapMutex = new System.Threading.Mutex();

            input = new InputManager();

            WorldController.SetObjectManager(objectManager);
            WorldController.SetGame(this);
            WorldController.Start();
            _GUIOverlay = new UI.GUIScreen();
            manager.AddScreen(_GUIOverlay);
        }
コード例 #2
0
ファイル: LightMap.cs プロジェクト: MyEyes/Igorr
        public LightMap(GraphicsDevice device)
        {
            this.device = device;
            LightReference = this;
            //Four triangles per shadow three shadows per block so 4*3*3*maxX*maxY
            shadowIB = new IndexBuffer(device, IndexElementSize.SixteenBits, 4 * 3 * 3 * maxX * maxY, BufferUsage.WriteOnly);
            short[] indices = new short[4 * 3 * 3 * maxX * maxY];
            for (int x = 0; x < 4 * 3 * 3 * maxX * maxY; x += 12)
            {
                short offset = (short)(6 * x / 12);
                indices[x] = (short)(offset);
                indices[x + 1] = (short)(offset + 1);
                indices[x + 2] = (short)(offset + 4);

                indices[x + 3] = (short)(offset + 1);
                indices[x + 4] = (short)(offset + 2);
                indices[x + 5] = (short)(offset + 4);

                indices[x + 6] = (short)(offset + 2);
                indices[x + 7] = (short)(offset + 5);
                indices[x + 8] = (short)(offset + 4);

                indices[x + 9] = (short)(offset + 2);
                indices[x + 10] = (short)(offset + 3);
                indices[x + 11] = (short)(offset + 5);
            }
            shadowIB.SetData<short>(indices);
            shadowVB = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, 6 * 3 * maxX * maxY, BufferUsage.WriteOnly);
            shadowEffect = ContentInterface.LoadShader("ShadowEffect");
            shadowTarget = new RenderTarget2D(device, device.PresentationParameters.BackBufferWidth/lightMapDownSample, device.PresentationParameters.BackBufferHeight/lightMapDownSample, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 1, RenderTargetUsage.DiscardContents);
            shadowTarget2 = new RenderTarget2D(device, device.PresentationParameters.BackBufferWidth / lightMapDownSample, device.PresentationParameters.BackBufferHeight / lightMapDownSample, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 1, RenderTargetUsage.DiscardContents);
            blendShadow = new BlendState();
            blendShadow.ColorWriteChannels = ColorWriteChannels.All;
            blendShadow.ColorBlendFunction = BlendFunction.Add;
            blendShadow.ColorDestinationBlend = Blend.SourceColor;
            blendShadow.ColorSourceBlend = Blend.Zero;

            //Write to stencil buffer
            generateShadow = new BlendState();
            generateShadow.ColorSourceBlend = Blend.Zero;
            generateShadow.ColorDestinationBlend = Blend.One;
            generateShadow.ColorWriteChannels = ColorWriteChannels.None;

            generateShadow2 = new BlendState();
            generateShadow2.ColorBlendFunction = BlendFunction.Min;
            generateShadow2.ColorSourceBlend = Blend.One;
            generateShadow2.ColorDestinationBlend = Blend.One;
            generateShadow2.ColorWriteChannels = ColorWriteChannels.All;

            addLight = new BlendState();
            addLight.ColorBlendFunction = BlendFunction.Add;
            addLight.ColorSourceBlend = Blend.One;
            addLight.ColorDestinationBlend = Blend.One;
            addLight.ColorWriteChannels = ColorWriteChannels.All;

            generateShadowStencil = new DepthStencilState();
            generateShadowStencil.StencilEnable = true;
            generateShadowStencil.DepthBufferEnable = false;
            generateShadowStencil.ReferenceStencil = 1;
            generateShadowStencil.StencilFunction = CompareFunction.Equal;
            generateShadowStencil.StencilPass = StencilOperation.Increment;

            preventShadowStencil = new DepthStencilState();
            preventShadowStencil.StencilEnable = true;
            preventShadowStencil.DepthBufferEnable = false;
            preventShadowStencil.ReferenceStencil = 1;
            preventShadowStencil.StencilFunction = CompareFunction.Equal;
            preventShadowStencil.StencilPass = StencilOperation.Decrement;

            drawShadowedLight = new DepthStencilState();
            drawShadowedLight.DepthBufferEnable = false;
            drawShadowedLight.StencilEnable = true;
            drawShadowedLight.ReferenceStencil = 1;
            drawShadowedLight.StencilFunction = CompareFunction.GreaterEqual;

            disableShadows = new DepthStencilState();
            disableShadows.DepthBufferEnable = false;
            disableShadows.StencilEnable = true;
            disableShadows.StencilFunction = CompareFunction.Always;
            disableShadows.ReferenceStencil = 1;
            disableShadows.StencilPass = StencilOperation.Zero;

            maxLightState = new BlendState();
            maxLightState.ColorBlendFunction = BlendFunction.Max;
            maxLightState.ColorDestinationBlend = Blend.One;
            maxLightState.ColorSourceBlend = Blend.One;

            clearStencil = new DepthStencilState();
            clearStencil.StencilEnable = true;
            clearStencil.StencilFunction = CompareFunction.Always;
            clearStencil.ReferenceStencil = 1;
            clearStencil.StencilPass = StencilOperation.Replace;

            if (clearVBuffer == null)
            {
                clearVBuffer = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, 4, BufferUsage.None);
                clearIBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, 6, BufferUsage.None);
                clearIBuffer.SetData<short>(new short[] { 0, 1, 2, 2, 3, 0 });
                clearVBuffer.SetData<VertexPositionColor>(new VertexPositionColor[]
                {
                    new VertexPositionColor(new Vector3(-1,-1,0), new Color(new Vector3(0,0,0))),
                    new VertexPositionColor(new Vector3(1,-1,0), new Color(new Vector3(1,0,0))),
                    new VertexPositionColor(new Vector3(1,1,0), new Color(new Vector3(1,1,0))),
                    new VertexPositionColor(new Vector3(-1,1,0), new Color(new Vector3(0,1,0)))
                });
            }

            if (rotateLeft == Matrix.Identity)
            {
                rotateLeft = Matrix.CreateRotationZ(0 * MathHelper.Pi / 180);
                rotateRight = Matrix.CreateRotationZ(0 * MathHelper.Pi / 180);
            }
            _unusedTexture=new Texture2D(device, 1,1);

            shadowEffect.Parameters["xTexelDist"].SetValue(1.0f / (device.PresentationParameters.BackBufferWidth/lightMapDownSample));
            shadowEffect.Parameters["yTexelDist"].SetValue(1.0f / (device.PresentationParameters.BackBufferHeight/lightMapDownSample));

            _lightMutex = new Mutex();
        }
コード例 #3
0
ファイル: ObjectManager.cs プロジェクト: MyEyes/Igorr
 public void SetLight(LightMap light)
 {
     _light = light;
 }