Если вы умножите свою световую текстуру на сцену, вы затемните область, а не сделаете ее ярче.
Вы можете попробовать рендеринг с аддитивным смешиванием; это будет выглядеть не совсем правильно, но это легко и может быть приемлемо. Вам придется рисовать свет с довольно низкой альфой, чтобы текстура света не просто перенасыщала эту часть изображения.
Другой, более сложный способ создания освещения состоит в том, чтобы нарисовать все ваши световые текстуры (для всех источников света в сцене) аддитивно на второй цели рендеринга, а затем умножить эту текстуру на вашу сцену. Это должно дать гораздо более реалистичное освещение, но требует больше производительности и является более сложным.
Инициализация:
RenderTarget2D lightBuffer = new RenderTarget2D(graphicsDevice, screenWidth, screenHeight, 1, SurfaceFormat.Color);
Color ambientLight = new Color(0.3f, 0.3f, 0.3f, 1.0f);
Рисовать:
// set the render target and clear it to the ambient lighting
graphicsDevice.SetRenderTarget(0, lightBuffer);
graphicsDevice.Clear(ambientLight)
// additively draw all of the lights onto this texture. The lights can be coloured etc.
spriteBatch.Begin(SpriteBlendMode.Additive);
foreach (light in lights)
spriteBatch.Draw(lightFadeOffTexture, light.Area, light.Color);
spriteBatch.End();
// change render target back to the back buffer, so we are back to drawing onto the screen
graphicsDevice.SetRenderTarget(0, null);
// draw the old, non-lit, scene
DrawScene();
// multiply the light buffer texture with the scene
spriteBatch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.None);
graphicsDevice.RenderState.SourceBlend = Blend.Zero;
graphicsDevice.RenderState.DestinationBlend = Blend.SourceColor;
spriteBatch.Draw(lightBuffer.GetTexture(), new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
spriteBatch.End();
person
Tom Gillen
schedule
05.01.2010