mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2024-12-28 18:18:52 +00:00
po2 scaling for average luminance
This commit is contained in:
parent
72efd3a650
commit
e778ffee9b
@ -1,5 +1,6 @@
|
|||||||
#include "luminancecalculator.hpp"
|
#include "luminancecalculator.hpp"
|
||||||
|
|
||||||
|
#include <components/misc/mathutil.hpp>
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
#include <components/shader/shadermanager.hpp>
|
#include <components/shader/shadermanager.hpp>
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ namespace MWRender
|
|||||||
buffer.sceneLumSS = new osg::StateSet;
|
buffer.sceneLumSS = new osg::StateSet;
|
||||||
buffer.sceneLumSS->setAttributeAndModes(mLuminanceProgram);
|
buffer.sceneLumSS->setAttributeAndModes(mLuminanceProgram);
|
||||||
buffer.sceneLumSS->addUniform(new osg::Uniform("sceneTex", 0));
|
buffer.sceneLumSS->addUniform(new osg::Uniform("sceneTex", 0));
|
||||||
|
buffer.sceneLumSS->addUniform(new osg::Uniform("scaling", mScale));
|
||||||
|
|
||||||
buffer.resolveSS = new osg::StateSet;
|
buffer.resolveSS = new osg::StateSet;
|
||||||
buffer.resolveSS->setAttributeAndModes(mResolveProgram);
|
buffer.resolveSS->setAttributeAndModes(mResolveProgram);
|
||||||
@ -108,6 +110,7 @@ namespace MWRender
|
|||||||
auto& buffer = mBuffers[frameId];
|
auto& buffer = mBuffers[frameId];
|
||||||
buffer.sceneLumFbo->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);
|
buffer.sceneLumFbo->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);
|
||||||
buffer.sceneLumSS->setTextureAttributeAndModes(0, canvas.getSceneTexture(frameId));
|
buffer.sceneLumSS->setTextureAttributeAndModes(0, canvas.getSceneTexture(frameId));
|
||||||
|
buffer.sceneLumSS->getUniform("scaling")->set(mScale);
|
||||||
|
|
||||||
state.apply(buffer.sceneLumSS);
|
state.apply(buffer.sceneLumSS);
|
||||||
canvas.drawGeometry(renderInfo);
|
canvas.drawGeometry(renderInfo);
|
||||||
@ -140,4 +143,16 @@ namespace MWRender
|
|||||||
{
|
{
|
||||||
return mBuffers[frameId].luminanceTex;
|
return mBuffers[frameId].luminanceTex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuminanceCalculator::dirty(int w, int h)
|
||||||
|
{
|
||||||
|
constexpr int minSize = 64;
|
||||||
|
|
||||||
|
mWidth = std::max(minSize, Misc::nextPowerOfTwo(w) / 2);
|
||||||
|
mHeight = std::max(minSize, Misc::nextPowerOfTwo(h) / 2);
|
||||||
|
|
||||||
|
mScale = osg::Vec2f(w / static_cast<float>(mWidth), h / static_cast<float>(mHeight));
|
||||||
|
|
||||||
|
mCompiled = false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -32,13 +32,7 @@ namespace MWRender
|
|||||||
void enable() { mEnabled = true; }
|
void enable() { mEnabled = true; }
|
||||||
void disable() { mEnabled = false; }
|
void disable() { mEnabled = false; }
|
||||||
|
|
||||||
void dirty(int w, int h)
|
void dirty(int w, int h);
|
||||||
{
|
|
||||||
constexpr float scale = 0.5;
|
|
||||||
mWidth = w * scale;
|
|
||||||
mHeight = h * scale;
|
|
||||||
mCompiled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> getLuminanceTexture(size_t frameId) const;
|
osg::ref_ptr<osg::Texture2D> getLuminanceTexture(size_t frameId) const;
|
||||||
|
|
||||||
@ -67,6 +61,7 @@ namespace MWRender
|
|||||||
|
|
||||||
int mWidth = 1;
|
int mWidth = 1;
|
||||||
int mHeight = 1;
|
int mHeight = 1;
|
||||||
|
osg::Vec2f mScale = osg::Vec2f(1, 1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ namespace MWRender
|
|||||||
|
|
||||||
mFallbackStateSet->setAttributeAndModes(mFallbackProgram);
|
mFallbackStateSet->setAttributeAndModes(mFallbackProgram);
|
||||||
mFallbackStateSet->addUniform(new osg::Uniform("omw_SamplerLastShader", 0));
|
mFallbackStateSet->addUniform(new osg::Uniform("omw_SamplerLastShader", 0));
|
||||||
|
mFallbackStateSet->addUniform(new osg::Uniform("scaling", osg::Vec2f(1, 1)));
|
||||||
|
|
||||||
auto multiviewResolveVertex = shaderManager.getShader("multiview_resolve_vertex.glsl", {}, osg::Shader::VERTEX);
|
auto multiviewResolveVertex = shaderManager.getShader("multiview_resolve_vertex.glsl", {}, osg::Shader::VERTEX);
|
||||||
auto multiviewResolveFragment
|
auto multiviewResolveFragment
|
||||||
|
@ -22,6 +22,23 @@ namespace Misc
|
|||||||
return osg::Vec2f(vec.x() * c + vec.y() * -s, vec.x() * s + vec.y() * c);
|
return osg::Vec2f(vec.x() * c + vec.y() * -s, vec.x() * s + vec.y() * c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool isPowerOfTwo(int x)
|
||||||
|
{
|
||||||
|
return ((x > 0) && ((x & (x - 1)) == 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int nextPowerOfTwo(int v)
|
||||||
|
{
|
||||||
|
if (isPowerOfTwo(v))
|
||||||
|
return v;
|
||||||
|
int depth = 0;
|
||||||
|
while (v)
|
||||||
|
{
|
||||||
|
v >>= 1;
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
return 1 << depth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <components/loadinglistener/reporter.hpp>
|
#include <components/loadinglistener/reporter.hpp>
|
||||||
#include <components/misc/constants.hpp>
|
#include <components/misc/constants.hpp>
|
||||||
|
#include <components/misc/mathutil.hpp>
|
||||||
#include <components/resource/resourcesystem.hpp>
|
#include <components/resource/resourcesystem.hpp>
|
||||||
#include <components/sceneutil/positionattitudetransform.hpp>
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
||||||
|
|
||||||
@ -22,25 +23,6 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
bool isPowerOfTwo(int x)
|
|
||||||
{
|
|
||||||
return ((x > 0) && ((x & (x - 1)) == 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
int nextPowerOfTwo(int v)
|
|
||||||
{
|
|
||||||
if (isPowerOfTwo(v))
|
|
||||||
return v;
|
|
||||||
int depth = 0;
|
|
||||||
while (v)
|
|
||||||
{
|
|
||||||
v >>= 1;
|
|
||||||
depth++;
|
|
||||||
}
|
|
||||||
return 1 << depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int Log2(unsigned int n)
|
unsigned int Log2(unsigned int n)
|
||||||
{
|
{
|
||||||
unsigned int targetlevel = 0;
|
unsigned int targetlevel = 0;
|
||||||
@ -153,7 +135,7 @@ namespace Terrain
|
|||||||
int origSizeY = static_cast<int>(mMaxY - mMinY);
|
int origSizeY = static_cast<int>(mMaxY - mMinY);
|
||||||
|
|
||||||
// Dividing a quad tree only works well for powers of two, so round up to the nearest one
|
// Dividing a quad tree only works well for powers of two, so round up to the nearest one
|
||||||
int size = nextPowerOfTwo(std::max(origSizeX, origSizeY));
|
int size = Misc::nextPowerOfTwo(std::max(origSizeX, origSizeY));
|
||||||
|
|
||||||
float centerX = (mMinX + mMaxX) / 2.f + (size - origSizeX) / 2.f;
|
float centerX = (mMinX + mMaxX) / 2.f + (size - origSizeX) / 2.f;
|
||||||
float centerY = (mMinY + mMaxY) / 2.f + (size - origSizeY) / 2.f;
|
float centerY = (mMinY + mMaxY) / 2.f + (size - origSizeY) / 2.f;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
|
uniform vec2 scaling = vec2(1.0, 1.0);
|
||||||
|
|
||||||
varying vec2 uv;
|
varying vec2 uv;
|
||||||
|
|
||||||
#include "openmw_vertex.h.glsl"
|
#include "openmw_vertex.h.glsl"
|
||||||
@ -7,5 +9,5 @@ varying vec2 uv;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(gl_Vertex.xy, 0.0, 1.0);
|
gl_Position = vec4(gl_Vertex.xy, 0.0, 1.0);
|
||||||
uv = gl_Position.xy * 0.5 + 0.5;
|
uv = (gl_Position.xy * 0.5 + 0.5) * scaling;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user