mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-06 20:41:32 +00:00
Merge branch 'sky_shaders' into 'master'
Sky shaders See merge request OpenMW/openmw!1057
This commit is contained in:
commit
b3f84df43c
13 changed files with 3440 additions and 2950 deletions
|
@ -12,6 +12,8 @@
|
||||||
Bug #4602: Robert's Bodies: crash inside createInstance()
|
Bug #4602: Robert's Bodies: crash inside createInstance()
|
||||||
Bug #4700: Editor: Incorrect command implementation
|
Bug #4700: Editor: Incorrect command implementation
|
||||||
Bug #4744: Invisible particles must still be processed
|
Bug #4744: Invisible particles must still be processed
|
||||||
|
Bug #4752: UpdateCellCommand doesn't undo properly
|
||||||
|
Bug #5088: Sky abruptly changes direction during certain weather transitions
|
||||||
Bug #5100: Persuasion doesn't always clamp the resulting disposition
|
Bug #5100: Persuasion doesn't always clamp the resulting disposition
|
||||||
Bug #5120: Scripted object spawning updates physics system
|
Bug #5120: Scripted object spawning updates physics system
|
||||||
Bug #5207: Loose summons can be present in scene
|
Bug #5207: Loose summons can be present in scene
|
||||||
|
@ -42,6 +44,7 @@
|
||||||
Bug #6133: Cannot reliably sneak or steal in the sight of the NPCs siding with player
|
Bug #6133: Cannot reliably sneak or steal in the sight of the NPCs siding with player
|
||||||
Bug #6143: Capturing a screenshot makes engine to be a temporary unresponsive
|
Bug #6143: Capturing a screenshot makes engine to be a temporary unresponsive
|
||||||
Bug #6165: Paralyzed player character can pickup items when the inventory is open
|
Bug #6165: Paralyzed player character can pickup items when the inventory is open
|
||||||
|
Bug #6168: Weather particles flicker for a frame at start of storms
|
||||||
Bug #6172: Some creatures can't open doors
|
Bug #6172: Some creatures can't open doors
|
||||||
Bug #6174: Spellmaking and Enchanting sliders differences from vanilla
|
Bug #6174: Spellmaking and Enchanting sliders differences from vanilla
|
||||||
Bug #6184: Command and Calm and Demoralize and Frenzy and Rally magic effects inconsistencies with vanilla
|
Bug #6184: Command and Calm and Demoralize and Frenzy and Rally magic effects inconsistencies with vanilla
|
||||||
|
@ -76,6 +79,7 @@
|
||||||
Feature #6017: Separate persistent and temporary cell references when saving
|
Feature #6017: Separate persistent and temporary cell references when saving
|
||||||
Feature #6032: Reverse-z depth buffer
|
Feature #6032: Reverse-z depth buffer
|
||||||
Feature #6078: First person should not clear depth buffer
|
Feature #6078: First person should not clear depth buffer
|
||||||
|
Feature #6161: Refactor Sky to use shaders and GLES/GL3 friendly
|
||||||
Feature #6162: Refactor GUI to use shaders and to be GLES and GL3+ friendly
|
Feature #6162: Refactor GUI to use shaders and to be GLES and GL3+ friendly
|
||||||
Feature #6199: Support FBO Rendering
|
Feature #6199: Support FBO Rendering
|
||||||
Feature #6249: Alpha testing support for Collada
|
Feature #6249: Alpha testing support for Collada
|
||||||
|
|
|
@ -19,7 +19,7 @@ set(GAME_HEADER
|
||||||
source_group(game FILES ${GAME} ${GAME_HEADER})
|
source_group(game FILES ${GAME} ${GAME_HEADER})
|
||||||
|
|
||||||
add_openmw_dir (mwrender
|
add_openmw_dir (mwrender
|
||||||
actors objects renderingmanager animation rotatecontroller sky npcanimation vismask
|
actors objects renderingmanager animation rotatecontroller sky skyutil npcanimation vismask
|
||||||
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager
|
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager
|
||||||
bulletdebugdraw globalmap characterpreview camera viewovershoulder localmap water terrainstorage ripplesimulation
|
bulletdebugdraw globalmap characterpreview camera viewovershoulder localmap water terrainstorage ripplesimulation
|
||||||
renderbin actoranimation landmanager navmesh actorspaths recastmesh fogmanager objectpaging groundcover postprocessor
|
renderbin actoranimation landmanager navmesh actorspaths recastmesh fogmanager objectpaging groundcover postprocessor
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,10 +8,7 @@
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
#include <osg/Vec4f>
|
#include <osg/Vec4f>
|
||||||
|
|
||||||
namespace osg
|
#include "skyutil.hpp"
|
||||||
{
|
|
||||||
class Camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace osg
|
namespace osg
|
||||||
{
|
{
|
||||||
|
@ -19,6 +16,7 @@ namespace osg
|
||||||
class Node;
|
class Node;
|
||||||
class Material;
|
class Material;
|
||||||
class PositionAttitudeTransform;
|
class PositionAttitudeTransform;
|
||||||
|
class Camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace osgParticle
|
namespace osgParticle
|
||||||
|
@ -45,80 +43,6 @@ namespace MWRender
|
||||||
class AlphaFader;
|
class AlphaFader;
|
||||||
class UnderwaterSwitchCallback;
|
class UnderwaterSwitchCallback;
|
||||||
|
|
||||||
struct WeatherResult
|
|
||||||
{
|
|
||||||
std::string mCloudTexture;
|
|
||||||
std::string mNextCloudTexture;
|
|
||||||
float mCloudBlendFactor;
|
|
||||||
|
|
||||||
osg::Vec4f mFogColor;
|
|
||||||
|
|
||||||
osg::Vec4f mAmbientColor;
|
|
||||||
|
|
||||||
osg::Vec4f mSkyColor;
|
|
||||||
|
|
||||||
// sun light color
|
|
||||||
osg::Vec4f mSunColor;
|
|
||||||
|
|
||||||
// alpha is the sun transparency
|
|
||||||
osg::Vec4f mSunDiscColor;
|
|
||||||
|
|
||||||
float mFogDepth;
|
|
||||||
|
|
||||||
float mDLFogFactor;
|
|
||||||
float mDLFogOffset;
|
|
||||||
|
|
||||||
float mWindSpeed;
|
|
||||||
float mBaseWindSpeed;
|
|
||||||
float mCurrentWindSpeed;
|
|
||||||
float mNextWindSpeed;
|
|
||||||
|
|
||||||
float mCloudSpeed;
|
|
||||||
|
|
||||||
float mGlareView;
|
|
||||||
|
|
||||||
bool mNight; // use night skybox
|
|
||||||
float mNightFade; // fading factor for night skybox
|
|
||||||
|
|
||||||
bool mIsStorm;
|
|
||||||
|
|
||||||
std::string mAmbientLoopSoundID;
|
|
||||||
float mAmbientSoundVolume;
|
|
||||||
|
|
||||||
std::string mParticleEffect;
|
|
||||||
std::string mRainEffect;
|
|
||||||
float mPrecipitationAlpha;
|
|
||||||
|
|
||||||
float mRainDiameter;
|
|
||||||
float mRainMinHeight;
|
|
||||||
float mRainMaxHeight;
|
|
||||||
float mRainSpeed;
|
|
||||||
float mRainEntranceSpeed;
|
|
||||||
int mRainMaxRaindrops;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MoonState
|
|
||||||
{
|
|
||||||
enum class Phase
|
|
||||||
{
|
|
||||||
Full = 0,
|
|
||||||
WaningGibbous,
|
|
||||||
ThirdQuarter,
|
|
||||||
WaningCrescent,
|
|
||||||
New,
|
|
||||||
WaxingCrescent,
|
|
||||||
FirstQuarter,
|
|
||||||
WaxingGibbous,
|
|
||||||
Unspecified
|
|
||||||
};
|
|
||||||
|
|
||||||
float mRotationFromHorizon;
|
|
||||||
float mRotationFromNorth;
|
|
||||||
Phase mPhase;
|
|
||||||
float mShadowBlend;
|
|
||||||
float mMoonAlpha;
|
|
||||||
};
|
|
||||||
|
|
||||||
///@brief The SkyManager handles rendering of the sky domes, celestial bodies as well as other objects that need to be rendered
|
///@brief The SkyManager handles rendering of the sky domes, celestial bodies as well as other objects that need to be rendered
|
||||||
/// relative to the camera (e.g. weather particle effects)
|
/// relative to the camera (e.g. weather particle effects)
|
||||||
class SkyManager
|
class SkyManager
|
||||||
|
@ -162,7 +86,7 @@ namespace MWRender
|
||||||
|
|
||||||
void setRainSpeed(float speed);
|
void setRainSpeed(float speed);
|
||||||
|
|
||||||
void setStormDirection(const osg::Vec3f& direction);
|
void setStormParticleDirection(const osg::Vec3f& direction);
|
||||||
|
|
||||||
void setSunDirection(const osg::Vec3f& direction);
|
void setSunDirection(const osg::Vec3f& direction);
|
||||||
|
|
||||||
|
@ -203,12 +127,12 @@ namespace MWRender
|
||||||
osg::ref_ptr<osg::Node> mParticleEffect;
|
osg::ref_ptr<osg::Node> mParticleEffect;
|
||||||
osg::ref_ptr<UnderwaterSwitchCallback> mUnderwaterSwitch;
|
osg::ref_ptr<UnderwaterSwitchCallback> mUnderwaterSwitch;
|
||||||
|
|
||||||
osg::ref_ptr<osg::PositionAttitudeTransform> mCloudNode;
|
osg::ref_ptr<osg::Group> mCloudNode;
|
||||||
|
|
||||||
osg::ref_ptr<CloudUpdater> mCloudUpdater;
|
osg::ref_ptr<CloudUpdater> mCloudUpdater;
|
||||||
osg::ref_ptr<CloudUpdater> mCloudUpdater2;
|
osg::ref_ptr<CloudUpdater> mNextCloudUpdater;
|
||||||
osg::ref_ptr<osg::Node> mCloudMesh;
|
osg::ref_ptr<osg::PositionAttitudeTransform> mCloudMesh;
|
||||||
osg::ref_ptr<osg::Node> mCloudMesh2;
|
osg::ref_ptr<osg::PositionAttitudeTransform> mNextCloudMesh;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> mAtmosphereDay;
|
osg::ref_ptr<osg::Node> mAtmosphereDay;
|
||||||
|
|
||||||
|
@ -239,7 +163,10 @@ namespace MWRender
|
||||||
|
|
||||||
float mRainTimer;
|
float mRainTimer;
|
||||||
|
|
||||||
|
// particle system rotation is independent of cloud rotation internally
|
||||||
|
osg::Vec3f mStormParticleDirection;
|
||||||
osg::Vec3f mStormDirection;
|
osg::Vec3f mStormDirection;
|
||||||
|
osg::Vec3f mNextStormDirection;
|
||||||
|
|
||||||
// remember some settings so we don't have to apply them again if they didn't change
|
// remember some settings so we don't have to apply them again if they didn't change
|
||||||
std::string mClouds;
|
std::string mClouds;
|
||||||
|
@ -275,4 +202,4 @@ namespace MWRender
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GAME_RENDER_SKY_H
|
#endif
|
||||||
|
|
1142
apps/openmw/mwrender/skyutil.cpp
Normal file
1142
apps/openmw/mwrender/skyutil.cpp
Normal file
File diff suppressed because it is too large
Load diff
343
apps/openmw/mwrender/skyutil.hpp
Normal file
343
apps/openmw/mwrender/skyutil.hpp
Normal file
|
@ -0,0 +1,343 @@
|
||||||
|
#ifndef OPENMW_MWRENDER_SKYUTIL_H
|
||||||
|
#define OPENMW_MWRENDER_SKYUTIL_H
|
||||||
|
|
||||||
|
#include <osg/Vec4f>
|
||||||
|
#include <osg/Matrixf>
|
||||||
|
#include <osg/Texture2D>
|
||||||
|
#include <osg/Transform>
|
||||||
|
#include <osg/Material>
|
||||||
|
|
||||||
|
#include <osgParticle/Shooter>
|
||||||
|
#include <osgParticle/ConstantRateCounter>
|
||||||
|
|
||||||
|
#include <components/sceneutil/statesetupdater.hpp>
|
||||||
|
#include <components/sceneutil/nodecallback.hpp>
|
||||||
|
|
||||||
|
namespace Resource
|
||||||
|
{
|
||||||
|
class ImageManager;
|
||||||
|
class SceneManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
struct MoonUpdater;
|
||||||
|
class SunUpdater;
|
||||||
|
class SunFlashCallback;
|
||||||
|
class SunGlareCallback;
|
||||||
|
|
||||||
|
struct WeatherResult
|
||||||
|
{
|
||||||
|
std::string mCloudTexture;
|
||||||
|
std::string mNextCloudTexture;
|
||||||
|
float mCloudBlendFactor;
|
||||||
|
|
||||||
|
osg::Vec4f mFogColor;
|
||||||
|
|
||||||
|
osg::Vec4f mAmbientColor;
|
||||||
|
|
||||||
|
osg::Vec4f mSkyColor;
|
||||||
|
|
||||||
|
// sun light color
|
||||||
|
osg::Vec4f mSunColor;
|
||||||
|
|
||||||
|
// alpha is the sun transparency
|
||||||
|
osg::Vec4f mSunDiscColor;
|
||||||
|
|
||||||
|
float mFogDepth;
|
||||||
|
|
||||||
|
float mDLFogFactor;
|
||||||
|
float mDLFogOffset;
|
||||||
|
|
||||||
|
float mWindSpeed;
|
||||||
|
float mBaseWindSpeed;
|
||||||
|
float mCurrentWindSpeed;
|
||||||
|
float mNextWindSpeed;
|
||||||
|
|
||||||
|
float mCloudSpeed;
|
||||||
|
|
||||||
|
float mGlareView;
|
||||||
|
|
||||||
|
bool mNight; // use night skybox
|
||||||
|
float mNightFade; // fading factor for night skybox
|
||||||
|
|
||||||
|
bool mIsStorm;
|
||||||
|
|
||||||
|
std::string mAmbientLoopSoundID;
|
||||||
|
float mAmbientSoundVolume;
|
||||||
|
|
||||||
|
std::string mParticleEffect;
|
||||||
|
std::string mRainEffect;
|
||||||
|
float mPrecipitationAlpha;
|
||||||
|
|
||||||
|
float mRainDiameter;
|
||||||
|
float mRainMinHeight;
|
||||||
|
float mRainMaxHeight;
|
||||||
|
float mRainSpeed;
|
||||||
|
float mRainEntranceSpeed;
|
||||||
|
int mRainMaxRaindrops;
|
||||||
|
|
||||||
|
osg::Vec3f mStormDirection;
|
||||||
|
osg::Vec3f mNextStormDirection;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MoonState
|
||||||
|
{
|
||||||
|
enum class Phase
|
||||||
|
{
|
||||||
|
Full,
|
||||||
|
WaningGibbous,
|
||||||
|
ThirdQuarter,
|
||||||
|
WaningCrescent,
|
||||||
|
New,
|
||||||
|
WaxingCrescent,
|
||||||
|
FirstQuarter,
|
||||||
|
WaxingGibbous,
|
||||||
|
Unspecified
|
||||||
|
};
|
||||||
|
|
||||||
|
float mRotationFromHorizon;
|
||||||
|
float mRotationFromNorth;
|
||||||
|
Phase mPhase;
|
||||||
|
float mShadowBlend;
|
||||||
|
float mMoonAlpha;
|
||||||
|
};
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Material> createAlphaTrackingUnlitMaterial();
|
||||||
|
osg::ref_ptr<osg::Material> createUnlitMaterial();
|
||||||
|
|
||||||
|
class OcclusionCallback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OcclusionCallback(osg::ref_ptr<osg::OcclusionQueryNode> oqnVisible, osg::ref_ptr<osg::OcclusionQueryNode> oqnTotal);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
float getVisibleRatio (osg::Camera* camera);
|
||||||
|
|
||||||
|
private:
|
||||||
|
osg::ref_ptr<osg::OcclusionQueryNode> mOcclusionQueryVisiblePixels;
|
||||||
|
osg::ref_ptr<osg::OcclusionQueryNode> mOcclusionQueryTotalPixels;
|
||||||
|
|
||||||
|
std::map<osg::observer_ptr<osg::Camera>, float> mLastRatio;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AtmosphereUpdater : public SceneUtil::StateSetUpdater
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void setEmissionColor(const osg::Vec4f& emissionColor);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setDefaults(osg::StateSet* stateset) override;
|
||||||
|
void apply(osg::StateSet* stateset, osg::NodeVisitor* /*nv*/) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
osg::Vec4f mEmissionColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AtmosphereNightUpdater : public SceneUtil::StateSetUpdater
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AtmosphereNightUpdater(Resource::ImageManager* imageManager, bool forceShaders);
|
||||||
|
|
||||||
|
void setFade(float fade);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setDefaults(osg::StateSet* stateset) override;
|
||||||
|
|
||||||
|
void apply(osg::StateSet* stateset, osg::NodeVisitor* /*nv*/) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
osg::Vec4f mColor;
|
||||||
|
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||||
|
bool mForceShaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CloudUpdater : public SceneUtil::StateSetUpdater
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CloudUpdater(bool forceShaders);
|
||||||
|
|
||||||
|
void setTexture(osg::ref_ptr<osg::Texture2D> texture);
|
||||||
|
|
||||||
|
void setEmissionColor(const osg::Vec4f& emissionColor);
|
||||||
|
void setOpacity(float opacity);
|
||||||
|
void setTextureCoord(float timer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setDefaults(osg::StateSet *stateset) override;
|
||||||
|
void apply(osg::StateSet *stateset, osg::NodeVisitor *nv) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||||
|
osg::Vec4f mEmissionColor;
|
||||||
|
float mOpacity;
|
||||||
|
bool mForceShaders;
|
||||||
|
osg::Matrixf mTexMat;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Transform that removes the eyepoint of the modelview matrix,
|
||||||
|
/// i.e. its children are positioned relative to the camera.
|
||||||
|
class CameraRelativeTransform : public osg::Transform
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CameraRelativeTransform();
|
||||||
|
|
||||||
|
CameraRelativeTransform(const CameraRelativeTransform& copy, const osg::CopyOp& copyop);
|
||||||
|
|
||||||
|
META_Node(MWRender, CameraRelativeTransform)
|
||||||
|
|
||||||
|
const osg::Vec3f& getLastViewPoint() const;
|
||||||
|
|
||||||
|
bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override;
|
||||||
|
|
||||||
|
osg::BoundingSphere computeBound() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// viewPoint for the current frame
|
||||||
|
mutable osg::Vec3f mViewPoint;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Hides the node subgraph if the eye point is below water.
|
||||||
|
/// @note Must be added as cull callback.
|
||||||
|
/// @note Meant to be used on a node that is child of a CameraRelativeTransform.
|
||||||
|
/// The current view point must be retrieved by the CameraRelativeTransform since we can't get it anymore once we are in camera-relative space.
|
||||||
|
class UnderwaterSwitchCallback : public SceneUtil::NodeCallback<UnderwaterSwitchCallback>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UnderwaterSwitchCallback(CameraRelativeTransform* cameraRelativeTransform);
|
||||||
|
bool isUnderwater();
|
||||||
|
|
||||||
|
void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||||
|
void setEnabled(bool enabled);
|
||||||
|
void setWaterLevel(float waterLevel);
|
||||||
|
|
||||||
|
private:
|
||||||
|
osg::ref_ptr<CameraRelativeTransform> mCameraRelativeTransform;
|
||||||
|
bool mEnabled;
|
||||||
|
float mWaterLevel;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A base class for the sun and moons.
|
||||||
|
class CelestialBody
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CelestialBody(osg::Group* parentNode, float scaleFactor, int numUvSets, unsigned int visibleMask=~0u);
|
||||||
|
|
||||||
|
virtual ~CelestialBody() = default;
|
||||||
|
|
||||||
|
virtual void adjustTransparency(const float ratio) = 0;
|
||||||
|
|
||||||
|
void setVisible(bool visible);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
unsigned int mVisibleMask;
|
||||||
|
static const float mDistance;
|
||||||
|
osg::ref_ptr<osg::PositionAttitudeTransform> mTransform;
|
||||||
|
osg::ref_ptr<osg::Geometry> mGeom;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Sun : public CelestialBody
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Sun(osg::Group* parentNode, Resource::ImageManager& imageManager);
|
||||||
|
|
||||||
|
~Sun();
|
||||||
|
|
||||||
|
void setColor(const osg::Vec4f& color);
|
||||||
|
void adjustTransparency(const float ratio) override;
|
||||||
|
|
||||||
|
void setDirection(const osg::Vec3f& direction);
|
||||||
|
void setGlareTimeOfDayFade(float val);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// @param queryVisible If true, queries the amount of visible pixels. If false, queries the total amount of pixels.
|
||||||
|
osg::ref_ptr<osg::OcclusionQueryNode> createOcclusionQueryNode(osg::Group* parent, bool queryVisible);
|
||||||
|
|
||||||
|
void createSunFlash(Resource::ImageManager& imageManager);
|
||||||
|
void destroySunFlash();
|
||||||
|
|
||||||
|
void createSunGlare();
|
||||||
|
void destroySunGlare();
|
||||||
|
|
||||||
|
osg::ref_ptr<SunUpdater> mUpdater;
|
||||||
|
osg::ref_ptr<osg::Node> mSunFlashNode;
|
||||||
|
osg::ref_ptr<osg::Node> mSunGlareNode;
|
||||||
|
osg::ref_ptr<SunFlashCallback> mSunFlashCallback;
|
||||||
|
osg::ref_ptr<SunGlareCallback> mSunGlareCallback;
|
||||||
|
osg::ref_ptr<osg::OcclusionQueryNode> mOcclusionQueryVisiblePixels;
|
||||||
|
osg::ref_ptr<osg::OcclusionQueryNode> mOcclusionQueryTotalPixels;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Moon : public CelestialBody
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
Type_Masser = 0,
|
||||||
|
Type_Secunda
|
||||||
|
};
|
||||||
|
|
||||||
|
Moon(osg::Group* parentNode, Resource::SceneManager& sceneManager, float scaleFactor, Type type);
|
||||||
|
|
||||||
|
~Moon();
|
||||||
|
|
||||||
|
void adjustTransparency(const float ratio) override;
|
||||||
|
void setState(const MoonState state);
|
||||||
|
void setAtmosphereColor(const osg::Vec4f& color);
|
||||||
|
void setColor(const osg::Vec4f& color);
|
||||||
|
|
||||||
|
unsigned int getPhaseInt() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type mType;
|
||||||
|
MoonState::Phase mPhase;
|
||||||
|
osg::ref_ptr<MoonUpdater> mUpdater;
|
||||||
|
|
||||||
|
void setPhase(const MoonState::Phase& phase);
|
||||||
|
};
|
||||||
|
|
||||||
|
class RainCounter : public osgParticle::ConstantRateCounter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int numParticlesToCreate(double dt) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RainShooter : public osgParticle::Shooter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RainShooter();
|
||||||
|
|
||||||
|
osg::Object* cloneType() const override;
|
||||||
|
|
||||||
|
osg::Object* clone(const osg::CopyOp &) const override;
|
||||||
|
|
||||||
|
void shoot(osgParticle::Particle* particle) const override;
|
||||||
|
|
||||||
|
void setVelocity(const osg::Vec3f& velocity);
|
||||||
|
void setAngle(float angle);
|
||||||
|
|
||||||
|
private:
|
||||||
|
osg::Vec3f mVelocity;
|
||||||
|
float mAngle;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ModVertexAlphaVisitor : public osg::NodeVisitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum MeshType
|
||||||
|
{
|
||||||
|
Atmosphere,
|
||||||
|
Stars,
|
||||||
|
Clouds
|
||||||
|
};
|
||||||
|
|
||||||
|
ModVertexAlphaVisitor(MeshType type);
|
||||||
|
|
||||||
|
void apply(osg::Geometry& geometry) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MeshType mType;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using namespace MWWorld;
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static const int invalidWeatherID = -1;
|
static const int invalidWeatherID = -1;
|
||||||
|
@ -38,8 +36,24 @@ namespace
|
||||||
{
|
{
|
||||||
return x * (1-factor) + y * factor;
|
return x * (1-factor) + y * factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osg::Vec3f calculateStormDirection(const std::string& particleEffect)
|
||||||
|
{
|
||||||
|
osg::Vec3f stormDirection = MWWorld::Weather::defaultDirection();
|
||||||
|
if (particleEffect == "meshes\\ashcloud.nif" || particleEffect == "meshes\\blightcloud.nif")
|
||||||
|
{
|
||||||
|
osg::Vec3f playerPos = MWMechanics::getPlayer().getRefData().getPosition().asVec3();
|
||||||
|
playerPos.z() = 0;
|
||||||
|
osg::Vec3f redMountainPos = osg::Vec3f(25000.f, 70000.f, 0.f);
|
||||||
|
stormDirection = (playerPos - redMountainPos);
|
||||||
|
stormDirection.normalize();
|
||||||
|
}
|
||||||
|
return stormDirection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T TimeOfDayInterpolator<T>::getValue(const float gameHour, const TimeOfDaySettings& timeSettings, const std::string& prefix) const
|
T TimeOfDayInterpolator<T>::getValue(const float gameHour, const TimeOfDaySettings& timeSettings, const std::string& prefix) const
|
||||||
{
|
{
|
||||||
|
@ -109,11 +123,15 @@ T TimeOfDayInterpolator<T>::getValue(const float gameHour, const TimeOfDaySettin
|
||||||
return T();
|
return T();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template class MWWorld::TimeOfDayInterpolator<float>;
|
template class MWWorld::TimeOfDayInterpolator<float>;
|
||||||
template class MWWorld::TimeOfDayInterpolator<osg::Vec4f>;
|
template class MWWorld::TimeOfDayInterpolator<osg::Vec4f>;
|
||||||
|
|
||||||
|
osg::Vec3f Weather::defaultDirection()
|
||||||
|
{
|
||||||
|
static const osg::Vec3f direction = osg::Vec3f(0.f, 1.f, 0.f);
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
Weather::Weather(const std::string& name,
|
Weather::Weather(const std::string& name,
|
||||||
float stormWindSpeed,
|
float stormWindSpeed,
|
||||||
float rainSpeed,
|
float rainSpeed,
|
||||||
|
@ -155,6 +173,7 @@ Weather::Weather(const std::string& name,
|
||||||
, mRainMaxHeight(Fallback::Map::getFloat("Weather_" + name + "_Rain_Height_Max"))
|
, mRainMaxHeight(Fallback::Map::getFloat("Weather_" + name + "_Rain_Height_Max"))
|
||||||
, mParticleEffect(particleEffect)
|
, mParticleEffect(particleEffect)
|
||||||
, mRainEffect(Fallback::Map::getBool("Weather_" + name + "_Using_Precip") ? "meshes\\raindrop.nif" : "")
|
, mRainEffect(Fallback::Map::getBool("Weather_" + name + "_Using_Precip") ? "meshes\\raindrop.nif" : "")
|
||||||
|
, mStormDirection(Weather::defaultDirection())
|
||||||
, mTransitionDelta(Fallback::Map::getFloat("Weather_" + name + "_Transition_Delta"))
|
, mTransitionDelta(Fallback::Map::getFloat("Weather_" + name + "_Transition_Delta"))
|
||||||
, mCloudsMaximumPercent(Fallback::Map::getFloat("Weather_" + name + "_Clouds_Maximum_Percent"))
|
, mCloudsMaximumPercent(Fallback::Map::getFloat("Weather_" + name + "_Clouds_Maximum_Percent"))
|
||||||
, mThunderFrequency(Fallback::Map::getFloat("Weather_" + name + "_Thunder_Frequency"))
|
, mThunderFrequency(Fallback::Map::getFloat("Weather_" + name + "_Thunder_Frequency"))
|
||||||
|
@ -536,7 +555,7 @@ WeatherManager::WeatherManager(MWRender::RenderingManager& rendering, MWWorld::E
|
||||||
, mNextWindSpeed(0.f)
|
, mNextWindSpeed(0.f)
|
||||||
, mIsStorm(false)
|
, mIsStorm(false)
|
||||||
, mPrecipitation(false)
|
, mPrecipitation(false)
|
||||||
, mStormDirection(0,1,0)
|
, mStormDirection(Weather::defaultDirection())
|
||||||
, mCurrentRegion()
|
, mCurrentRegion()
|
||||||
, mTimePassed(0)
|
, mTimePassed(0)
|
||||||
, mFastForward(false)
|
, mFastForward(false)
|
||||||
|
@ -727,20 +746,8 @@ void WeatherManager::update(float duration, bool paused, const TimeStamp& time,
|
||||||
mPrecipitation = !(mResult.mParticleEffect.empty() && mResult.mRainEffect.empty())
|
mPrecipitation = !(mResult.mParticleEffect.empty() && mResult.mRainEffect.empty())
|
||||||
&& mResult.mParticleEffect != "meshes\\ashcloud.nif";
|
&& mResult.mParticleEffect != "meshes\\ashcloud.nif";
|
||||||
|
|
||||||
if (mIsStorm)
|
mStormDirection = calculateStormDirection(mResult.mParticleEffect);
|
||||||
{
|
mRendering.getSkyManager()->setStormParticleDirection(mStormDirection);
|
||||||
osg::Vec3f stormDirection(0, 1, 0);
|
|
||||||
if (mResult.mParticleEffect == "meshes\\ashcloud.nif" || mResult.mParticleEffect == "meshes\\blightcloud.nif")
|
|
||||||
{
|
|
||||||
osg::Vec3f playerPos (MWMechanics::getPlayer().getRefData().getPosition().asVec3());
|
|
||||||
playerPos.z() = 0;
|
|
||||||
osg::Vec3f redMountainPos (25000, 70000, 0);
|
|
||||||
stormDirection = (playerPos - redMountainPos);
|
|
||||||
stormDirection.normalize();
|
|
||||||
}
|
|
||||||
mStormDirection = stormDirection;
|
|
||||||
mRendering.getSkyManager()->setStormDirection(mStormDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable sun during night
|
// disable sun during night
|
||||||
if (time.getHour() >= mTimeSettings.mNightStart || time.getHour() <= mSunriseTime)
|
if (time.getHour() >= mTimeSettings.mNightStart || time.getHour() <= mSunriseTime)
|
||||||
|
@ -1190,6 +1197,7 @@ inline void WeatherManager::calculateResult(const int weatherID, const float gam
|
||||||
else
|
else
|
||||||
mResult.mSunDiscColor.a() = 1;
|
mResult.mSunDiscColor.a() = 1;
|
||||||
|
|
||||||
|
mResult.mStormDirection = calculateStormDirection(mResult.mParticleEffect);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void WeatherManager::calculateTransitionResult(const float factor, const float gameHour)
|
inline void WeatherManager::calculateTransitionResult(const float factor, const float gameHour)
|
||||||
|
@ -1199,6 +1207,9 @@ inline void WeatherManager::calculateTransitionResult(const float factor, const
|
||||||
calculateResult(mNextWeather, gameHour);
|
calculateResult(mNextWeather, gameHour);
|
||||||
const MWRender::WeatherResult other = mResult;
|
const MWRender::WeatherResult other = mResult;
|
||||||
|
|
||||||
|
mResult.mStormDirection = current.mStormDirection;
|
||||||
|
mResult.mNextStormDirection = other.mStormDirection;
|
||||||
|
|
||||||
mResult.mCloudTexture = current.mCloudTexture;
|
mResult.mCloudTexture = current.mCloudTexture;
|
||||||
mResult.mNextCloudTexture = other.mCloudTexture;
|
mResult.mNextCloudTexture = other.mCloudTexture;
|
||||||
mResult.mCloudBlendFactor = mWeatherSettings[mNextWeather].cloudBlendFactor(factor);
|
mResult.mCloudBlendFactor = mWeatherSettings[mNextWeather].cloudBlendFactor(factor);
|
||||||
|
@ -1225,7 +1236,7 @@ inline void WeatherManager::calculateTransitionResult(const float factor, const
|
||||||
mResult.mNight = current.mNight;
|
mResult.mNight = current.mNight;
|
||||||
|
|
||||||
float threshold = mWeatherSettings[mNextWeather].mRainThreshold;
|
float threshold = mWeatherSettings[mNextWeather].mRainThreshold;
|
||||||
if (threshold <= 0)
|
if (threshold <= 0.f)
|
||||||
threshold = 0.5f;
|
threshold = 0.5f;
|
||||||
|
|
||||||
if(factor < threshold)
|
if(factor < threshold)
|
||||||
|
@ -1235,7 +1246,7 @@ inline void WeatherManager::calculateTransitionResult(const float factor, const
|
||||||
mResult.mRainEffect = current.mRainEffect;
|
mResult.mRainEffect = current.mRainEffect;
|
||||||
mResult.mRainSpeed = current.mRainSpeed;
|
mResult.mRainSpeed = current.mRainSpeed;
|
||||||
mResult.mRainEntranceSpeed = current.mRainEntranceSpeed;
|
mResult.mRainEntranceSpeed = current.mRainEntranceSpeed;
|
||||||
mResult.mAmbientSoundVolume = 1 - factor / threshold;
|
mResult.mAmbientSoundVolume = 1.f - factor / threshold;
|
||||||
mResult.mPrecipitationAlpha = mResult.mAmbientSoundVolume;
|
mResult.mPrecipitationAlpha = mResult.mAmbientSoundVolume;
|
||||||
mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
||||||
mResult.mRainDiameter = current.mRainDiameter;
|
mResult.mRainDiameter = current.mRainDiameter;
|
||||||
|
@ -1260,4 +1271,5 @@ inline void WeatherManager::calculateTransitionResult(const float factor, const
|
||||||
mResult.mRainMaxRaindrops = other.mRainMaxRaindrops;
|
mResult.mRainMaxRaindrops = other.mRainMaxRaindrops;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,8 @@ namespace MWWorld
|
||||||
class Weather
|
class Weather
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static osg::Vec3f defaultDirection();
|
||||||
|
|
||||||
Weather(const std::string& name,
|
Weather(const std::string& name,
|
||||||
float stormWindSpeed,
|
float stormWindSpeed,
|
||||||
float rainSpeed,
|
float rainSpeed,
|
||||||
|
@ -189,6 +191,8 @@ namespace MWWorld
|
||||||
|
|
||||||
std::string mRainEffect;
|
std::string mRainEffect;
|
||||||
|
|
||||||
|
osg::Vec3f mStormDirection;
|
||||||
|
|
||||||
// Note: For Weather Blight, there is a "Disease Chance" (=0.1) setting. But according to MWSFD this feature
|
// Note: For Weather Blight, there is a "Disease Chance" (=0.1) setting. But according to MWSFD this feature
|
||||||
// is broken in the vanilla game and was disabled.
|
// is broken in the vanilla game and was disabled.
|
||||||
|
|
||||||
|
|
|
@ -516,6 +516,14 @@ namespace Shader
|
||||||
// We could fall back to a texture size uniform if EXT_gpu_shader4 is missing
|
// We could fall back to a texture size uniform if EXT_gpu_shader4 is missing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool simpleLighting = false;
|
||||||
|
node.getUserValue("simpleLighting", simpleLighting);
|
||||||
|
if (simpleLighting)
|
||||||
|
{
|
||||||
|
defineMap["forcePPL"] = "1";
|
||||||
|
defineMap["endLight"] = "0";
|
||||||
|
}
|
||||||
|
|
||||||
if (writableStateSet->getMode(GL_ALPHA_TEST) != osg::StateAttribute::INHERIT && !previousAddedState->hasMode(GL_ALPHA_TEST))
|
if (writableStateSet->getMode(GL_ALPHA_TEST) != osg::StateAttribute::INHERIT && !previousAddedState->hasMode(GL_ALPHA_TEST))
|
||||||
removedState->setMode(GL_ALPHA_TEST, writableStateSet->getMode(GL_ALPHA_TEST));
|
removedState->setMode(GL_ALPHA_TEST, writableStateSet->getMode(GL_ALPHA_TEST));
|
||||||
// This disables the deprecated fixed-function alpha test
|
// This disables the deprecated fixed-function alpha test
|
||||||
|
|
|
@ -36,6 +36,9 @@ set(SHADER_FILES
|
||||||
gui_fragment.glsl
|
gui_fragment.glsl
|
||||||
debug_vertex.glsl
|
debug_vertex.glsl
|
||||||
debug_fragment.glsl
|
debug_fragment.glsl
|
||||||
|
sky_vertex.glsl
|
||||||
|
sky_fragment.glsl
|
||||||
|
skypasses.glsl
|
||||||
)
|
)
|
||||||
|
|
||||||
copy_all_resource_files(${CMAKE_CURRENT_SOURCE_DIR} ${OPENMW_SHADERS_ROOT} ${DDIRRELATIVE} "${SHADER_FILES}")
|
copy_all_resource_files(${CMAKE_CURRENT_SOURCE_DIR} ${OPENMW_SHADERS_ROOT} ${DDIRRELATIVE} "${SHADER_FILES}")
|
||||||
|
|
87
files/shaders/sky_fragment.glsl
Normal file
87
files/shaders/sky_fragment.glsl
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
#include "skypasses.glsl"
|
||||||
|
|
||||||
|
uniform int pass;
|
||||||
|
uniform sampler2D diffuseMap;
|
||||||
|
uniform sampler2D maskMap; // PASS_MOON
|
||||||
|
uniform float opacity; // PASS_CLOUDS, PASS_ATMOSPHERE_NIGHT
|
||||||
|
uniform vec4 moonBlend; // PASS_MOON
|
||||||
|
uniform vec4 atmosphereFade; // PASS_MOON
|
||||||
|
|
||||||
|
varying vec2 diffuseMapUV;
|
||||||
|
varying vec4 passColor;
|
||||||
|
|
||||||
|
void paintAtmosphere(inout vec4 color)
|
||||||
|
{
|
||||||
|
color = gl_FrontMaterial.emission;
|
||||||
|
color.a *= passColor.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintAtmosphereNight(inout vec4 color)
|
||||||
|
{
|
||||||
|
color = texture2D(diffuseMap, diffuseMapUV);
|
||||||
|
color.a *= passColor.a * opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintClouds(inout vec4 color)
|
||||||
|
{
|
||||||
|
color = texture2D(diffuseMap, diffuseMapUV);
|
||||||
|
color.a *= passColor.a * opacity;
|
||||||
|
color.xyz = clamp(color.xyz * gl_FrontMaterial.emission.xyz, 0.0, 1.0);
|
||||||
|
|
||||||
|
// ease transition between clear color and atmosphere/clouds
|
||||||
|
color = mix(vec4(gl_Fog.color.xyz, color.a), color, passColor.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintMoon(inout vec4 color)
|
||||||
|
{
|
||||||
|
vec4 phase = texture2D(diffuseMap, diffuseMapUV);
|
||||||
|
vec4 mask = texture2D(maskMap, diffuseMapUV);
|
||||||
|
|
||||||
|
vec4 blendedLayer = phase * moonBlend;
|
||||||
|
color = vec4(blendedLayer.xyz + atmosphereFade.xyz, atmosphereFade.a * mask.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintSun(inout vec4 color)
|
||||||
|
{
|
||||||
|
color = texture2D(diffuseMap, diffuseMapUV);
|
||||||
|
color.a *= gl_FrontMaterial.diffuse.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintSunflashQuery(inout vec4 color)
|
||||||
|
{
|
||||||
|
const float threshold = 0.8;
|
||||||
|
|
||||||
|
color = texture2D(diffuseMap, diffuseMapUV);
|
||||||
|
if (color.a <= threshold)
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintSunglare(inout vec4 color)
|
||||||
|
{
|
||||||
|
color = gl_FrontMaterial.emission;
|
||||||
|
color.a = gl_FrontMaterial.diffuse.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 color = vec4(0.0);
|
||||||
|
|
||||||
|
if (pass == PASS_ATMOSPHERE)
|
||||||
|
paintAtmosphere(color);
|
||||||
|
else if (pass == PASS_ATMOSPHERE_NIGHT)
|
||||||
|
paintAtmosphereNight(color);
|
||||||
|
else if (pass == PASS_CLOUDS)
|
||||||
|
paintClouds(color);
|
||||||
|
else if (pass == PASS_MOON)
|
||||||
|
paintMoon(color);
|
||||||
|
else if (pass == PASS_SUN)
|
||||||
|
paintSun(color);
|
||||||
|
else if (pass == PASS_SUNFLASH_QUERY)
|
||||||
|
paintSunflashQuery(color);
|
||||||
|
else if (pass == PASS_SUNGLARE)
|
||||||
|
paintSunglare(color);
|
||||||
|
|
||||||
|
gl_FragData[0] = color;
|
||||||
|
}
|
20
files/shaders/sky_vertex.glsl
Normal file
20
files/shaders/sky_vertex.glsl
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
#include "skypasses.glsl"
|
||||||
|
|
||||||
|
uniform mat4 projectionMatrix;
|
||||||
|
uniform int pass;
|
||||||
|
|
||||||
|
varying vec4 passColor;
|
||||||
|
varying vec2 diffuseMapUV;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projectionMatrix * (gl_ModelViewMatrix * gl_Vertex);
|
||||||
|
passColor = gl_Color;
|
||||||
|
|
||||||
|
if (pass == PASS_CLOUDS)
|
||||||
|
diffuseMapUV = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
||||||
|
else
|
||||||
|
diffuseMapUV = gl_MultiTexCoord0.xy;
|
||||||
|
}
|
7
files/shaders/skypasses.glsl
Normal file
7
files/shaders/skypasses.glsl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#define PASS_ATMOSPHERE 0
|
||||||
|
#define PASS_ATMOSPHERE_NIGHT 1
|
||||||
|
#define PASS_CLOUDS 2
|
||||||
|
#define PASS_MOON 3
|
||||||
|
#define PASS_SUN 4
|
||||||
|
#define PASS_SUNFLASH_QUERY 5
|
||||||
|
#define PASS_SUNGLARE 6
|
Loading…
Reference in a new issue