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:
parent
86c462eb4d
commit
7f6a4bbbe5
|
@ -126,6 +126,7 @@ void LightView::draw(const Rect& dest, const Rect& src)
|
|||
m_lightbuffer->bind();
|
||||
g_painter->setCompositionMode(Painter::CompositionMode_Replace);
|
||||
drawGlobalLight(m_globalLight);
|
||||
g_painter->setBlendEquation(Painter::BlendEquation_Max);
|
||||
g_painter->setCompositionMode(Painter::CompositionMode_Add);
|
||||
for(const LightSource& source : m_lightMap)
|
||||
drawLightSource(source.center, source.color, source.radius);
|
||||
|
|
|
@ -357,6 +357,19 @@ bool Graphics::canUseBlendFuncSeparate()
|
|||
#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()
|
||||
{
|
||||
if(!m_alphaBits)
|
||||
|
|
|
@ -72,6 +72,7 @@ public:
|
|||
bool canUseHardwareMipmaps();
|
||||
bool canUseClampToEdge();
|
||||
bool canUseBlendFuncSeparate();
|
||||
bool canUseBlendEquation();
|
||||
bool canCacheBackbuffer();
|
||||
bool shouldUseShaders() { return m_shouldUseShaders; }
|
||||
bool hasScissorBug();
|
||||
|
|
|
@ -34,6 +34,7 @@ Painter::Painter()
|
|||
m_color = Color::white;
|
||||
m_opacity = 1.0f;
|
||||
m_compositionMode = CompositionMode_Normal;
|
||||
m_blendEquation = BlendEquation_Add;
|
||||
m_shaderProgram = nullptr;
|
||||
m_texture = nullptr;
|
||||
m_alphaWriting = false;
|
||||
|
@ -45,6 +46,7 @@ void Painter::resetState()
|
|||
resetColor();
|
||||
resetOpacity();
|
||||
resetCompositionMode();
|
||||
resetBlendEquation();
|
||||
resetClipRect();
|
||||
resetShaderProgram();
|
||||
resetTexture();
|
||||
|
@ -56,6 +58,7 @@ void Painter::refreshState()
|
|||
{
|
||||
updateGlViewport();
|
||||
updateGlCompositionMode();
|
||||
updateGlBlendEquation();
|
||||
updateGlClipRect();
|
||||
updateGlTexture();
|
||||
updateGlAlphaWriting();
|
||||
|
@ -71,6 +74,7 @@ void Painter::saveState()
|
|||
m_olderStates[m_oldStateIndex].color = m_color;
|
||||
m_olderStates[m_oldStateIndex].opacity = m_opacity;
|
||||
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].shaderProgram = m_shaderProgram;
|
||||
m_olderStates[m_oldStateIndex].texture = m_texture;
|
||||
|
@ -94,6 +98,7 @@ void Painter::restoreSavedState()
|
|||
setColor(m_olderStates[m_oldStateIndex].color);
|
||||
setOpacity(m_olderStates[m_oldStateIndex].opacity);
|
||||
setCompositionMode(m_olderStates[m_oldStateIndex].compositionMode);
|
||||
setBlendEquation(m_olderStates[m_oldStateIndex].blendEquation);
|
||||
setClipRect(m_olderStates[m_oldStateIndex].clipRect);
|
||||
setShaderProgram(m_olderStates[m_oldStateIndex].shaderProgram);
|
||||
setTexture(m_olderStates[m_oldStateIndex].texture);
|
||||
|
@ -123,6 +128,14 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
|||
updateGlCompositionMode();
|
||||
}
|
||||
|
||||
void Painter::setBlendEquation(Painter::BlendEquation blendEquation)
|
||||
{
|
||||
if(m_blendEquation == blendEquation)
|
||||
return;
|
||||
m_blendEquation = blendEquation;
|
||||
updateGlBlendEquation();
|
||||
}
|
||||
|
||||
void Painter::setClipRect(const Rect& 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()
|
||||
{
|
||||
if(m_clipRect.isValid()) {
|
||||
|
|
|
@ -37,12 +37,16 @@ public:
|
|||
CompositionMode_Add,
|
||||
CompositionMode_Replace,
|
||||
CompositionMode_DestBlending,
|
||||
CompositionMode_Light
|
||||
CompositionMode_Light,
|
||||
};
|
||||
enum DrawMode {
|
||||
Triangles = GL_TRIANGLES,
|
||||
TriangleStrip = GL_TRIANGLE_STRIP
|
||||
};
|
||||
enum BlendEquation {
|
||||
BlendEquation_Add,
|
||||
BlendEquation_Max,
|
||||
};
|
||||
|
||||
struct PainterState {
|
||||
Size resolution;
|
||||
|
@ -52,6 +56,7 @@ public:
|
|||
Color color;
|
||||
float opacity;
|
||||
Painter::CompositionMode compositionMode;
|
||||
Painter::BlendEquation blendEquation;
|
||||
Rect clipRect;
|
||||
Texture *texture;
|
||||
PainterShaderProgram *shaderProgram;
|
||||
|
@ -89,6 +94,7 @@ public:
|
|||
virtual void setColor(const Color& color) { m_color = color; }
|
||||
virtual void setOpacity(float opacity) { m_opacity = opacity; }
|
||||
virtual void setCompositionMode(CompositionMode compositionMode);
|
||||
virtual void setBlendEquation(BlendEquation blendEquation);
|
||||
virtual void setClipRect(const Rect& clipRect);
|
||||
virtual void setShaderProgram(PainterShaderProgram *shaderProgram) { m_shaderProgram = shaderProgram; }
|
||||
virtual void setTexture(Texture *texture);
|
||||
|
@ -115,6 +121,7 @@ public:
|
|||
Color getColor() { return m_color; }
|
||||
float getOpacity() { return m_opacity; }
|
||||
CompositionMode getCompositionMode() { return m_compositionMode; }
|
||||
BlendEquation getBlendEquation() { return m_blendEquation; }
|
||||
Rect getClipRect() { return m_clipRect; }
|
||||
PainterShaderProgram *getShaderProgram() { return m_shaderProgram; }
|
||||
bool getAlphaWriting() { return m_alphaWriting; }
|
||||
|
@ -124,6 +131,7 @@ public:
|
|||
void resetOpacity() { setOpacity(1.0f); }
|
||||
void resetClipRect() { setClipRect(Rect()); }
|
||||
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
|
||||
void resetBlendEquation() { setBlendEquation(BlendEquation_Add); }
|
||||
void resetShaderProgram() { setShaderProgram(nullptr); }
|
||||
void resetTexture() { setTexture(nullptr); }
|
||||
void resetAlphaWriting() { setAlphaWriting(false); }
|
||||
|
@ -134,6 +142,7 @@ public:
|
|||
protected:
|
||||
void updateGlTexture();
|
||||
void updateGlCompositionMode();
|
||||
void updateGlBlendEquation();
|
||||
void updateGlClipRect();
|
||||
void updateGlAlphaWriting();
|
||||
void updateGlViewport();
|
||||
|
@ -147,6 +156,7 @@ protected:
|
|||
Color m_color;
|
||||
float m_opacity;
|
||||
CompositionMode m_compositionMode;
|
||||
BlendEquation m_blendEquation;
|
||||
Rect m_clipRect;
|
||||
Texture *m_texture;
|
||||
PainterShaderProgram *m_shaderProgram;
|
||||
|
|
Loading…
Reference in New Issue