コード例 #1
0
        public void renderLightMap(List <GameObject> gobs, List <InstanceDescriptor> insts)
        {
            ConvexHull.InitializeStaticMembers(GraphicsDevice);

            EffectParameter widthParameter  = lightEffect.Parameters["screenWidth"];
            EffectParameter heightParameter = lightEffect.Parameters["screenHeight"];


            setShaderValue(widthParameter, lightMapTarget.Width);
            setShaderValue(heightParameter, lightMapTarget.Height);


            GraphicsDevice.SetRenderTarget(lightMapTarget);

            GraphicsDevice.Clear(XnaColor.Transparent);

            insts.ForEach(i =>
            {
                if (i.Light.Visible)
                {
                    ClearAlphaToOne();


                    GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                    GraphicsDevice.BlendState      = CustomBlendStates.MultiplyShadows;

                    //shadowing algorithm taken from http://www.catalinzima.com/xna/samples/dynamic-2d-shadows/
                    if (Level.PreviewShadowing)
                    {
                        insts.ForEach(hull =>
                        {
                            if (hull.Shadows.CastsShadows)
                            {
                                Boolean pass = hull != i;
                                if (i.Shadows.SelfShadows)
                                {
                                    pass = true;
                                }

                                if (pass)
                                {
                                    Convex convex   = hull.Bounds.Convex;
                                    convex.Origin   = hull.Position;
                                    convex.Rotation = hull.Sprite.Rotation;

                                    ConvexHull convexHull = new ConvexHull(convex, WhiskeyColor.White);
                                    convexHull.DrawShadows(i.Light, CameraTransform, hull.Shadows.IncludeLight, hull.Shadows.Solidness, hull.Shadows.Height);
                                }
                            }
                        });
                    }


                    spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.MultiplyWithAlpha, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, CameraTransform);
                    i.renderLight(RenderInfo);
                    spriteBatch.End();
                }
            });
            ClearAlphaToOne();


            lightBloomComponent.BeginDraw();
            GraphicsDevice.Clear(XnaColor.Transparent);
            spriteBatch.Begin();
            spriteBatch.Draw(lightMapTarget, Vector.Zero, null, XnaColor.White);
            spriteBatch.End();
            lightBloomComponent.draw();
            lightMapTarget = lightBloomComponent.OutputTarget;
        }