Lightning is not additive anymore

Now otclient lightning may look like more tibia lights,
before this too many lights together would increase
brightness a lot, this won't happen anymore in cards
with OpenGL 1.4 or newer
This commit is contained in:
Eduardo Bart 2013-02-06 19:49:40 -02:00
parent 86c462eb4d
commit 7f6a4bbbe5
5 changed files with 53 additions and 1 deletions

View File

@ -126,6 +126,7 @@ void LightView::draw(const Rect& dest, const Rect& src)
m_lightbuffer->bind(); m_lightbuffer->bind();
g_painter->setCompositionMode(Painter::CompositionMode_Replace); g_painter->setCompositionMode(Painter::CompositionMode_Replace);
drawGlobalLight(m_globalLight); drawGlobalLight(m_globalLight);
g_painter->setBlendEquation(Painter::BlendEquation_Max);
g_painter->setCompositionMode(Painter::CompositionMode_Add); g_painter->setCompositionMode(Painter::CompositionMode_Add);
for(const LightSource& source : m_lightMap) for(const LightSource& source : m_lightMap)
drawLightSource(source.center, source.color, source.radius); drawLightSource(source.center, source.color, source.radius);

View File

@ -357,6 +357,19 @@ bool Graphics::canUseBlendFuncSeparate()
#endif #endif
} }
bool Graphics::canUseBlendEquation()
{
#if OPENGL_ES==2
return true;
#elif OPENGL_ES==1
return true;
#else
if(!GLEW_VERSION_1_4)
return false;
return true;
#endif
}
bool Graphics::canCacheBackbuffer() bool Graphics::canCacheBackbuffer()
{ {
if(!m_alphaBits) if(!m_alphaBits)

View File

@ -72,6 +72,7 @@ public:
bool canUseHardwareMipmaps(); bool canUseHardwareMipmaps();
bool canUseClampToEdge(); bool canUseClampToEdge();
bool canUseBlendFuncSeparate(); bool canUseBlendFuncSeparate();
bool canUseBlendEquation();
bool canCacheBackbuffer(); bool canCacheBackbuffer();
bool shouldUseShaders() { return m_shouldUseShaders; } bool shouldUseShaders() { return m_shouldUseShaders; }
bool hasScissorBug(); bool hasScissorBug();

View File

@ -34,6 +34,7 @@ Painter::Painter()
m_color = Color::white; m_color = Color::white;
m_opacity = 1.0f; m_opacity = 1.0f;
m_compositionMode = CompositionMode_Normal; m_compositionMode = CompositionMode_Normal;
m_blendEquation = BlendEquation_Add;
m_shaderProgram = nullptr; m_shaderProgram = nullptr;
m_texture = nullptr; m_texture = nullptr;
m_alphaWriting = false; m_alphaWriting = false;
@ -45,6 +46,7 @@ void Painter::resetState()
resetColor(); resetColor();
resetOpacity(); resetOpacity();
resetCompositionMode(); resetCompositionMode();
resetBlendEquation();
resetClipRect(); resetClipRect();
resetShaderProgram(); resetShaderProgram();
resetTexture(); resetTexture();
@ -56,6 +58,7 @@ void Painter::refreshState()
{ {
updateGlViewport(); updateGlViewport();
updateGlCompositionMode(); updateGlCompositionMode();
updateGlBlendEquation();
updateGlClipRect(); updateGlClipRect();
updateGlTexture(); updateGlTexture();
updateGlAlphaWriting(); updateGlAlphaWriting();
@ -71,6 +74,7 @@ void Painter::saveState()
m_olderStates[m_oldStateIndex].color = m_color; m_olderStates[m_oldStateIndex].color = m_color;
m_olderStates[m_oldStateIndex].opacity = m_opacity; m_olderStates[m_oldStateIndex].opacity = m_opacity;
m_olderStates[m_oldStateIndex].compositionMode = m_compositionMode; m_olderStates[m_oldStateIndex].compositionMode = m_compositionMode;
m_olderStates[m_oldStateIndex].blendEquation = m_blendEquation;
m_olderStates[m_oldStateIndex].clipRect = m_clipRect; m_olderStates[m_oldStateIndex].clipRect = m_clipRect;
m_olderStates[m_oldStateIndex].shaderProgram = m_shaderProgram; m_olderStates[m_oldStateIndex].shaderProgram = m_shaderProgram;
m_olderStates[m_oldStateIndex].texture = m_texture; m_olderStates[m_oldStateIndex].texture = m_texture;
@ -94,6 +98,7 @@ void Painter::restoreSavedState()
setColor(m_olderStates[m_oldStateIndex].color); setColor(m_olderStates[m_oldStateIndex].color);
setOpacity(m_olderStates[m_oldStateIndex].opacity); setOpacity(m_olderStates[m_oldStateIndex].opacity);
setCompositionMode(m_olderStates[m_oldStateIndex].compositionMode); setCompositionMode(m_olderStates[m_oldStateIndex].compositionMode);
setBlendEquation(m_olderStates[m_oldStateIndex].blendEquation);
setClipRect(m_olderStates[m_oldStateIndex].clipRect); setClipRect(m_olderStates[m_oldStateIndex].clipRect);
setShaderProgram(m_olderStates[m_oldStateIndex].shaderProgram); setShaderProgram(m_olderStates[m_oldStateIndex].shaderProgram);
setTexture(m_olderStates[m_oldStateIndex].texture); setTexture(m_olderStates[m_oldStateIndex].texture);
@ -123,6 +128,14 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
updateGlCompositionMode(); updateGlCompositionMode();
} }
void Painter::setBlendEquation(Painter::BlendEquation blendEquation)
{
if(m_blendEquation == blendEquation)
return;
m_blendEquation = blendEquation;
updateGlBlendEquation();
}
void Painter::setClipRect(const Rect& clipRect) void Painter::setClipRect(const Rect& clipRect)
{ {
if(m_clipRect == clipRect) if(m_clipRect == clipRect)
@ -272,6 +285,20 @@ void Painter::updateGlCompositionMode()
} }
} }
void Painter::updateGlBlendEquation()
{
if(!g_graphics.canUseBlendEquation())
return;
switch(m_blendEquation) {
case BlendEquation_Max:
glBlendEquation(GL_MAX);
break;
case BlendEquation_Add:
glBlendEquation(GL_FUNC_ADD);
break;
}
}
void Painter::updateGlClipRect() void Painter::updateGlClipRect()
{ {
if(m_clipRect.isValid()) { if(m_clipRect.isValid()) {

View File

@ -37,12 +37,16 @@ public:
CompositionMode_Add, CompositionMode_Add,
CompositionMode_Replace, CompositionMode_Replace,
CompositionMode_DestBlending, CompositionMode_DestBlending,
CompositionMode_Light CompositionMode_Light,
}; };
enum DrawMode { enum DrawMode {
Triangles = GL_TRIANGLES, Triangles = GL_TRIANGLES,
TriangleStrip = GL_TRIANGLE_STRIP TriangleStrip = GL_TRIANGLE_STRIP
}; };
enum BlendEquation {
BlendEquation_Add,
BlendEquation_Max,
};
struct PainterState { struct PainterState {
Size resolution; Size resolution;
@ -52,6 +56,7 @@ public:
Color color; Color color;
float opacity; float opacity;
Painter::CompositionMode compositionMode; Painter::CompositionMode compositionMode;
Painter::BlendEquation blendEquation;
Rect clipRect; Rect clipRect;
Texture *texture; Texture *texture;
PainterShaderProgram *shaderProgram; PainterShaderProgram *shaderProgram;
@ -89,6 +94,7 @@ public:
virtual void setColor(const Color& color) { m_color = color; } virtual void setColor(const Color& color) { m_color = color; }
virtual void setOpacity(float opacity) { m_opacity = opacity; } virtual void setOpacity(float opacity) { m_opacity = opacity; }
virtual void setCompositionMode(CompositionMode compositionMode); virtual void setCompositionMode(CompositionMode compositionMode);
virtual void setBlendEquation(BlendEquation blendEquation);
virtual void setClipRect(const Rect& clipRect); virtual void setClipRect(const Rect& clipRect);
virtual void setShaderProgram(PainterShaderProgram *shaderProgram) { m_shaderProgram = shaderProgram; } virtual void setShaderProgram(PainterShaderProgram *shaderProgram) { m_shaderProgram = shaderProgram; }
virtual void setTexture(Texture *texture); virtual void setTexture(Texture *texture);
@ -115,6 +121,7 @@ public:
Color getColor() { return m_color; } Color getColor() { return m_color; }
float getOpacity() { return m_opacity; } float getOpacity() { return m_opacity; }
CompositionMode getCompositionMode() { return m_compositionMode; } CompositionMode getCompositionMode() { return m_compositionMode; }
BlendEquation getBlendEquation() { return m_blendEquation; }
Rect getClipRect() { return m_clipRect; } Rect getClipRect() { return m_clipRect; }
PainterShaderProgram *getShaderProgram() { return m_shaderProgram; } PainterShaderProgram *getShaderProgram() { return m_shaderProgram; }
bool getAlphaWriting() { return m_alphaWriting; } bool getAlphaWriting() { return m_alphaWriting; }
@ -124,6 +131,7 @@ public:
void resetOpacity() { setOpacity(1.0f); } void resetOpacity() { setOpacity(1.0f); }
void resetClipRect() { setClipRect(Rect()); } void resetClipRect() { setClipRect(Rect()); }
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); } void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
void resetBlendEquation() { setBlendEquation(BlendEquation_Add); }
void resetShaderProgram() { setShaderProgram(nullptr); } void resetShaderProgram() { setShaderProgram(nullptr); }
void resetTexture() { setTexture(nullptr); } void resetTexture() { setTexture(nullptr); }
void resetAlphaWriting() { setAlphaWriting(false); } void resetAlphaWriting() { setAlphaWriting(false); }
@ -134,6 +142,7 @@ public:
protected: protected:
void updateGlTexture(); void updateGlTexture();
void updateGlCompositionMode(); void updateGlCompositionMode();
void updateGlBlendEquation();
void updateGlClipRect(); void updateGlClipRect();
void updateGlAlphaWriting(); void updateGlAlphaWriting();
void updateGlViewport(); void updateGlViewport();
@ -147,6 +156,7 @@ protected:
Color m_color; Color m_color;
float m_opacity; float m_opacity;
CompositionMode m_compositionMode; CompositionMode m_compositionMode;
BlendEquation m_blendEquation;
Rect m_clipRect; Rect m_clipRect;
Texture *m_texture; Texture *m_texture;
PainterShaderProgram *m_shaderProgram; PainterShaderProgram *m_shaderProgram;