コード例 #1
0
ファイル: LightMap.cs プロジェクト: MyEyes/Igorr
 public void SetGlow(int id, Vector2 position, Color color, float radius, bool shadows, float timeout)
 {
     _lightMutex.WaitOne();
     for (int x = 0; x < _glows.Count; x++)
     {
         if (_glows[x].id == id)
         {
             _glows[x].position = position;
             _glows[x].radius = radius;
             _glows[x].timeOut = timeout;
             _glows[x].color = color;
             if (radius < 0)
                 _glows.RemoveAt(x);
             _lightMutex.ReleaseMutex();
             return;
         }
     }
     LightSource glow = new LightSource();
     glow.id = id;
     glow.position = position;
     glow.radius = radius;
     glow.timeOut = timeout;
     glow.timeOutStart = timeout;
     glow.color = color;
     glow.shadows = shadows;
     _glows.Add(glow);
     _lightMutex.ReleaseMutex();
 }
コード例 #2
0
ファイル: LightMap.cs プロジェクト: MyEyes/Igorr
        public void DrawLight(Camera cam, LightSource light, Map map, SpriteBatch batch)
        {
            //Clear stencil buffer
            device.Clear(ClearOptions.Stencil, Color.White, 0, 1);

            if (light.shadows)
            {
                Vector2 camPosition = cam.Position;
                //cam.MoveTo(light.position, 1);
                UnShadowTiles(cam, batch, map);
                //cam.MoveTo(camPosition,1);

                //Build shadow geometry for the light
                int vertexCount = map.CreateShadowGeometry(light.position, new Rectangle((int)(light.position.X - light.radius), (int)(light.position.Y - light.radius), (int)(2*light.radius), (int)(2*light.radius)), shadowVB);

                //Draw Shadows into stencil buffer
                device.BlendState = generateShadow;
                device.DepthStencilState = generateShadowStencil;
                shadowEffect.CurrentTechnique = shadowEffect.Techniques["Shadow"];
                device.SetVertexBuffer(shadowVB);
                device.Indices = shadowIB;
                shadowEffect.CurrentTechnique.Passes[0].Apply();

                //Check necessary because empty draw calls cause crashes
                if (vertexCount > 0)
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, 4 * vertexCount / 6);
            }
            //Draw glow over everything that has not been stenciled out
            shadowEffect.CurrentTechnique = shadowEffect.Techniques["Glow"];
            batch.Begin(SpriteSortMode.Immediate, addLight, null, drawShadowedLight, RasterizerState.CullNone, shadowEffect);
            //I need to specify a texture to use this call, but since I use a custom shader it is never used, it might actually be null I am not sure
            batch.Draw(_unusedTexture, new Rectangle((int)(light.position.X - light.radius), (int)(light.position.Y - light.radius), (int)(light.radius * 2), (int)(light.radius * 2)), Color.Lerp(light.color, Color.Black, 1-light.brightness));
            batch.End();
        }