#ifndef OPENMW_COMPONENTS_FX_STATEUPDATER_H #define OPENMW_COMPONENTS_FX_STATEUPDATER_H #include #include #include #include namespace fx { class StateUpdater : public SceneUtil::StateSetUpdater { public: StateUpdater(bool useUBO); void setProjectionMatrix(const osg::Matrixf& matrix) { mData.get() = matrix; mData.get() = osg::Matrixf::inverse(matrix); } void setViewMatrix(const osg::Matrixf& matrix) { mData.get() = matrix; mData.get() = osg::Matrixf::inverse(matrix); } void setPrevViewMatrix(const osg::Matrixf& matrix) { mData.get() = matrix; } void setEyePos(const osg::Vec3f& pos) { mData.get() = osg::Vec4f(pos, 0.f); } void setEyeVec(const osg::Vec3f& vec) { mData.get() = osg::Vec4f(vec, 0.f); } void setFogColor(const osg::Vec4f& color) { mData.get() = color; } void setAmbientColor(const osg::Vec4f& color) { mData.get() = color; } void setSkyColor(const osg::Vec4f& color) { mData.get() = color; } void setSunColor(const osg::Vec4f& color) { mData.get() = color; } void setSunPos(const osg::Vec4f& pos, bool night) { mData.get() = pos; mData.get().normalize(); if (night) mData.get().z() *= -1.f; } void setResolution(const osg::Vec2f& size) { mData.get() = size; mData.get() = { 1.f / size.x(), 1.f / size.y() }; } void setSunVis(float vis) { mData.get() = vis; } void setFogRange(float near, float far) { mData.get() = near; mData.get() = far; } void setNearFar(float near, float far) { mData.get() = near; mData.get() = far; } void setIsUnderwater(bool underwater) { mData.get() = underwater; } void setIsInterior(bool interior) { mData.get() = interior; } void setFov(float fov) { mData.get() = fov; } void setGameHour(float hour) { mData.get() = hour; } void setWeatherId(int id) { mData.get() = id; } void setNextWeatherId(int id) { mData.get() = id; } void setWaterHeight(float height) { mData.get() = height; } void setIsWaterEnabled(bool enabled) { mData.get() = enabled; } void setSimulationTime(float time) { mData.get() = time; } void setDeltaSimulationTime(float time) { mData.get() = time; } void setFrameNumber(int frame) { mData.get() = frame; } void setWindSpeed(float speed) { mData.get() = speed; } void setWeatherTransition(float transition) { mData.get() = transition > 0 ? 1 - transition : 0; } void bindPointLights(std::shared_ptr buffer) { mPointLightBuffer = std::move(buffer); } static const std::string& getStructDefinition() { return sDefinition; } void setDefaults(osg::StateSet* stateset) override; void apply(osg::StateSet* stateset, osg::NodeVisitor* nv) override; private: struct ProjectionMatrix : std140::Mat4 { static constexpr std::string_view sName = "projectionMatrix"; }; struct InvProjectionMatrix : std140::Mat4 { static constexpr std::string_view sName = "invProjectionMatrix"; }; struct ViewMatrix : std140::Mat4 { static constexpr std::string_view sName = "viewMatrix"; }; struct PrevViewMatrix : std140::Mat4 { static constexpr std::string_view sName = "prevViewMatrix"; }; struct InvViewMatrix : std140::Mat4 { static constexpr std::string_view sName = "invViewMatrix"; }; struct EyePos : std140::Vec4 { static constexpr std::string_view sName = "eyePos"; }; struct EyeVec : std140::Vec4 { static constexpr std::string_view sName = "eyeVec"; }; struct AmbientColor : std140::Vec4 { static constexpr std::string_view sName = "ambientColor"; }; struct SkyColor : std140::Vec4 { static constexpr std::string_view sName = "skyColor"; }; struct FogColor : std140::Vec4 { static constexpr std::string_view sName = "fogColor"; }; struct SunColor : std140::Vec4 { static constexpr std::string_view sName = "sunColor"; }; struct SunPos : std140::Vec4 { static constexpr std::string_view sName = "sunPos"; }; struct Resolution : std140::Vec2 { static constexpr std::string_view sName = "resolution"; }; struct RcpResolution : std140::Vec2 { static constexpr std::string_view sName = "rcpResolution"; }; struct FogNear : std140::Float { static constexpr std::string_view sName = "fogNear"; }; struct FogFar : std140::Float { static constexpr std::string_view sName = "fogFar"; }; struct Near : std140::Float { static constexpr std::string_view sName = "near"; }; struct Far : std140::Float { static constexpr std::string_view sName = "far"; }; struct Fov : std140::Float { static constexpr std::string_view sName = "fov"; }; struct GameHour : std140::Float { static constexpr std::string_view sName = "gameHour"; }; struct SunVis : std140::Float { static constexpr std::string_view sName = "sunVis"; }; struct WaterHeight : std140::Float { static constexpr std::string_view sName = "waterHeight"; }; struct IsWaterEnabled : std140::Bool { static constexpr std::string_view sName = "isWaterEnabled"; }; struct SimulationTime : std140::Float { static constexpr std::string_view sName = "simulationTime"; }; struct DeltaSimulationTime : std140::Float { static constexpr std::string_view sName = "deltaSimulationTime"; }; struct FrameNumber : std140::Int { static constexpr std::string_view sName = "frameNumber"; }; struct WindSpeed : std140::Float { static constexpr std::string_view sName = "windSpeed"; }; struct WeatherTransition : std140::Float { static constexpr std::string_view sName = "weatherTransition"; }; struct WeatherID : std140::Int { static constexpr std::string_view sName = "weatherID"; }; struct NextWeatherID : std140::Int { static constexpr std::string_view sName = "nextWeatherID"; }; struct IsUnderwater : std140::Bool { static constexpr std::string_view sName = "isUnderwater"; }; struct IsInterior : std140::Bool { static constexpr std::string_view sName = "isInterior"; }; using UniformData = std140::UBO; UniformData mData; bool mUseUBO; static std::string sDefinition; std::shared_ptr mPointLightBuffer; }; } #endif