parent
81068f820d
commit
d7a45311ed
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
LightView::LightView()
|
LightView::LightView()
|
||||||
{
|
{
|
||||||
m_lightbuffer = g_framebuffers.getTemporaryFrameBuffer();
|
m_lightbuffer = g_framebuffers.createFrameBuffer();
|
||||||
generateLightBuble();
|
generateLightBuble();
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ void LightView::generateLightBuble()
|
||||||
|
|
||||||
void LightView::reset()
|
void LightView::reset()
|
||||||
{
|
{
|
||||||
m_numLights = 0;
|
m_lightMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightView::setGlobalLight(const Light& light)
|
void LightView::setGlobalLight(const Light& light)
|
||||||
|
@ -74,26 +74,25 @@ void LightView::setGlobalLight(const Light& light)
|
||||||
|
|
||||||
void LightView::addLightSource(const Point& center, float scaleFactor, const Light& light)
|
void LightView::addLightSource(const Point& center, float scaleFactor, const Light& light)
|
||||||
{
|
{
|
||||||
if(m_numLights > MAX_LIGHTS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int radius = light.intensity * 64 * scaleFactor;
|
int radius = light.intensity * 64 * scaleFactor;
|
||||||
|
|
||||||
m_lightMap[m_numLights].center = center;
|
LightSource source;
|
||||||
m_lightMap[m_numLights].color = Color::from8bit(light.color);
|
source.center = center;
|
||||||
m_lightMap[m_numLights].radius = radius;
|
source.color = Color::from8bit(light.color);
|
||||||
m_numLights++;
|
source.radius = radius;
|
||||||
|
m_lightMap.push_back(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightView::drawGlobalLight(const Light& light)
|
void LightView::drawGlobalLight(const Light& light, const Size& size)
|
||||||
{
|
{
|
||||||
Color color = Color::from8bit(light.color);
|
Color color = Color::from8bit(light.color);
|
||||||
float factor = 0;//std::max<int>(256 - light.intensity, 0) / 256.0f;
|
float factor = light.intensity / 256.0f;
|
||||||
color.setRed(color.rF() * factor);
|
color.setRed(color.rF() * factor);
|
||||||
color.setGreen(color.gF() * factor);
|
color.setGreen(color.gF() * factor);
|
||||||
color.setBlue(color.bF() * factor);
|
color.setBlue(color.bF() * factor);
|
||||||
color.setAlpha(1.0f);
|
color.setAlpha(1.0f);
|
||||||
g_painter->clear(color);
|
g_painter->setColor(color);
|
||||||
|
g_painter->drawFilledRect(Rect(0,0,size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightView::drawLightSource(const Point& center, const Color& color, int radius)
|
void LightView::drawLightSource(const Point& center, const Color& color, int radius)
|
||||||
|
@ -110,10 +109,10 @@ void LightView::draw(Size size)
|
||||||
{
|
{
|
||||||
m_lightbuffer->resize(size);
|
m_lightbuffer->resize(size);
|
||||||
m_lightbuffer->bind();
|
m_lightbuffer->bind();
|
||||||
drawGlobalLight(m_globalLight);
|
drawGlobalLight(m_globalLight, size);
|
||||||
g_painter->setCompositionMode(Painter::CompositionMode_Add);
|
g_painter->setCompositionMode(Painter::CompositionMode_Add);
|
||||||
for(int i=0;i<m_numLights;++i)
|
for(const LightSource& source : m_lightMap)
|
||||||
drawLightSource(m_lightMap[i].center, m_lightMap[i].color, m_lightMap[i].radius);
|
drawLightSource(source.center, source.color, source.radius);
|
||||||
m_lightbuffer->release();
|
m_lightbuffer->release();
|
||||||
|
|
||||||
g_painter->setCompositionMode(Painter::CompositionMode_Light);
|
g_painter->setCompositionMode(Painter::CompositionMode_Light);
|
||||||
|
|
|
@ -35,10 +35,6 @@ struct LightSource {
|
||||||
|
|
||||||
class LightView : public LuaObject
|
class LightView : public LuaObject
|
||||||
{
|
{
|
||||||
enum {
|
|
||||||
MAX_LIGHTS = 1024
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LightView();
|
LightView();
|
||||||
|
|
||||||
|
@ -48,16 +44,15 @@ public:
|
||||||
void draw(Size size);
|
void draw(Size size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawGlobalLight(const Light& light);
|
void drawGlobalLight(const Light& light, const Size& size);
|
||||||
void drawLightSource(const Point& center, const Color& color, int radius);
|
void drawLightSource(const Point& center, const Color& color, int radius);
|
||||||
void generateLightBuble();
|
void generateLightBuble();
|
||||||
|
|
||||||
TexturePtr m_lightTexture;
|
TexturePtr m_lightTexture;
|
||||||
FrameBufferPtr m_lightbuffer;
|
FrameBufferPtr m_lightbuffer;
|
||||||
MapView* m_mapView;
|
MapView* m_mapView;
|
||||||
int m_numLights;
|
|
||||||
Light m_globalLight;
|
Light m_globalLight;
|
||||||
std::array<LightSource, MAX_LIGHTS> m_lightMap;
|
std::vector<LightSource> m_lightMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIGHTVIEW_H
|
#endif // LIGHTVIEW_H
|
||||||
|
|
|
@ -90,14 +90,6 @@ void MapView::draw(const Rect& rect)
|
||||||
|
|
||||||
Size tileSize = Size(1,1) * m_tileSize;
|
Size tileSize = Size(1,1) * m_tileSize;
|
||||||
|
|
||||||
if(m_drawLights) {
|
|
||||||
m_lightView->reset();
|
|
||||||
Light globalLight = g_map.getLight();
|
|
||||||
if(cameraPosition.z <= 7)
|
|
||||||
globalLight.intensity = std::min<uint8>(200, globalLight.intensity);
|
|
||||||
m_lightView->setGlobalLight(globalLight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m_mustDrawVisibleTilesCache || (drawFlags & Otc::DrawAnimations)) {
|
if(m_mustDrawVisibleTilesCache || (drawFlags & Otc::DrawAnimations)) {
|
||||||
m_framebuffer->bind();
|
m_framebuffer->bind();
|
||||||
|
|
||||||
|
@ -105,6 +97,19 @@ void MapView::draw(const Rect& rect)
|
||||||
Rect clearRect = Rect(0, 0, m_drawDimension * m_tileSize);
|
Rect clearRect = Rect(0, 0, m_drawDimension * m_tileSize);
|
||||||
g_painter->setColor(Color::black);
|
g_painter->setColor(Color::black);
|
||||||
g_painter->drawFilledRect(clearRect);
|
g_painter->drawFilledRect(clearRect);
|
||||||
|
|
||||||
|
if(m_drawLights) {
|
||||||
|
m_lightView->reset();
|
||||||
|
|
||||||
|
if(cameraPosition.z <= 7)
|
||||||
|
m_lightView->setGlobalLight(g_map.getLight());
|
||||||
|
else {
|
||||||
|
Light undergroundLight;
|
||||||
|
undergroundLight.color = 0;
|
||||||
|
undergroundLight.intensity = 0;
|
||||||
|
m_lightView->setGlobalLight(undergroundLight);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g_painter->setColor(Color::white);
|
g_painter->setColor(Color::white);
|
||||||
|
|
||||||
|
@ -139,6 +144,9 @@ void MapView::draw(const Rect& rect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_drawLights && m_updateTilesPos == 0)
|
||||||
|
m_lightView->draw(m_framebuffer->getSize());
|
||||||
|
|
||||||
m_framebuffer->release();
|
m_framebuffer->release();
|
||||||
|
|
||||||
// generating mipmaps each frame can be slow in older cards
|
// generating mipmaps each frame can be slow in older cards
|
||||||
|
@ -147,12 +155,6 @@ void MapView::draw(const Rect& rect)
|
||||||
m_mustDrawVisibleTilesCache = false;
|
m_mustDrawVisibleTilesCache = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_drawLights) {
|
|
||||||
m_framebuffer->bind();
|
|
||||||
m_lightView->draw(m_framebuffer->getSize());
|
|
||||||
m_framebuffer->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
Point drawOffset = ((m_drawDimension - m_visibleDimension - Size(1,1)).toPoint()/2) * m_tileSize;
|
Point drawOffset = ((m_drawDimension - m_visibleDimension - Size(1,1)).toPoint()/2) * m_tileSize;
|
||||||
if(isFollowingCreature())
|
if(isFollowingCreature())
|
||||||
drawOffset += m_followingCreature->getWalkOffset() * scaleFactor;
|
drawOffset += m_followingCreature->getWalkOffset() * scaleFactor;
|
||||||
|
|
Loading…
Reference in New Issue